Skip to content

Commit

Permalink
Merge pull request #31 from SonarOpenCommunity/html_annotations
Browse files Browse the repository at this point in the history
using HTML description
  • Loading branch information
guwirth authored Mar 13, 2024
2 parents e1d4e2e + cc38654 commit 53e61e9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
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."
)
@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

0 comments on commit 53e61e9

Please sign in to comment.