From: Tom de Vries Date: Mon, 31 Mar 2025 07:30:00 +0000 (+0200) Subject: [pre-commit] Add codespell hook X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88c06ad206a407f60409b0e4b4ac91aa64938406;p=thirdparty%2Fbinutils-gdb.git [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 --- diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index be3ee825575..88288e044ec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -65,6 +65,12 @@ repos: - id: isort types_or: [file] files: 'gdb/.*\.py(\.in)?$' + - repo: https://github.com/codespell-project/codespell + rev: v2.4.1 + hooks: + - id: codespell + files: '^(gdbsupport|gdbserver)/' + args: [--config, gdb/contrib/setup.cfg] - repo: local hooks: - id: check-include-guards diff --git a/gdbserver/setup.cfg b/gdb/contrib/setup.cfg similarity index 64% rename from gdbserver/setup.cfg rename to gdb/contrib/setup.cfg index 08646b8ea19..71459fe5471 100644 --- a/gdbserver/setup.cfg +++ b/gdb/contrib/setup.cfg @@ -1,4 +1,6 @@ [codespell] + # Skip ChangeLogs and generated files. -skip = ChangeLog*,configure +skip = */ChangeLog*,*/configure,gdbsupport/Makefile.in + ignore-words = gdb/contrib/codespell-ignore-words.txt diff --git a/gdbsupport/setup.cfg b/gdbsupport/setup.cfg deleted file mode 100644 index e3e92988fd7..00000000000 --- a/gdbsupport/setup.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[codespell] -# Skip ChangeLogs and generated files. -skip = ChangeLog*,Makefile.in,configure -ignore-words = gdb/contrib/codespell-ignore-words.txt