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

Include links to documentation for default output #2353

Merged
merged 1 commit into from
Aug 29, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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