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

Ensure that yamllint config ignore entries are used #1346

Merged
merged 4 commits into from Feb 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ansiblelint/rules/YamllintRule.py
Expand Up @@ -63,6 +63,7 @@ class YamllintRule(AnsibleLintRule):
)
config_override = YamlLintConfig(file=file)
config_override.extend(config)
config = config_override
break
_logger.debug("Effective yamllint rules used: %s", config.rules)

Expand All @@ -79,7 +80,9 @@ def matchyaml(self, file: Lintable) -> List["MatchError"]:
return matches

if YamllintRule.config:
for p in run_yamllint(file.content, YamllintRule.config):
for p in run_yamllint(
file.content, YamllintRule.config, filepath=file.path
):
matches.append(
self.create_matcherror(
message=p.desc,
Expand Down
14 changes: 11 additions & 3 deletions test/TestExamples.py
@@ -1,14 +1,22 @@
"""Assure samples produced desire outcomes."""
import os

import pytest

from ansiblelint.runner import Runner


@pytest.fixture
def _change_into_examples_dir(request):
os.chdir('examples')
yield
os.chdir('..')


@pytest.mark.usefixtures('_change_into_examples_dir')
def test_example(default_rules_collection):
"""example.yml is expected to have 15 match errors inside."""
result = Runner(
'examples/playbooks/example.yml', rules=default_rules_collection
).run()
result = Runner('playbooks/example.yml', rules=default_rules_collection).run()
assert len(result) == 15


Expand Down