Skip to content

Forbid adding a link to rules.sonarsource.com #3928

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

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 13 additions & 3 deletions rspec-tools/rspec_tools/validation/sanitize_asciidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Inline code with backquotes is correctly escaped and balanced
* Include commands are not appended to other code
"""

import re
from pathlib import Path

Expand Down Expand Up @@ -52,6 +53,8 @@

CPP = re.compile(r"\b[Cc]\+\+")

RULES_SONARSOURCE = re.compile(r"https:\/\/rules\.sonarsource\.com\/(.*)\/RSPEC-\d+")

# There is a regex trick here:
# We want to skip passthrough macros, to not find pass:[``whatever``]
# We do that by matching
Expand Down Expand Up @@ -199,7 +202,8 @@ def _advance_to_next_backquote(self, line: str, pos: int, line_number: int):
cpp = CPP.search(line, pos)
if cpp:
self._on_error(
line_number, 'To avoid rendering issues, always use the "{cpp}" attribute to refer to the language C++'
line_number,
'To avoid rendering issues, always use the "{cpp}" attribute to refer to the language C++.',
)
return next_pos

Expand All @@ -211,7 +215,7 @@ def _process_description(self, line_number: int, line: str):
line_number - 1,
"""An empty line is missing after the include.
This may result in broken tags and other display issues.
Make sure there are always empty lines before and after each include""",
Make sure there are always empty lines before and after each include.""",
)
if INCLUDE.match(line):
self._previous_line_was_include = True
Expand All @@ -220,11 +224,17 @@ def _process_description(self, line_number: int, line: str):
line_number,
"""An empty line is missing before the include.
This may result in broken tags and other display issues.
Make sure there are always empty lines before and after each include""",
Make sure there are always empty lines before and after each include.""",
)
return
else:
self._previous_line_was_include = False
if RULES_SONARSOURCE.search(line) and not self._is_env_open:
self._on_error(
line_number,
"""Do not put direct links to https://rules.sonarsource.com/.
Just use the rule ID and let cross-reference substitution do its job.""",
)
pos = 0
res = self._advance_to_next_backquote(line, pos, line_number)
# We filter out matches for passthrough. See comment near the BACKQUOTE declaration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
== Title

In this case, there is also an impact on reliability and so it is handled by the rule https://rules.sonarsource.com/java/RSPEC-5810/[S5810].

=== Documentation

* https://rules.sonarsource.com/csharp/RSPEC-6420/[S6420 - Client instances should not be recreated on each Azure Function invocation]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$PATH/include_stuck_after.adoc:3 An empty line is missing after the include.
This may result in broken tags and other display issues.
Make sure there are always empty lines before and after each include
Make sure there are always empty lines before and after each include.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$PATH/include_stuck_before.adoc:2 An empty line is missing before the include.
This may result in broken tags and other display issues.
Make sure there are always empty lines before and after each include
Make sure there are always empty lines before and after each include.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$PATH/link_rule_sonarsource_com.adoc:3 Do not put direct links to https://rules.sonarsource.com/.
Just use the rule ID and let cross-reference substitution do its job.
$PATH/link_rule_sonarsource_com.adoc:7 Do not put direct links to https://rules.sonarsource.com/.
Just use the rule ID and let cross-reference substitution do its job.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$PATH/two_stuck_includes.adoc:3 An empty line is missing after the include.
This may result in broken tags and other display issues.
Make sure there are always empty lines before and after each include
Make sure there are always empty lines before and after each include.
$PATH/two_stuck_includes.adoc:4 An empty line is missing before the include.
This may result in broken tags and other display issues.
Make sure there are always empty lines before and after each include
Make sure there are always empty lines before and after each include.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$PATH/unnamed_language.adoc:1 To avoid rendering issues, always use the "{cpp}" attribute to refer to the language C++
$PATH/unnamed_language.adoc:3 To avoid rendering issues, always use the "{cpp}" attribute to refer to the language C++
$PATH/unnamed_language.adoc:1 To avoid rendering issues, always use the "{cpp}" attribute to refer to the language C++.
$PATH/unnamed_language.adoc:3 To avoid rendering issues, always use the "{cpp}" attribute to refer to the language C++.
1 change: 1 addition & 0 deletions rspec-tools/tests/validation/test_asciidoc_sanitization.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def relative_output(capsys, path: Path):
("include_stuck_after", 1),
("two_stuck_includes", 2),
("unnamed_language", 2),
("link_rule_sonarsource_com", 2),
],
)
def test_need_sanitation(
Expand Down