Skip to content

Commit

Permalink
Add support for excluding file globs
Browse files Browse the repository at this point in the history
Addresses #1424
  • Loading branch information
greg-hellings committed Mar 4, 2021
1 parent 2bb568c commit 98ef1ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import multiprocessing
import multiprocessing.pool
import os
from pathlib import Path
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, FrozenSet, Generator, List, Optional, Set, Union

Expand Down Expand Up @@ -84,8 +85,9 @@ 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 98ef1ca

Please sign in to comment.