Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid reporting matcherrors against cwd #1440

Merged
merged 1 commit into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ the following:
If playbooks include other playbooks, or tasks, or handlers or roles, these
are also handled:

.. command-output:: ansible-lint -p examples/playbooks/include.yml
.. command-output:: ansible-lint --offline -p examples/playbooks/include.yml
:cwd: ..
:returncode: 2
:nostderr:
Expand Down
4 changes: 1 addition & 3 deletions src/ansiblelint/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Exceptions and error representations."""
import functools
import os
from typing import Any, Optional, Union

from ansiblelint._internal.rules import BaseRule, RuntimeErrorRule
Expand Down Expand Up @@ -47,13 +46,12 @@ def __init__(
self.linenumber = linenumber
self.column = column
self.details = details
self.filename = ""
if filename:
if isinstance(filename, Lintable):
self.filename = normpath(str(filename.path))
else:
self.filename = normpath(filename)
else:
self.filename = os.getcwd()
self.rule = rule
self.ignored = False # If set it will be displayed but not counted as failure
# This can be used by rules that can report multiple errors type, so
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _format_path(self, path: Union[str, Path]) -> str:
if isinstance(path, Path):
path = str(path) # Drop when Python 3.5 is no longer supported

if not self._base_dir:
if not self._base_dir or not path:
return path
# Use os.path.relpath 'cause Path.relative_to() misbehaves
return os.path.relpath(path, start=self._base_dir)
Expand Down
3 changes: 1 addition & 2 deletions src/ansiblelint/rules/MetaMainHasInfoRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,4 @@ def matchplay(self, file: Lintable, data: "odict[str, Any]") -> List[MatchError]
self.create_matcherror(message=err, filename=file)
for err in _galaxy_info_errors_itr(galaxy_info)
]

return [self.create_matcherror(message="No 'galaxy_info' found")]
return [self.create_matcherror(message="No 'galaxy_info' found", filename=file)]
5 changes: 5 additions & 0 deletions src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def is_excluded(self, file_path: str) -> bool:

# Exclusions should be evaluated only using absolute paths in order
# to work correctly.
if not file_path:
return False

abs_path = os.path.abspath(file_path)
_file_path = Path(file_path)

Expand Down Expand Up @@ -165,6 +168,8 @@ def _emit_matches(self, files: List[Lintable]) -> Generator[MatchError, None, No
self.lintables.add(child)
files.append(child)
except MatchError as e:
if not e.filename:
e.filename = str(lintable.path)
e.rule = LoadingFailureRule()
yield e
except AttributeError:
Expand Down