From f3b2dcd31a9238306c4b032278088c7d56317465 Mon Sep 17 00:00:00 2001 From: Uli Date: Wed, 19 Jan 2022 19:53:23 +0100 Subject: [PATCH 1/2] Allow noqa to be used in more lintable kinds This is the suggested fix from https://github.com/ansible-community/ansible-lint/issues/1723#issuecomment-918125017 --- src/ansiblelint/skip_utils.py | 4 +--- test/test_skiputils.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ansiblelint/skip_utils.py b/src/ansiblelint/skip_utils.py index e8efbd642b..60b93c0adb 100644 --- a/src/ansiblelint/skip_utils.py +++ b/src/ansiblelint/skip_utils.py @@ -97,7 +97,7 @@ def _append_skipped_rules( # parse file text using 2nd parser library ruamel_data = load_data(lintable.content) - if lintable.kind == 'meta': + if lintable.kind in ['yaml', 'requirements', 'vars', 'meta', 'reno']: pyyaml_data[0]['skipped_rules'] = _get_rule_skips_from_yaml(ruamel_data) return pyyaml_data @@ -114,8 +114,6 @@ def _append_skipped_rules( # assume it is a playbook, check needs to be added higher in the # call stack, and can remove this except return pyyaml_data - elif lintable.kind in ['yaml', 'requirements', 'vars', 'meta', 'reno']: - return pyyaml_data else: # For unsupported file types, we return empty skip lists return None diff --git a/test/test_skiputils.py b/test/test_skiputils.py index 7715ad4967..1defdd601a 100644 --- a/test/test_skiputils.py +++ b/test/test_skiputils.py @@ -2,6 +2,20 @@ import pytest from ansiblelint.skip_utils import get_rule_skips_from_line +from ansiblelint.testing import RunFromText + + +PLAYBOOK_WITH_NOQA = '''\ +- hosts: all + vars: + SOMEVARNOQA: "Foo" # noqa var-naming + SOMEVAR: "Bar" + tasks: + - name: "Set the SOMEOTHERVAR" + set_fact: + SOMEOTHERVARNOQA: "Baz" # noqa var-naming + SOMEOTHERVAR: "Bat" +''' @pytest.mark.parametrize( @@ -15,3 +29,9 @@ def test_get_rule_skips_from_line(line: str, expected: str) -> None: """Validate get_rule_skips_from_line.""" x = get_rule_skips_from_line(line) assert x == [expected] + + +def test_playbook_noqa(default_text_runner: RunFromText) -> None: + """Check that noqa is properly taken into account on vars and tasks.""" + results = default_text_runner.run_playbook(PLAYBOOK_WITH_NOQA) + assert len(results) == 2 From bc640a7a213cbcf9d38bee4ceda0f2aa0ba88db8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Jan 2022 19:35:25 +0000 Subject: [PATCH 2/2] chore: auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test/test_skiputils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_skiputils.py b/test/test_skiputils.py index 1defdd601a..aef30dcd3e 100644 --- a/test/test_skiputils.py +++ b/test/test_skiputils.py @@ -4,7 +4,6 @@ from ansiblelint.skip_utils import get_rule_skips_from_line from ansiblelint.testing import RunFromText - PLAYBOOK_WITH_NOQA = '''\ - hosts: all vars: