Skip to content

Commit

Permalink
Adding 2.9 ignore allow-list for sanity rule (#3118)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonlhart authored Mar 3, 2023
1 parent 97070b4 commit ade2eca
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
17 changes: 11 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -243,3 +246,5 @@ repos:
name: update json schemas
entry: python3 src/ansiblelint/schemas/__main__.py
language: python
pass_filenames: false
always_run: true
2 changes: 1 addition & 1 deletion examples/sanity_ignores/tests/sanity/ignore-2.13.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions examples/sanity_ignores/tests/sanity/ignore-2.14.txt

This file was deleted.

2 changes: 2 additions & 0 deletions examples/sanity_ignores/tests/sanity/ignore-2.9.txt
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion src/ansiblelint/rules/sanity.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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

```
Expand Down
19 changes: 16 additions & 3 deletions src/ansiblelint/rules/sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/schemas/__store__.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit ade2eca

Please sign in to comment.