From cc3865455533d6ddbf5be3341522702eaa924898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Wirth?= Date: Thu, 7 Mar 2024 16:26:15 +0100 Subject: [PATCH] using HTML description - 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. --- .../java/org/sonar/cxx/MyCustomRulesDefinition.java | 6 ++++-- .../org/sonar/cxx/checks/UsingNamespaceCheck.java | 12 ++++++++---- src/main/java/org/sonar/cxx/checks/package-info.java | 4 ++++ src/main/java/org/sonar/cxx/package-info.java | 4 ++++ .../cxx/rules/{cxx => mycxx}/UsingNamespace.html | 3 ++- .../org/sonar/cxx/MyCustomRulesDefinitionTest.java | 4 ++-- 6 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/sonar/cxx/checks/package-info.java create mode 100644 src/main/java/org/sonar/cxx/package-info.java rename src/main/resources/org/sonar/l10n/cxx/rules/{cxx => mycxx}/UsingNamespace.html (87%) diff --git a/src/main/java/org/sonar/cxx/MyCustomRulesDefinition.java b/src/main/java/org/sonar/cxx/MyCustomRulesDefinition.java index 06bd459..28045c3 100644 --- a/src/main/java/org/sonar/cxx/MyCustomRulesDefinition.java +++ b/src/main/java/org/sonar/cxx/MyCustomRulesDefinition.java @@ -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") diff --git a/src/main/java/org/sonar/cxx/checks/UsingNamespaceCheck.java b/src/main/java/org/sonar/cxx/checks/UsingNamespaceCheck.java index 23db115..0dd0b61 100644 --- a/src/main/java/org/sonar/cxx/checks/UsingNamespaceCheck.java +++ b/src/main/java/org/sonar/cxx/checks/UsingNamespaceCheck.java @@ -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 { diff --git a/src/main/java/org/sonar/cxx/checks/package-info.java b/src/main/java/org/sonar/cxx/checks/package-info.java new file mode 100644 index 0000000..3b88bbb --- /dev/null +++ b/src/main/java/org/sonar/cxx/checks/package-info.java @@ -0,0 +1,4 @@ +@ParametersAreNonnullByDefault +package org.sonar.cxx.checks; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/org/sonar/cxx/package-info.java b/src/main/java/org/sonar/cxx/package-info.java new file mode 100644 index 0000000..2aa0cdc --- /dev/null +++ b/src/main/java/org/sonar/cxx/package-info.java @@ -0,0 +1,4 @@ +@ParametersAreNonnullByDefault +package org.sonar.cxx; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/resources/org/sonar/l10n/cxx/rules/cxx/UsingNamespace.html b/src/main/resources/org/sonar/l10n/cxx/rules/mycxx/UsingNamespace.html similarity index 87% rename from src/main/resources/org/sonar/l10n/cxx/rules/cxx/UsingNamespace.html rename to src/main/resources/org/sonar/l10n/cxx/rules/mycxx/UsingNamespace.html index 49d8eb8..7436d69 100644 --- a/src/main/resources/org/sonar/l10n/cxx/rules/cxx/UsingNamespace.html +++ b/src/main/resources/org/sonar/l10n/cxx/rules/mycxx/UsingNamespace.html @@ -1,7 +1,7 @@

Using namespace directives are not allowed. -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. +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).

@@ -15,6 +15,7 @@

Non-compliant Sample

Compliant Sample

+

ToDo

 class MyClass {
diff --git a/src/test/java/org/sonar/cxx/MyCustomRulesDefinitionTest.java b/src/test/java/org/sonar/cxx/MyCustomRulesDefinitionTest.java
index 8032bdb..0a38e38 100644
--- a/src/test/java/org/sonar/cxx/MyCustomRulesDefinitionTest.java
+++ b/src/test/java/org/sonar/cxx/MyCustomRulesDefinitionTest.java
@@ -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);
   }