Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow noqa to be used in more lintable kinds #1819

Merged
merged 2 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/ansiblelint/skip_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/test_skiputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
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(
Expand All @@ -15,3 +28,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