]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3600 Support Checkstyle rules ClassTypeParameterName and MethodTypeParameterName
authorEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 7 Aug 2012 18:17:54 +0000 (00:17 +0600)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 7 Aug 2012 19:36:54 +0000 (01:36 +0600)
plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sonar-way.xml
plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sun-conventions.xml
plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepositoryTest.java
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayProfileTest.java
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SunConventionsProfileTest.java
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/checkstyle.properties
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/checkstyle/rules/checkstyle/com.puppycrawl.tools.checkstyle.checks.naming.ClassTypeParameterName.html [new file with mode: 0644]
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/checkstyle/rules/checkstyle/com.puppycrawl.tools.checkstyle.checks.naming.MethodTypeParameterName.html [new file with mode: 0644]

index d6798e01b1eef56a6328e786d425a711970a555f..1b91689f319a46bdc1395579c354b8aefe3aa1c0 100644 (file)
         </parameter>\r
       </parameters>\r
     </rule>\r
+    <rule>\r
+      <repositoryKey>checkstyle</repositoryKey>\r
+      <key>com.puppycrawl.tools.checkstyle.checks.naming.ClassTypeParameterName</key>\r
+    </rule>\r
+    <rule>\r
+      <repositoryKey>checkstyle</repositoryKey>\r
+      <key>com.puppycrawl.tools.checkstyle.checks.naming.MethodTypeParameterName</key>\r
+    </rule>\r
   </rules>\r
-</profile>
\ No newline at end of file
+</profile>\r
index 81d18cd226b38291ddc80ee636e1e4f08b897dfb..9eb0857c211b6e88829f0112544094a8ce751cc2 100644 (file)
         </parameter>\r
       </parameters>\r
     </rule>\r
+    <rule>\r
+      <repositoryKey>checkstyle</repositoryKey>\r
+      <key>com.puppycrawl.tools.checkstyle.checks.naming.ClassTypeParameterName</key>\r
+    </rule>\r
+    <rule>\r
+      <repositoryKey>checkstyle</repositoryKey>\r
+      <key>com.puppycrawl.tools.checkstyle.checks.naming.MethodTypeParameterName</key>\r
+    </rule>\r
   </rules>\r
-</profile>
\ No newline at end of file
+</profile>\r
index e8de5fb04c7ecf42891e023bbb64065d07cb764d..64033016da63e5e42355d9d91ef4a6d43711245d 100644 (file)
     <name><![CDATA[One Statement Per Line]]></name>
     <configKey><![CDATA[Checker/TreeWalker/OneStatementPerLine]]></configKey>
   </rule>
+
+  <rule key="com.puppycrawl.tools.checkstyle.checks.naming.ClassTypeParameterName">
+    <priority>MAJOR</priority>
+    <name><![CDATA[Class Type Parameter Name]]></name>
+    <configKey><![CDATA[Checker/TreeWalker/ClassTypeParameterName]]></configKey>
+
+    <param key="format" type="REGULAR_EXPRESSION">
+      <defaultValue>^[A-Z]$</defaultValue>
+    </param>
+  </rule>
+
+  <rule key="com.puppycrawl.tools.checkstyle.checks.naming.MethodTypeParameterName">
+    <priority>MAJOR</priority>
+    <name><![CDATA[Method Type Parameter Name]]></name>
+    <configKey><![CDATA[Checker/TreeWalker/MethodTypeParameterName]]></configKey>
+
+    <param key="format" type="REGULAR_EXPRESSION">
+      <defaultValue>^[A-Z]$</defaultValue>
+    </param>
+  </rule>
+
 </rules>
index 06b9ea9b566cc8fa40404aa2c306c2a2a0bb8e86..b42b99357d8bb2761184848b4525a47d3f9f7f5e 100644 (file)
@@ -26,8 +26,7 @@ import org.sonar.api.rules.XMLRuleParser;
 
 import java.util.List;
 
-import static org.hamcrest.Matchers.greaterThan;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 
 public class CheckstyleRuleRepositoryTest {
@@ -37,6 +36,7 @@ public class CheckstyleRuleRepositoryTest {
     ServerFileSystem fileSystem = mock(ServerFileSystem.class);
     CheckstyleRuleRepository repository = new CheckstyleRuleRepository(fileSystem, new XMLRuleParser());
     List<Rule> rules = repository.createRules();
-    assertThat(rules.size(), greaterThan(100));
+    assertThat(rules.size()).isEqualTo(129);
   }
+
 }
index 8db437da2d5c6daaa090ee18505b60672b4f2f8f..29c69ed9244495624ff7555e36dac1bc682d48e6 100644 (file)
@@ -30,9 +30,7 @@ import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.utils.ValidationMessages;
 
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -44,8 +42,8 @@ public class SonarWayProfileTest {
     ProfileDefinition sonarWay = new SonarWayProfile(new XMLProfileParser(newRuleFinder(), mock(MetricFinder.class)));
     ValidationMessages validation = ValidationMessages.create();
     RulesProfile profile = sonarWay.createProfile(validation);
-    assertThat(profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY).size(), greaterThan(1));
-    assertThat(validation.hasErrors(), is(false));
+    assertThat(profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY).size()).isEqualTo(32);
+    assertThat(validation.hasErrors()).isFalse();
   }
 
   private RuleFinder newRuleFinder() {
@@ -57,4 +55,5 @@ public class SonarWayProfileTest {
     });
     return ruleFinder;
   }
+
 }
index 26913a7ae48919efa7b64a0408ec4bc3f69e4a74..dc49069e45e8353659c76c5cbe7e20765ac8f233 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.plugins.checkstyle;
 
-import org.hamcrest.core.Is;
 import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
@@ -31,20 +30,20 @@ import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.utils.ValidationMessages;
 
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public class SunConventionsProfileTest {
+
   @Test
   public void shouldCreateProfile() {
     ProfileDefinition definition = new SunConventionsProfile(new XMLProfileParser(newRuleFinder(), mock(MetricFinder.class)));
     ValidationMessages validation = ValidationMessages.create();
     RulesProfile sunProfile = definition.createProfile(validation);
-    assertThat(sunProfile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY).size(), greaterThan(1));
-    assertThat(validation.hasErrors(), Is.is(false));
+    assertThat(sunProfile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY).size()).isEqualTo(59);
+    assertThat(validation.hasErrors()).isFalse();
   }
 
   private RuleFinder newRuleFinder() {
index 07491e32255902ce61a6b62ff9685d4539c5c64f..2f7c1e230a729f3e94523d8076d9069010e452c7 100644 (file)
@@ -338,3 +338,5 @@ rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.sizes.MethodCountCheck.pa
 rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.sizes.MethodCountCheck.param.maxProtected=maximum allowable number of protected methods.
 rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.sizes.MethodCountCheck.param.maxPublic=maximum allowable number of public methods.
 rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.coding.OneStatementPerLineCheck.name=One Statement Per Line
+rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.naming.ClassTypeParameterName=Class Type Parameter Name
+rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.naming.MethodTypeParameterName=Method Type Parameter Name
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/checkstyle/rules/checkstyle/com.puppycrawl.tools.checkstyle.checks.naming.ClassTypeParameterName.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/checkstyle/rules/checkstyle/com.puppycrawl.tools.checkstyle.checks.naming.ClassTypeParameterName.html
new file mode 100644 (file)
index 0000000..31398fe
--- /dev/null
@@ -0,0 +1 @@
+Checks that class parameter names conform to the specified format
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/checkstyle/rules/checkstyle/com.puppycrawl.tools.checkstyle.checks.naming.MethodTypeParameterName.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/checkstyle/rules/checkstyle/com.puppycrawl.tools.checkstyle.checks.naming.MethodTypeParameterName.html
new file mode 100644 (file)
index 0000000..cfdf3b0
--- /dev/null
@@ -0,0 +1 @@
+Checks that method type parameter names conform to the specified format