[binutils-gdb] [pre-commit] Remove duplication in config file

Tom de Vries via Gdb-cvs <[email protected]> Mon, 13 Jul 2026 11:11:10 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <20260713111110.7800D4BA5434__12441.7203756579$1783941083$gmane$org@sourceware.org>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D2b28c50ecd05=
8b3fe0328d1bf5f7bc06fd8ca41c

commit 2b28c50ecd058b3fe0328d1bf5f7bc06fd8ca41c
Author: Tom de Vries <[email protected]>
Date:   Mon Jul 13 13:11:06 2026 +0200

    [pre-commit] Remove duplication in config file
   =20
    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
    ...
   =20
    Use anchors and aliases a bit more to remove duplication, now using more
    descriptive names for non-local uses.
   =20
    Yaml also supports defining an anchor for more than one field, which re=
sult 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].
   =20
    Also add a default files setting.
   =20
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D34295
   =20
    [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)/'
=20
 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
=20
   # 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]
=20
@@ -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)/.*$'