Skip to content

Commit

Permalink
Indicate how to skip rules on failures (#971)
Browse files Browse the repository at this point in the history
Co-authored-by: Alicia Cozine <[email protected]>
  • Loading branch information
ssbarnea and acozine authored Aug 20, 2020
1 parent 5d8baa2 commit 42e682d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import os
import pathlib
import sys
from typing import TYPE_CHECKING, Set, Type
from typing import TYPE_CHECKING, List, Set, Type

from rich.console import Console
from rich.markdown import Markdown

from ansiblelint import cli, formatters
from ansiblelint.generate_docs import rules_as_rst
Expand All @@ -36,7 +39,10 @@
if TYPE_CHECKING:
from argparse import Namespace

from ansiblelint.errors import MatchError

_logger = logging.getLogger(__name__)
console = Console()


def initialize_logger(level: int = 0) -> None:
Expand Down Expand Up @@ -73,6 +79,21 @@ def choose_formatter_factory(
return r


def hint_about_skips(matches: List["MatchError"]):
"""Display information about how to skip found rules."""
msg = """\
You can skip specific rules by adding them to the skip_list section of your configuration file:
```yaml
# .ansible-lint
skip_list:
"""
matched_rules = {match.rule.id: match.rule.shortdesc for match in matches}
for id in sorted(matched_rules.keys()):
msg += f" - '{id}' # {matched_rules[id]}'\n"
msg += "```"
console.print(Markdown(msg))


def main() -> int:
"""Linter CLI entry point."""
cwd = pathlib.Path.cwd()
Expand Down Expand Up @@ -133,6 +154,7 @@ def main() -> int:
print(formatter.format(match))

if matches:
hint_about_skips(matches)
return 2
else:
return 0
Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ ignore_missing_imports = True
[mypy-importlib_metadata]
ignore_missing_imports = True

[mypy-rich.*]
ignore_missing_imports = True

[mypy-ruamel.*]
ignore_missing_imports = True

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ setup_requires =
install_requires =
ansible >= 2.8
pyyaml
rich
ruamel.yaml >= 0.15.34,<1; python_version < "3.7"
ruamel.yaml >= 0.15.37,<1; python_version >= "3.7"
# NOTE: per issue #509 0.15.34 included in debian backports
Expand Down

0 comments on commit 42e682d

Please sign in to comment.