Skip to content

Commit

Permalink
fix discover_lintables: strip ./ from WcMatch return value
Browse files Browse the repository at this point in the history
calling WcMatch('.', ...) causes the resulting file names to be prefixed
with `./`.
If the tests are run in a git-repository, this is not an issue, as git
is preferred of WcMatch in the code.

Therefore remove the `./` prefix from the WcMatch return value to get
the identical expected output.

fixes ansible#1836
  • Loading branch information
sebix committed Feb 1, 2022
1 parent 7a4247e commit 116015f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ansiblelint/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,22 @@ def discover_lintables(options: Namespace) -> Dict[str, Any]:
if out is None:
exclude_pattern = "|".join(str(x) for x in options.exclude_paths)
_logger.info("Looking up for files, excluding %s ...", exclude_pattern)
out = set(
WcMatch(
# remove './' prefix from output of WcMatch
out = {
strip_dotslash_prefix(fname)
for fname in WcMatch(
'.', exclude_pattern=exclude_pattern, flags=RECURSIVE, limit=256
).match()
)
}

return OrderedDict.fromkeys(sorted(out))


def strip_dotslash_prefix(fname: str) -> str:
"""Remove ./ leading from filenames"""
return fname[2:] if fname.startswith('./') else fname


def guess_project_dir(config_file: Optional[str]) -> str:
"""Return detected project dir or current working directory."""
path = None
Expand Down

0 comments on commit 116015f

Please sign in to comment.