diff --git a/src/ansiblelint/runner.py b/src/ansiblelint/runner.py index 4fbcf7d201..26cb35b522 100644 --- a/src/ansiblelint/runner.py +++ b/src/ansiblelint/runner.py @@ -4,6 +4,7 @@ import multiprocessing.pool import os from dataclasses import dataclass +from pathlib import Path from typing import TYPE_CHECKING, Any, FrozenSet, Generator, List, Optional, Set, Union import ansiblelint.skip_utils @@ -84,8 +85,12 @@ def is_excluded(self, file_path: str) -> bool: # Exclusions should be evaluated only using absolute paths in order # to work correctly. abs_path = os.path.abspath(file_path) + _file_path = Path(file_path) - return any(abs_path.startswith(path) for path in self.exclude_paths) + return any( + abs_path.startswith(path) or _file_path.match(path) + for path in self.exclude_paths + ) def run(self) -> List[MatchError]: """Execute the linting process.""" diff --git a/test/TestRunner.py b/test/TestRunner.py index e4e028034b..ce69ae51bc 100644 --- a/test/TestRunner.py +++ b/test/TestRunner.py @@ -69,6 +69,18 @@ def test_runner_exclude_paths(default_rules_collection) -> None: assert len(matches) == 0 +def test_runner_exclude_globs(default_rules_collection) -> None: + """Test that globs work.""" + runner = Runner( + 'examples/playbooks/example.yml', + rules=default_rules_collection, + exclude_paths=['**/example.yml'], + ) + + matches = runner.run() + assert len(matches) == 0 + + @pytest.mark.parametrize( ('formatter_cls'), (