Skip to content

Commit

Permalink
Ensure that yamllint config ignore entries are used (#1346)
Browse files Browse the repository at this point in the history
* Ensure that yamllint config ignore entries are used.

* Linting.

* Change into examples/ for test.

This ensures that the top-level .yamllint config does not prevent some of the
errors to be reported in this file.

* More linting.
  • Loading branch information
felixfontein committed Feb 14, 2021
1 parent bf7ad5d commit 4a1b96c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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

0 comments on commit 4a1b96c

Please sign in to comment.