diff --git a/Makefile.frag b/Makefile.frag index e2f17a9..2b1b437 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -1,2 +1,19 @@ +format_files=jsonpath.c \ + php_jsonpath.h \ + src/jsonpath/*.{c,h} \ + findphp: @echo $(PHP_EXECUTABLE) + +format-check: + @clang-format --dry-run -Werror $(format_files) + +format-code: + @clang-format -i $(format_files) + +lint-code: + @cppcheck --enable=all --error-exitcode=1 --std=c89 --suppress=missingInclude $(format_files) + +setup-pre-commit: + @ln -s ../../pre-commit .git/hooks + diff --git a/README.md b/README.md index 3d56508..9031699 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,32 @@ $ make lcov You can then find a coverage report in the `lcov_html/` directory. +## Code Quality Tooling + +Please run the code formatter and linter (and fix any issues reported by the linter) before filing a pull request. + +You may run these tasks automatically by setting up a pre-commit hook: + +```bash +make setup-pre-commit +``` + +### Formatting + +Code formatting requires [clang-format](https://clang.llvm.org/docs/index.html). + +```bash +make format-code +``` + +### Linting + +Linting requires [cppcheck](http://cppcheck.sourceforge.net/). + +```bash +make lint-code +``` + ## Contributors JsonPath-PHP is created by [Mike Kaminski](https://github.com/mkaminski1988) and maintained by diff --git a/pre-commit b/pre-commit new file mode 100755 index 0000000..9ca99d2 --- /dev/null +++ b/pre-commit @@ -0,0 +1,3 @@ +#!/bin/sh + +make format-check lint-code