[binutils-gdb] [pre-commit] Remove duplication in config file
Tom de Vries
vries@sourceware.org
Mon Jul 13 11:11:10 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2b28c50ecd058b3fe0328d1bf5f7bc06fd8ca41c
commit 2b28c50ecd058b3fe0328d1bf5f7bc06fd8ca41c
Author: Tom de Vries <tdevries@suse.de>
Date: Mon Jul 13 13:11:06 2026 +0200
[pre-commit] Remove duplication in config file
In a recent commit, I introduced anchor/alias pairs in
.pre-commit-config.yaml, with short non-descriptive names for local use:
...
- - id: check-include-guards
- name: check-include-guards
+ - id: &id0 check-include-guards
+ name: *id0
...
Use anchors and aliases a bit more to remove duplication, now using more
descriptive names for non-local uses.
Yaml also supports defining an anchor for more than one field, which result in
cleaner code:
...
+python-files: &python-files
+ types_or: [file]
+ files: '^gdb/.*\.py(\.in)?$'
+
...
- id: black
- types_or: [file]
- files: '^gdb/.*\.py(\.in)?$'
+ <<: *python-files
...
but unfortunately pre-commit generates a warning "[WARNING] Unexpected key(s)
present at root: python-files" for this [1].
Also add a default files setting.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34295
[1] https://github.com/pre-commit/pre-commit/issues/1481
Diff:
---
.pre-commit-config.yaml | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f77910d9e32..c113eeeb78b 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -40,6 +40,7 @@
minimum_pre_commit_version: 4.5.1
default_install_hook_types: [pre-commit, commit-msg]
default_stages: [pre-commit]
+files: '^(gdb|gdbserver|gdbsupport)/'
repos:
# Python hooks. Run these for (in glob notation):
@@ -56,33 +57,32 @@ repos:
rev: 26.5.1
hooks:
- id: black
- types_or: [file]
- files: '^gdb/.*\.py(\.in)?$'
+ types_or: &gdb_python_types [file]
+ files: &gdb_python_files '^gdb/.*\.py(\.in)?$'
- repo: https://github.com/pycqa/flake8
rev: 7.3.0
hooks:
- id: flake8
- types_or: [file]
- files: '^gdb/.*\.py(\.in)?$'
+ types_or: *gdb_python_types
+ files: *gdb_python_files
args: [--config, gdb/setup.cfg]
- repo: https://github.com/pycqa/isort
rev: 9.0.0b1
hooks:
- id: isort
- types_or: [file]
- files: '^gdb/.*\.py(\.in)?$'
+ types_or: *gdb_python_types
+ files: *gdb_python_files
# Codespell hooks.
- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
hooks:
- id: codespell
- files: '^(gdb|gdbserver|gdbsupport)/'
- args: [--toml, gdb/pyproject.toml]
+ args: &codespell_args [--toml, gdb/pyproject.toml]
- id: codespell
name: codespell-log
entry: gdb/contrib/codespell-log.sh
- args: [--toml, gdb/pyproject.toml]
+ args: *codespell_args
verbose: true
stages: [commit-msg]
@@ -116,7 +116,6 @@ repos:
name: *id2
language: unsupported_script
entry: gdb/contrib/check-whitespace-pre-commit.py
- files: '^(gdb(support|server)?)/.*$'
types: ['text']
- id: &id3 pre-commit-setup
name: *id3
@@ -129,4 +128,3 @@ repos:
name: *id4
language: unsupported_script
entry: gdb/contrib/check-file-mode.sh
- files: '^(gdb|gdbserver|gdbsupport)/.*$'
More information about the Binutils-cvs
mailing list