A pre-commit hook implementation of the Linux kernel checkpatch.pl
script.
Uses Linux kernel checkpatch.pl
to check for coding style errors in C code, Makefiles, etc.
See the docs for the script itself here.
The hook uses configuration file to specify which rules to enforce or ignore.
A default configuration file is provided in checkpatch_hook/data/checkpatch.yaml
but it can be overriden
by a custom configuration file and passed to the script using the --config-file
option.
The configuration file is a YAML file with the following structure:
DIR_CONFIGS:
<directory1>:
errors_ignored:
- <checkpatch option>
- <checkpatch option>
max_line_length: <number>
<directory2>:
errors_enabled:
- <checkpatch option>
- <checkpatch option>
max_line_length: <number>
Note: Either errors_enabled
or errors_ignored
are enforced, not both.
The configuration file supports some magic keys that make it easier to configure the script.
The __default__
key can be used to apply the same configuration to all the files in the repository.
__default__:
errors_ignored:
- <checkpatch option>
- <checkpatch option>
- ...
max_line_length: <number>
The ERRORS_ENABLED
key can be used as a placeholder for all the errors enabled, and this needs to be part of errors_enabled
list to be used.
ERRORS_ENABLED:
- <checkpatch option>
- <checkpatch option>
- ...
DIR_CONFIGS:
<directory>:
errors_enabled:
- ERRORS_ENABLED
- <checkpatch option>
- <checkpatch option>
- ...
max_line_length: <number>
The IGNORES_COMMON
key can be used as a placeholder for all the errors ignored for all the files, and this needs to be part of errors_ignored
list to be used.
IGNORES_COMMON:
- <checkpatch option>
- <checkpatch option>
- ...
DIR_CONFIGS:
<directory>:
errors_ignored:
- IGNORES_COMMON
- <checkpatch option>
- <checkpatch option>
max_line_length: <number>
To use the hooks in your local repository you need to install pre-commit
and add the following to your .pre-commit-config.yaml
file:
- repo: https://github.com/bluwireless/check-commit-hook
rev: xxxx
hooks:
- id: checkpatch
args: [--config-file, checkpatch_custom.yaml]
The --fix-inplace
argument can be added to let checkpatch
try to fix errors where it can.
See the checkpatch
docs.