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

Feat/explicitly define help url for each rule #1138

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions robocop/checkers/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from robocop.checkers import RawFileChecker, VisitorChecker
from robocop.rules import Rule, RuleParam, RuleSeverity
from robocop.utils import ROBOT_VERSION
from robocop.utils.misc import get_rule_help_url


def regex(value):
Expand Down Expand Up @@ -48,6 +49,7 @@ def regex(value):

""",
added_in_version="1.0.0",
help_url=get_rule_help_url("default", "todo-in-comment"),
),
"0702": Rule(
RuleParam(
Expand Down Expand Up @@ -86,6 +88,7 @@ def regex(value):

""",
added_in_version="1.0.0",
help_url=get_rule_help_url("default", "missing-space-after-comment"),
Lakitna marked this conversation as resolved.
Show resolved Hide resolved
),
"0703": Rule(
rule_id="0703",
Expand All @@ -106,6 +109,7 @@ def regex(value):

""",
added_in_version="1.0.0",
help_url=get_rule_help_url("default", "invalid-comment"),
),
"0704": Rule(
rule_id="0704",
Expand Down Expand Up @@ -135,6 +139,7 @@ def regex(value):

""",
added_in_version="1.3.0",
help_url=get_rule_help_url("default", "ignored-data"),
),
"0705": Rule(
rule_id="0705",
Expand All @@ -145,6 +150,7 @@ def regex(value):
Some code editors can save Robot file using BOM encoding. Ensure that file is saved in UTF-8 encoding.
""",
added_in_version="1.7.0",
help_url=get_rule_help_url("default", "bom-encoding-in-file"),
),
}

Expand Down
4 changes: 4 additions & 0 deletions robocop/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def __init__(
added_in_version: str | None = None,
enabled: bool = True,
deprecated: bool = False,
help_url: str = "",
):
"""
:param params: RuleParam() or SeverityThreshold() instances
Expand All @@ -311,6 +312,7 @@ def __init__(
:param added_in_version: Version of the Robocop when the Rule was created
:param enabled: Enable/disable rule by default using this parameter
:param deprecated: Deprecate rule. If rule is used in configuration, it will issue a warning.
:param help_url: URL to rule documentation or other help resource.
"""
self.rule_id = rule_id
self.name = name
Expand Down Expand Up @@ -342,6 +344,7 @@ def __init__(
self.added_in_version = added_in_version
self.community_rule = False
self.category_id = None
self.help_url = help_url

@property
def severity(self):
Expand Down Expand Up @@ -487,6 +490,7 @@ def __init__(
self.enabled = rule.enabled
self.rule_id = rule.rule_id
self.name = rule.name
self.help_url = rule.help_url
self.severity = self.get_severity(overwrite_severity, rule, sev_threshold_value)
self.desc = msg
self.source = source
Expand Down
15 changes: 14 additions & 1 deletion robocop/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pathlib import Path
from re import Pattern
from tokenize import generate_tokens
from typing import Literal

import platformdirs
from robot.api import Token
Expand Down Expand Up @@ -120,7 +121,7 @@ def issues_to_lsp_diagnostic(issues) -> list[dict]:
"code": issue.rule_id,
"source": "robocop",
"message": issue.desc,
"codeDescription": {"href": f"{ROBOCOP_RULES_URL.format(version=__version__)}#{issue.name}"},
"codeDescription": {"href": issue.help_url},
}
for issue in issues
]
Expand Down Expand Up @@ -420,3 +421,15 @@ def parse_test_case_order_param(value: str) -> list:
"teardown": Token.TEARDOWN,
}
return parse_order_comma_sep_list(value, mapping)


def get_rule_help_url(type: Literal["default", "community"], rule_name: str):
base_url = f"https://robocop.readthedocs.io/en/{__version__}"

if type == "default":
return f"{base_url}/rules_list.html#{rule_name}"

if type == "community":
return f"{base_url}/community_rules.html#{rule_name}"

raise TypeError(f"Can't create help url for rule. Unexpected type '{type}'")
Loading