Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
23 changes: 15 additions & 8 deletions post/clang_tidy_review/clang_tidy_review/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,9 +959,10 @@ def create_review(

line_ranges = get_line_ranges(diff, files)
if line_ranges == "[]":
with message_group("No lines added in this PR!"), REVIEW_FILE.open(
"w"
) as review_file:
with (
message_group("No lines added in this PR!"),
REVIEW_FILE.open("w") as review_file,
):
json.dump(
{
"body": "clang-tidy found no lines added",
Expand Down Expand Up @@ -1289,11 +1290,17 @@ def decorate_check_names(comment: str) -> str:
exception: if the first group starts with 'clang' such as 'clang-diagnostic-error'
exception to the exception: if the string starts with 'clang-analyzer', in which case, make it the first group
"""
version = "extra"
url = f"https://clang.llvm.org/{version}/clang-tidy/checks"
regex = r"(\[((?:clang-analyzer)|(?:(?!clang)[\w]+))-([\.\w-]+)\]$)"
subst = f"[\\g<1>({url}/\\g<2>/\\g<3>.html)]"
return re.sub(regex, subst, comment, count=1, flags=re.MULTILINE)
regex = r"\[(((?:clang-analyzer)|(?:(?!clang)[\w]+))-([\.\w-]+))\]$"

def repl(m: re.Match[str]) -> str:
match m.group(2):
case "clazy":
url = f"https://invent.kde.org/sdk/clazy/-/blob/master/docs/checks/README-{m.group(3)}.md"
case other:
url = f"https://clang.llvm.org/extra/clang-tidy/checks/{other}/{m.group(3)}.html"
return f"[[{m.group(1)}]({url})]"

return re.sub(regex, repl, comment, count=1, flags=re.MULTILINE)


def decorate_comment(comment: ReviewComment) -> ReviewComment:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ def test_decorate_comment_body():
== clang_analyzer_message_decorated
)

clazy_message = "warning: The QColor ctor taking RGB int value is cheaper than one taking string literals [clazy-qcolor-from-literal]"
clazy_message_decorated = "warning: The QColor ctor taking RGB int value is cheaper than one taking string literals [[clazy-qcolor-from-literal](https://invent.kde.org/sdk/clazy/-/blob/master/docs/checks/README-qcolor-from-literal.md)]"
assert ctr.decorate_check_names(clazy_message) == clazy_message_decorated

# Not sure it's necessary to link to prior version documentation especially since we have to map versions such as
# "17" to "17.0.1" and "18" to "18.1.0" because no other urls exist
# version_message_pre_15_version = "14.0.0"
Expand Down