]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[pre-commit] Remove duplication in config file
authorTom de Vries <tdevries@suse.de>
Mon, 13 Jul 2026 11:11:06 +0000 (13:11 +0200)
committerTom de Vries <tdevries@suse.de>
Mon, 13 Jul 2026 11:11:06 +0000 (13:11 +0200)
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

.pre-commit-config.yaml

index f77910d9e327b81cb136d82245ec996b71104b81..c113eeeb78b08131be75d3e368ebcf34154fecc5 100644 (file)
@@ -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)/.*$'