Skip to content

Commit

Permalink
Add support for excluding file globs (#1425)
Browse files Browse the repository at this point in the history
Fixes: #1424
  • Loading branch information
greg-hellings authored Mar 4, 2021
1 parent 2bb568c commit 8c543de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
12 changes: 12 additions & 0 deletions test/TestRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
(
Expand Down

0 comments on commit 8c543de

Please sign in to comment.