Skip to content

Commit

Permalink
Include links to documentation for default output (#2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Aug 29, 2022
1 parent 2293a93 commit 5161329
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/ansiblelint/_internal/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class BaseRule:
# _order 1 for rules that check that data can be loaded
# _order 5 implicit for normal rules
_order: int = 5
RULE_DOC_URL = "https://ansible-lint.readthedocs.io/en/latest/rules/"

@property
def url(self) -> str:
"""Return rule documentation url."""
return self.link or self.RULE_DOC_URL + self.id + "/"

@property
def shortdesc(self) -> str:
Expand Down
5 changes: 2 additions & 3 deletions src/ansiblelint/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Formatter(BaseFormatter): # type: ignore

def format(self, match: MatchError) -> str:
_id = getattr(match.rule, "id", "000")
result = f"[error_code]{_id}[/][dim]:[/] [error_title]{self.escape(match.message)}[/]"
result = f"[error_code][link={match.rule.url}]{_id}[/link][/][dim]:[/] [error_title]{self.escape(match.message)}[/]"
if match.tag:
result += f" [dim][error_code]({self.escape(match.tag)})[/][/]"
result += (
Expand Down Expand Up @@ -208,7 +208,6 @@ class SarifFormatter(BaseFormatter[Any]):
TOOL_NAME = "Ansible-lint"
TOOL_URL = "https://github.com/ansible/ansible-lint"
SARIF_SCHEMA_VERSION = "2.1.0"
RULE_DOC_URL = "https://ansible-lint.readthedocs.io/en/latest/default_rules/"
SARIF_SCHEMA = (
"https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json"
)
Expand Down Expand Up @@ -278,7 +277,7 @@ def _to_sarif_rule(self, match: MatchError) -> dict[str, Any]:
"help": {
"text": str(match.rule.description),
},
"helpUri": self.RULE_DOC_URL + "#" + match.rule.id,
"helpUri": match.rule.url,
"properties": {"tags": match.rule.tags},
}
if match.rule.link:
Expand Down
5 changes: 5 additions & 0 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
class AnsibleLintRule(BaseRule):
"""AnsibleLintRule should be used as base for writing new rules."""

@property
def url(self) -> str:
"""Return rule documentation url."""
return self.RULE_DOC_URL + self.id + "/"

@property
def rule_config(self) -> dict[str, Any]:
"""Retrieve rule specific configuration."""
Expand Down

0 comments on commit 5161329

Please sign in to comment.