Skip to content

Commit

Permalink
Fix config file outside project_dir bug (#2600)
Browse files Browse the repository at this point in the history
Also improve behavior when broken symlinks are present inside
the repository.

Fixes: #2598
  • Loading branch information
ssbarnea authored Oct 13, 2022
1 parent 644553e commit 1bb0f2d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/ansiblelint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,16 @@ def get_config(arguments: list[str]) -> Namespace:
f"'rich' or 'md' are supported with -f."
)

# save info about custom config file, as options.config_file may be modified by merge_config
has_custom_config = not options.config_file

file_config = load_config(options.config_file)

config = merge_config(file_config, options)

options.rulesdirs = get_rules_dirs(options.rulesdir, options.use_default_rules)

if options.project_dir == ".":
if has_custom_config and options.project_dir == ".":
project_dir = guess_project_dir(options.config_file)
options.project_dir = os.path.expanduser(normpath(project_dir))

Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def run(self) -> list[MatchError]: # noqa: C901
continue
try:
lintable.data
except RuntimeError as exc:
except (RuntimeError, FileNotFoundError) as exc:
matches.append(
MatchError(
filename=lintable,
Expand Down
4 changes: 4 additions & 0 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@ def get_lintables(
_logger.debug("Ignored %s due to: %s", path, exc)
continue

if path.is_symlink() and not path.exists():
_logger.warning("Ignored broken symlink %s -> %s", path, path.resolve())
continue

lintables.append(Lintable(path))

# stage 2: guess roles from current lintables, as there is no unique
Expand Down

0 comments on commit 1bb0f2d

Please sign in to comment.