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

ruff: Address A #3379

Merged
merged 1 commit into from
Apr 27, 2023
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
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ htpasswd
hwchksum
hwcksum
idempotency
ignorelist
importlib
iniconfig
inlinehilite
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ ignore = [
"PLW2901", # PLW2901: Redefined loop variable
"RET504", # Unnecessary variable assignment before `return` statement
# temporary disabled until we fix them:
"A",
"ANN",
"ARG002", # Unused method argument (currently in too many places)
"D",
Expand All @@ -242,6 +241,9 @@ target-version = "py39"
# Same as Black.
line-length = 88

[tool.ruff.flake8-builtins]
builtins-ignorelist = ["id"]

[tool.ruff.flake8-pytest-style]
parametrize-values-type = "tuple"

Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/_internal/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BaseRule:
_collection: RulesCollection | None = None

@property
def help(self) -> str:
def help(self) -> str: # noqa: A003
"""Return a help markdown string for the rule."""
if self._help is None:
self._help = ""
Expand Down
6 changes: 3 additions & 3 deletions src/ansiblelint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ def render_matches(self, matches: list[MatchError]) -> None: # noqa: C901
for match in ignored_matches:
if match.ignored:
# highlight must be off or apostrophes may produce unexpected results
console.print(self.formatter.format(match), highlight=False)
console.print(self.formatter.apply(match), highlight=False)
if fatal_matches:
_logger.warning(
"Listing %s violation(s) that are fatal",
len(fatal_matches),
)
for match in fatal_matches:
if not match.ignored:
console.print(self.formatter.format(match), highlight=False)
console.print(self.formatter.apply(match), highlight=False)

# If run under GitHub Actions we also want to emit output recognized by it.
if os.getenv("GITHUB_ACTIONS") == "true" and os.getenv("GITHUB_WORKFLOW"):
Expand All @@ -92,7 +92,7 @@ def render_matches(self, matches: list[MatchError]) -> None: # noqa: C901
formatter = formatters.AnnotationsFormatter(self.options.cwd, True)
for match in itertools.chain(fatal_matches, ignored_matches):
console_stderr.print(
formatter.format(match),
formatter.apply(match),
markup=False,
highlight=False,
)
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ def __init__( # pylint: disable=too-many-arguments,redefined-builtin
nargs: int | str | None = None,
const: Any = None,
default: Any = None,
type: Callable[[str], Any] | None = None,
type: Callable[[str], Any] | None = None, # noqa: A002
choices: list[Any] | None = None,
required: bool = False,
help: str | None = None,
help: str | None = None, # noqa: A002
metavar: str | None = None,
) -> None:
"""Create the argparse action with WriteArg-specific defaults."""
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Options: # pylint: disable=too-many-instance-attributes,too-few-public-me
cwd: Path = Path(".") # noqa: RUF009
display_relative_path: bool = True
exclude_paths: list[str] = field(default_factory=list)
format: str = "brief"
format: str = "brief" # noqa: A003
lintables: list[str] = field(default_factory=list)
list_rules: bool = False
list_tags: bool = False
Expand Down
10 changes: 5 additions & 5 deletions 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: str | Path) -> str | Path:
# Use os.path.relpath 'cause Path.relative_to() misbehaves
return os.path.relpath(path, start=self.base_dir)

def format(self, match: MatchError) -> str:
def apply(self, match: MatchError) -> str:
"""Format a match error."""
return str(match)

Expand All @@ -56,7 +56,7 @@ def escape(text: str) -> str:
class Formatter(BaseFormatter): # type: ignore
"""Default output formatter of ansible-lint."""

def format(self, match: MatchError) -> str:
def apply(self, match: MatchError) -> str:
_id = getattr(match.rule, "id", "000")
result = f"[{match.level}][bold][link={match.rule.url}]{self.escape(match.tag)}[/link][/][/][dim]:[/] [{match.level}]{self.escape(match.message)}[/]"
if match.level != "error":
Expand All @@ -76,7 +76,7 @@ def format(self, match: MatchError) -> str:
class QuietFormatter(BaseFormatter[Any]):
"""Brief output formatter for ansible-lint."""

def format(self, match: MatchError) -> str:
def apply(self, match: MatchError) -> str:
return (
f"[{match.level}]{match.rule.id}[/] "
f"[filename]{self._format_path(match.filename or '')}[/]:{match.position}"
Expand All @@ -86,7 +86,7 @@ def format(self, match: MatchError) -> str:
class ParseableFormatter(BaseFormatter[Any]):
"""Parseable uses PEP8 compatible format."""

def format(self, match: MatchError) -> str:
def apply(self, match: MatchError) -> str:
result = (
f"[filename]{self._format_path(match.filename or '')}[/][dim]:{match.position}:[/] "
f"[{match.level}][bold]{self.escape(match.tag)}[/bold]"
Expand All @@ -113,7 +113,7 @@ class AnnotationsFormatter(BaseFormatter): # type: ignore
Supported levels: debug, warning, error
"""

def format(self, match: MatchError) -> str:
def apply(self, match: MatchError) -> str:
"""Prepare a match instance for reporting as a GitHub Actions annotation."""
file_path = self._format_path(match.filename or "")
line_num = match.lineno
Expand Down
6 changes: 3 additions & 3 deletions test/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_format_coloured_string() -> None:
lintable=Lintable("filename.yml", content=""),
rule=rule,
)
formatter.format(match)
formatter.apply(match)


def test_unicode_format_string() -> None:
Expand All @@ -53,7 +53,7 @@ def test_unicode_format_string() -> None:
lintable=Lintable("filename.yml", content=""),
rule=rule,
)
formatter.format(match)
formatter.apply(match)


def test_dict_format_line() -> None:
Expand All @@ -65,4 +65,4 @@ def test_dict_format_line() -> None:
lintable=Lintable("filename.yml", content=""),
rule=rule,
)
formatter.format(match)
formatter.apply(match)
2 changes: 1 addition & 1 deletion test/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_runner_unicode_format(

matches = runner.run()

formatter.format(matches[0])
formatter.apply(matches[0])


@pytest.mark.parametrize(
Expand Down