Skip to content

Commit

Permalink
squash: fix comments, take 79
Browse files Browse the repository at this point in the history
  • Loading branch information
happz committed May 5, 2023
1 parent a90adcf commit f4bebbd
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions tmt/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Methods whose names start with ``lint_*`` prefix are considered linters.
def lint_path_exists(self) -> LinterReturn:
# A linter must have a docstring which is then used to generate documentation,
# e.g. when ``lint --list-checks`` is called. The docstring must being with
# e.g. when ``lint --list-checks`` is called. The docstring must begin with
# a linter *id*. The id should match ``[CTPS]\\d\\d\\d`` regular expression:
# ``C``ommon, ``T``est, ``P``lan, ``S``tory, plus a three-digit serial number
# of the linter among its peers.
Expand Down Expand Up @@ -210,11 +210,10 @@ def resolve_enabled_linters(
return linters

def lint(
self,
enable_checks: Optional[List[str]] = None,
disable_checks: Optional[List[str]] = None,
enforce_checks: Optional[List[str]] = None
) -> Tuple[bool, List[LinterRuling]]:
self,
enable_checks: Optional[List[str]] = None,
disable_checks: Optional[List[str]] = None,
enforce_checks: Optional[List[str]] = None) -> Tuple[bool, List[LinterRuling]]:
"""
Check the instance against a battery of linters and report results.
Expand Down Expand Up @@ -256,7 +255,7 @@ def format_linters(cls) -> str:
hints: List[str] = []

for linter in sorted(cls.get_linter_registry(), key=lambda x: x.id):
# Thsi has been already verified when registering the linter
# This has been already verified when registering the linter
assert linter.callback.__doc__ is not None

hints.append(textwrap.dedent(linter.callback.__doc__).strip())
Expand All @@ -267,6 +266,15 @@ def format_linters(cls) -> str:
def filter_allowed_checks(
rulings: Iterable[LinterRuling],
outcomes: Optional[List[LinterOutcome]] = None) -> Generator[LinterRuling, None, None]:
"""
Filter only rulings whose outcomes are allowed.
:param rulings: rulings to process.
:param outcomes: a list of allowed ruling outcomes, :py:class:`LinterOutcome`.
If not set, all outcomes are allowed.
:yields: rulings with allowed outcomes.
"""

outcomes = outcomes or []

for linter, actual_outcome, eventual_outcome, message in rulings:
Expand All @@ -277,6 +285,13 @@ def filter_allowed_checks(


def format_rulings(rulings: Iterable[LinterRuling]) -> Generator[str, None, None]:
"""
Format rulings for printing or logging.
:param rulings: rulings to format.
:yields: rulings formatted as separate strings.
"""

display_eventual = any(
actual_outcome != eventual_outcome for _, actual_outcome, eventual_outcome, _ in rulings)

Expand Down

0 comments on commit f4bebbd

Please sign in to comment.