From 46130c4c092c89dd372f2a3f3b14e7568375d067 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Wed, 8 Nov 2023 15:55:52 +0000 Subject: [PATCH] test(pre-commit): switch to using `pre-commit`'s built-in file filtering * only run `yamllint` when relevant files have changed * avoids having to exclude files/dirs not tracked by Git e.g. .kitchen/, .bundle/ etc. * avoids a `yamllint` bug whereby pillar files under `test/` were not checked due to a conflicting `ignore` entry --- .pre-commit-config.yaml | 27 ++++++++++++++++++++++++--- .yamllint | 27 --------------------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 363fab7..5beebf2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -45,9 +45,30 @@ repos: hooks: - id: yamllint name: Check YAML syntax with yamllint - args: [--strict, '.'] - always_run: true - pass_filenames: false + args: [--strict] + types: [file] + # Files to include + # 1. Obvious YAML files + # 2. `pillar.example` and similar files + # 3. SLS files under directory `test/` which are pillar files + # Files to exclude + # 1. SLS files under directory `test/` which are state files + # 2. `kitchen.vagrant.yml`, which contains Embedded Ruby (ERB) template syntax + # 3. YAML files heavily reliant on Jinja + files: | + (?x)^( + .*\.yaml| + .*\.yml| + \.salt-lint| + \.yamllint| + .*\.example| + test/.*\.sls + )$ + exclude: | + (?x)^( + kitchen.vagrant.yml| + test/.*/states/.*\.sls + )$ - repo: https://github.com/warpnet/salt-lint rev: v0.9.2 hooks: diff --git a/.yamllint b/.yamllint index 716baaf..b408788 100644 --- a/.yamllint +++ b/.yamllint @@ -4,33 +4,6 @@ # Extend the `default` configuration provided by `yamllint` extends: 'default' -# Files to ignore completely -# 1. All YAML files under directory `.bundle/`, introduced if gems are installed locally -# 2. All YAML files under directory `.cache/`, introduced during the CI run -# 3. All YAML files under directory `.git/` -# 4. All YAML files under directory `node_modules/`, introduced during the CI run -# 5. Any SLS files under directory `test/`, which are actually state files -# 6. Any YAML files under directory `.kitchen/`, introduced during local testing -# 7. `kitchen.vagrant.yml`, which contains Embedded Ruby (ERB) template syntax -ignore: | - .bundle/ - .cache/ - .git/ - node_modules/ - test/**/states/**/*.sls - .kitchen/ - kitchen.vagrant.yml - -yaml-files: - # Default settings - - '*.yaml' - - '*.yml' - - .salt-lint - - .yamllint - # SaltStack Formulas additional settings - - '*.example' - - test/**/*.sls - rules: empty-values: forbid-in-block-mappings: true