From ade2ecadcfe402e1154e4374a52975603ac073a1 Mon Sep 17 00:00:00 2001 From: Alison Hart Date: Fri, 3 Mar 2023 07:52:20 -0500 Subject: [PATCH] Adding 2.9 ignore allow-list for sanity rule (#3118) --- .pre-commit-config.yaml | 17 +++++++++++------ .../tests/sanity/ignore-2.13.txt | 2 +- .../tests/sanity/ignore-2.14.txt | 2 -- .../tests/sanity/ignore-2.9.txt | 2 ++ src/ansiblelint/rules/sanity.md | 7 ++++++- src/ansiblelint/rules/sanity.py | 19 ++++++++++++++++--- src/ansiblelint/schemas/__store__.json | 2 +- 7 files changed, 37 insertions(+), 14 deletions(-) delete mode 100644 examples/sanity_ignores/tests/sanity/ignore-2.14.txt create mode 100644 examples/sanity_ignores/tests/sanity/ignore-2.9.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e68f7998bc..8a9d3cb843 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -207,29 +207,32 @@ repos: hooks: - id: pip-compile name: lock + alias: lock always_run: true entry: pip-compile --upgrade --resolver=backtracking -q --no-annotate --output-file=.config/requirements-lock.txt pyproject.toml --strip-extras --unsafe-package ruamel-yaml-clib - language: python files: ^.config\/requirements.*$ - alias: lock - stages: [manual] + language: python language_version: "3.9" # minimal we support officially + pass_filenames: false + stages: [manual] additional_dependencies: - pip>=22.3.1 - id: pip-compile name: deps + alias: deps + always_run: true entry: pip-compile --resolver=backtracking -q --no-annotate --output-file=.config/requirements.txt pyproject.toml --extra docs --extra test --strip-extras --unsafe-package ruamel-yaml-clib - language: python files: ^.config\/requirements.*$ - alias: deps + language: python language_version: "3.9" # minimal we support officially - always_run: true + pass_filenames: false additional_dependencies: - pip>=22.3.1 - id: pip-compile entry: pip-compile --resolver=backtracking -q --no-annotate --output-file=.config/requirements.txt pyproject.toml --extra docs --extra test --strip-extras --unsafe-package ruamel-yaml-clib --upgrade language: python always_run: true + pass_filenames: false files: ^.config\/requirements.*$ alias: up stages: [manual] @@ -243,3 +246,5 @@ repos: name: update json schemas entry: python3 src/ansiblelint/schemas/__main__.py language: python + pass_filenames: false + always_run: true diff --git a/examples/sanity_ignores/tests/sanity/ignore-2.13.txt b/examples/sanity_ignores/tests/sanity/ignore-2.13.txt index 81fb3a5d52..2b95cf50b8 100644 --- a/examples/sanity_ignores/tests/sanity/ignore-2.13.txt +++ b/examples/sanity_ignores/tests/sanity/ignore-2.13.txt @@ -1 +1 @@ -plugins/module_utils/ansible_example_module.py import-3.6!skip # comment +plugins/module_utils/ansible_example_module.py validate-modules:deprecation-mismatch # comment diff --git a/examples/sanity_ignores/tests/sanity/ignore-2.14.txt b/examples/sanity_ignores/tests/sanity/ignore-2.14.txt deleted file mode 100644 index d86f85256a..0000000000 --- a/examples/sanity_ignores/tests/sanity/ignore-2.14.txt +++ /dev/null @@ -1,2 +0,0 @@ -plugins/module_utils/ansible_example_module.py compile-2.6!skip -plugins/module_utils/ansible_example_module.py import-2.6!skip diff --git a/examples/sanity_ignores/tests/sanity/ignore-2.9.txt b/examples/sanity_ignores/tests/sanity/ignore-2.9.txt new file mode 100644 index 0000000000..bfee509358 --- /dev/null +++ b/examples/sanity_ignores/tests/sanity/ignore-2.9.txt @@ -0,0 +1,2 @@ +plugins/module_utils/ansible_example_module.py validate-modules:deprecation-mismatch +plugins/module_utils/ansible_example_module.py import-2.6!skip diff --git a/src/ansiblelint/rules/sanity.md b/src/ansiblelint/rules/sanity.md index 6eb2988e14..5b4f3a456f 100644 --- a/src/ansiblelint/rules/sanity.md +++ b/src/ansiblelint/rules/sanity.md @@ -13,9 +13,10 @@ This rule can produce messages like: - `sanity[bad-ignore]` - Ignore file entry at {line_num} is formatted incorrectly. Please review. -Currently allowed ignores are: +Currently allowed ignores for all Ansible versions are: - `validate-modules:missing-gplv3-license` +- `action-plugin-docs` - `import-2.6` - `import-2.6!skip` - `import-2.7` @@ -29,6 +30,10 @@ Currently allowed ignores are: - `compile-3.5` - `compile-3.5!skip` +Additionally allowed ignores for Ansible 2.9 are: +- `validate-modules:deprecation-mismatch` +- `validate-modules:invalid-documentation` + ## Problematic code ``` diff --git a/src/ansiblelint/rules/sanity.py b/src/ansiblelint/rules/sanity.py index 47e25f5701..de58461eeb 100644 --- a/src/ansiblelint/rules/sanity.py +++ b/src/ansiblelint/rules/sanity.py @@ -28,8 +28,15 @@ class CheckSanityIgnoreFiles(AnsibleLintRule): version_added = "v6.14.0" # Partner Engineering defines this list. Please contact PE for changes. - allowed_ignores = [ + + allowed_ignores_v2_9 = [ + "validate-modules:deprecation-mismatch", # Note: 2.9 expects a deprecated key in the METADATA. It was removed in later versions. + "validate-modules:invalid-documentation", # Note: The removed_at_date key in the deprecated section is invalid for 2.9. + ] + + allowed_ignores_all = [ "validate-modules:missing-gplv3-license", + "action-plugin-docs", # Added for Networking Collections "import-2.6", "import-2.6!skip", "import-2.7", @@ -59,13 +66,19 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: with open(file.abspath, encoding="utf-8") as ignore_file: entries = ignore_file.read().splitlines() + ignores = self.allowed_ignores_all + + # If there is a ignore-2.9.txt file, add the v2_9 list of allowed ignores + if "ignore-2.9.txt" in str(file.abspath): + ignores = self.allowed_ignores_all + self.allowed_ignores_v2_9 + for line_num, entry in enumerate(entries, 1): if entry and entry[0] != "#": try: if "#" in entry: entry, _ = entry.split("#") (_, test) = entry.split() - if test not in self.allowed_ignores: + if test not in ignores: results.append( self.create_matcherror( message=f"Ignore file contains {test} at line {line_num}, which is not a permitted ignore.", @@ -99,7 +112,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: ("test_file", "failures", "tags"), ( pytest.param( - "examples/sanity_ignores/tests/sanity/ignore-2.14.txt", + "examples/sanity_ignores/tests/sanity/ignore-2.9.txt", 0, "sanity[cannot-ignore]", id="pass", diff --git a/src/ansiblelint/schemas/__store__.json b/src/ansiblelint/schemas/__store__.json index e02bc75891..4b3db070aa 100644 --- a/src/ansiblelint/schemas/__store__.json +++ b/src/ansiblelint/schemas/__store__.json @@ -1,6 +1,6 @@ { "ansible-lint-config": { - "etag": "03cc2882dff22434360b76d333bc58cf88ed1629dc2c4432ae92caa35d6cb61a", + "etag": "4753f3c433fc6c05c62c7c36adf8cc9379a51f0554b2c7eee67685a2a7061a4d", "url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible-lint-config.json" }, "ansible-navigator-config": {