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

using HTML description #31

Merged
merged 1 commit into from
Mar 13, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/org/sonar/cxx/MyCustomRulesDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ public class MyCustomRulesDefinition extends CustomCxxRulesDefinition {

@Override
public String repositoryName() {
return "MyCustomCxxRepository";
return "Custom CXX";
}

@Override
public String repositoryKey() {
return "mycustomcxxrepo";
// The html descriptions for the rules of repository must be stored in the path '/org/sonar/l10n/cxx/rules/mycxx'.
// If the return value of 'repositoryKey' is changed, the storage location in 'resources' must also be adjusted.
return "mycxx";
}

@SuppressWarnings("rawtypes")
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/sonar/cxx/checks/UsingNamespaceCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
import org.sonar.cxx.squidbridge.checks.SquidCheck;
import org.sonar.cxx.tag.Tag;

// In case you are adding a .html description in resources, the .html file name should match the rule key.
// In this sample the name must be 'UsingNamespace.html'.
@Rule(
key = "UsingNamespace",
priority = Priority.BLOCKER,
name = "Using namespace directives are not allowed",
tags = {Tag.CONVENTION},
description = "Using namespace directives are not allowed.")
priority = Priority.BLOCKER,
name = "Using namespace directives are not allowed",
tags = {Tag.CONVENTION}
// second possibility to add a rule description:
//,description = "Using namespace directives are not allowed."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description here can be retained. If we use the addHtmlDescription method, we can override the description. If you do not use the addHtmlDescription method, we can use this description as basic description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I haven't tried what happens when both are in? Does the html description overwrite the description?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this part of the code and it worked fine.
test version :
cxx: master (c753dd71932baabd7dcbe57e3a7985a48d733a60)
plugin: master (d221e45)

image

This design idea comes from the Sonar official rules custom plug-in demo.
image
image

)
@SqaleConstantRemediation("5min")
@ActivatedByDefault
public class UsingNamespaceCheck extends SquidCheck<Grammar> {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/sonar/cxx/checks/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package org.sonar.cxx.checks;

import javax.annotation.ParametersAreNonnullByDefault;
4 changes: 4 additions & 0 deletions src/main/java/org/sonar/cxx/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package org.sonar.cxx;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p>
Using namespace directives are not allowed.

Using-directives (using namespace foo) are dangerous enough to be banned by the Google style guide. Dont use them in code that will ever need to be upgraded.
Using-directives (using namespace foo) are dangerous enough to be banned by the Google style guide. Don't use them in code that will ever need to be upgraded.
If you wish to shorten a name, you may instead use a namespace alias (namespace baz = ::foo::bar::baz;) or a using-declaration (using ::foo::SomeName), both of which are permitted by the style guide in certain contexts (e.g. in *.cc files).
</p>

Expand All @@ -15,6 +15,7 @@ <h2>Non-compliant Sample</h2>
</pre>

<h2>Compliant Sample</h2>
<p>ToDo</p>

<pre>
class MyClass {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/sonar/cxx/MyCustomRulesDefinitionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class MyCustomRulesDefinitionTest {
@Test
public void test() {
MyCustomRulesDefinition definition = new MyCustomRulesDefinition();
assertThat(definition.repositoryName()).isEqualTo("MyCustomCxxRepository");
assertThat(definition.repositoryKey()).isEqualTo("mycustomcxxrepo");
assertThat(definition.repositoryName()).isEqualTo("Custom CXX");
assertThat(definition.repositoryKey()).isEqualTo("mycxx");
assertThat(definition.checkClasses().length).isEqualTo(1);
}

Expand Down