Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatting script to allow contributers to easily format code #37

Merged
merged 3 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,34 @@ int main(const int argc, const char * argv[]) {
- For the current set of unit tests, the working directory must be at the git
root directory or in `build` directory so that the TOML configuration files in
`config` directory can be found.

## Contributions

Pull requests are welcome!

To make the code formatting more objective, `clang-format` is used to format
all the source code files.

Please try to run

```bash
./run-clang-format.sh
```

which will pull the appropriate Docker image to run the formatting command over
the entire repository directory.

If your `docker` command requires `sudo`, then you will need to run it as

```bash
sudo sh ./run-clang-format.sh
```

Alternatively, you could also try to set up your own `clang-format` (currently
this repository uses version 7), and run

```bash
clang-format -i path_to_h_cpp_file
```

over the changed files.
13 changes: 13 additions & 0 deletions run-clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env sh
if ! which docker >/dev/null; then
echo "You need 'docker' command to run clang-format for this repository"
exit 1
fi

docker run \
-v $(pwd):/workdir -w /workdir \
-u "$(id -u):$(id -g)" \
--rm -t \
guangie88/clang-cmake:7 \
find include/ src/ -type f \( -iname *.h -o -iname *.cpp \) -print0 | \
xargs -0 -I {} clang-format -i {}