Skip to content

Commit

Permalink
Add pre-commit hook + clang-format GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
lhearachel committed Jul 6, 2024
1 parent 36045f7 commit 9053ebe
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
# Redirect output to stderr.
exec 1>&2

# Run clang-format on staged files; abort the commit if any files are changed
if ! git clang-format ; then
echo "linting made changes to source files; aborting commit"
exit 1
fi
18 changes: 18 additions & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: clang-format check
on: [pull_request]
jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
strategy:
matrix:
path:
- 'include'
- 'src'
steps:
- uses: actions/checkout@v4
- name: Run clang-format style check
uses: jidicula/[email protected]
with:
clang-format-version: '17'
check-path: ${{ matrix.path }}
26 changes: 16 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Contributing to pret/pokeplatinum

This document provides a synopsis and loose guidelines for how to contribute to this project. It is a work in progress. Maintainers should expand this document.

## Contents
<!--toc:start-->
- [Editor Enhancements](#editor-enhancements)
- [Code Formatting](#code-formatting)
<!--toc:end-->

This document provides a synopsis and loose guidelines for how to contribute to this project. It is a work in progress. Maintainers should expand this document.

<a href="editor-enhancements"></a>
## Editor Enhancements


This repository includes a script to generate a `compile_commands.json` that is compatible with C language servers such as `clangd`.

### Requirements
Expand All @@ -25,20 +26,25 @@ This repository includes a script to generate a `compile_commands.json` that is

This will create a file named `compile_commands.json` in the project root, overwriting the previous copy.

<a href="code-formatting"></a>
## Code Formatting

This repository includes an opinionated `clang-format` specification which is integrated into the build system for convenience in ensuring that your code adheres to repository style guidelines.
This repository includes an opinionated `clang-format` specification to ensure that we maintain a common code style. For convenience, a pre-commit hook is also provided in `.githooks` which will run `clang-format` against any staged changes prior to executing a commit.

### Requirements

- `clang-format`
- `clang-format@17` or newer

### Usage

```bash
./build.sh format
To set up the pre-commit hook:

```sh
git config --local core.hooksPath .githooks/
```

This will traverse the source tree and format all found C sources and headers according to the specified style rules.
To run the formatter on the full source tree:

```bash
./format.sh
```

0 comments on commit 9053ebe

Please sign in to comment.