diff options
author | Tom de Vries <tdevries@suse.de> | 2025-03-31 09:30:00 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2025-03-31 09:30:00 +0200 |
commit | 88c06ad206a407f60409b0e4b4ac91aa64938406 (patch) | |
tree | d4577799d255cb587fd18482e2b01f1c86b90f3d /gdb | |
parent | 7109ea04ac79f641c48b6a1e6a2f3fc38a83c2ed (diff) | |
download | binutils-88c06ad206a407f60409b0e4b4ac91aa64938406.zip binutils-88c06ad206a407f60409b0e4b4ac91aa64938406.tar.gz binutils-88c06ad206a407f60409b0e4b4ac91aa64938406.tar.bz2 |
[pre-commit] Add codespell hook
Add a pre-commit codespell hook for directories gdbsupport and gdbserver,
which are codespell-clean:
...
$ pre-commit run codespell --all-files
codespell................................................................Passed
...
A non-trivial question is where the codespell configuration goes.
Currently we have codespell sections in gdbsupport/setup.cfg and
gdbserver/setup.cfg, but codespell doesn't automatically use those because the
pre-commit hook runs codespell at the root of the repository.
A solution would be to replace those 2 setup.cfg files with a setup.cfg in the
root of the repository. Not ideal because generally we try to avoid adding
files related to subdirectories at the root.
Another solution would be to add two codespell hooks, one using
--config gdbsupport/setup.cfg and one using --config gdbserver/setup.cfg, and
add a third one once we start supporting gdb. Not ideal because it creates
duplication, but certainly possible.
I went with the following solution: a setup.cfg file in gdb/contrib (alongside
codespell-ignore-words.txt) which is used for both gdbserver and gdbsupport.
So, what can this new setup do for us? Let's demonstrate by simulating a typo:
...
$ echo "/* aways */" >> gdbsupport/agent.cc
...
We can check unstaged changes before committing:
...
$ pre-commit run codespell --all-files
codespell................................................................Failed
- hook id: codespell
- exit code: 65
gdbsupport/agent.cc:282: aways ==> always, away
...
Likewise, staged changes (no need for the --all-files):
...
$ git add gdbsupport/agent.cc
$ pre-commit run codespell
codespell................................................................Failed
- hook id: codespell
- exit code: 65
gdbsupport/agent.cc:282: aways ==> always, away
...
Or we can try to commit, and run into the codespell failure:
...
$ git commit -a
black................................................(no files to check)Skipped
flake8...............................................(no files to check)Skipped
isort................................................(no files to check)Skipped
codespell................................................................Failed
- hook id: codespell
- exit code: 65
gdbsupport/agent.cc:282: aways ==> always, away
check-include-guards.................................(no files to check)Skipped
...
which makes the commit fail.
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/contrib/setup.cfg | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/gdb/contrib/setup.cfg b/gdb/contrib/setup.cfg new file mode 100644 index 0000000..71459fe --- /dev/null +++ b/gdb/contrib/setup.cfg @@ -0,0 +1,6 @@ +[codespell] + +# Skip ChangeLogs and generated files. +skip = */ChangeLog*,*/configure,gdbsupport/Makefile.in + +ignore-words = gdb/contrib/codespell-ignore-words.txt |