mirror of
https://github.com/alibaba/p3c.git
synced 2025-10-14 23:21:32 +00:00
add rules
[Recommended] The total number of lines for a method should not be more than 80 [Recommended] Avoid using the negation operator '!' [Mandatory] When doing date formatting, "y" should be written in lowercase for "year" in a pattern statement and some bug fix
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<feature
|
||||
id="com.alibaba.smartfox.eclipse.feature"
|
||||
label="%feature.label"
|
||||
version="1.0.4.qualifier"
|
||||
version="1.0.5.qualifier"
|
||||
provider-name="%feature.provider_name"
|
||||
plugin="com.alibaba.smartfox.eclipse.plugin"
|
||||
image="smartfox.png">
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.smartfox.eclipse</groupId>
|
||||
<artifactId>smartfox-eclipse</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<version>1.0.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>com.alibaba.smartfox.eclipse.feature</artifactId>
|
||||
<packaging>eclipse-feature</packaging>
|
||||
|
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: com.alibaba.smartfox.eclipse.plugin
|
||||
Bundle-SymbolicName: com.alibaba.smartfox.eclipse.plugin;singleton:=true
|
||||
Bundle-Version: 1.0.4.qualifier
|
||||
Bundle-Version: 1.0.5.qualifier
|
||||
Bundle-Activator: com.alibaba.smartfox.eclipse.SmartfoxActivator
|
||||
Bundle-Vendor: Alibaba
|
||||
Require-Bundle: org.eclipse.ui,
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.smartfox.eclipse</groupId>
|
||||
<artifactId>smartfox-eclipse</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<version>1.0.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>com.alibaba.smartfox.eclipse.plugin</artifactId>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.smartfox.eclipse</groupId>
|
||||
<artifactId>smartfox-eclipse</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<version>1.0.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>com.alibaba.smartfox.eclipse.updatesite</artifactId>
|
||||
<packaging>eclipse-repository</packaging>
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.alibaba.smartfox.eclipse</groupId>
|
||||
<artifactId>smartfox-eclipse</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<version>1.0.5-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<inceptionYear>2017</inceptionYear>
|
||||
<properties>
|
||||
|
@@ -6,10 +6,15 @@
|
||||
<change-notes>
|
||||
<![CDATA[
|
||||
<ul>
|
||||
1.0.5
|
||||
<li>https://github.com/alibaba/p3c/issues/264</li>
|
||||
</ul>
|
||||
<ul>
|
||||
1.0.4
|
||||
<li>fix https://github.com/alibaba/p3c/issues/217</li>
|
||||
<li>fix https://github.com/alibaba/p3c/issues/208</li>
|
||||
<li>fix https://github.com/alibaba/p3c/issues/195</li>
|
||||
</ul>
|
||||
<ul>
|
||||
1.0.3
|
||||
<li>fix <a href="https://github.com/alibaba/p3c/issues/191">https://github.com/alibaba/p3c/issues/191</a></li>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.alibaba.p3c</groupId>
|
||||
<artifactId>p3c-pmd</artifactId>
|
||||
<version>1.3.4</version>
|
||||
<version>1.3.5</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>p3c-pmd</name>
|
||||
<properties>
|
||||
|
@@ -49,9 +49,11 @@ public class EnumConstantsMustHaveCommentRule extends AbstractAliCommentRule {
|
||||
if (value instanceof ASTEnumDeclaration) {
|
||||
isPreviousEnumDecl = true;
|
||||
} else if (value instanceof ASTEnumConstant && isPreviousEnumDecl) {
|
||||
addViolationWithMessage(data, value,
|
||||
Node enumBody = value.jjtGetParent();
|
||||
Node enumDeclaration = enumBody.jjtGetParent();
|
||||
addViolationWithMessage(data, enumBody,
|
||||
I18nResources.getMessage("java.comment.EnumConstantsMustHaveCommentRule.violation.msg",
|
||||
value.getImage()));
|
||||
enumDeclaration.getImage()));
|
||||
isPreviousEnumDecl = false;
|
||||
} else {
|
||||
isPreviousEnumDecl = false;
|
||||
|
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.p3c.pmd.lang.java.rule.flowcontrol;
|
||||
|
||||
import com.alibaba.p3c.pmd.lang.AbstractXpathRule;
|
||||
import com.alibaba.p3c.pmd.lang.java.util.ViolationUtils;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
/**
|
||||
* [Recommended] Avoid using the negation operator '!'.
|
||||
* Note: The negation operator is not easy to be quickly understood. There must be a positive
|
||||
* way to represent the same logic.
|
||||
*
|
||||
* @author zenghou.fw
|
||||
* @date 2017/11/21
|
||||
*/
|
||||
public class AvoidNegationOperatorRule extends AbstractXpathRule {
|
||||
private static final String XPATH = "//UnaryExpressionNotPlusMinus[child::PrimaryExpression"
|
||||
+ "//PrimaryPrefix/Expression/RelationalExpression]"
|
||||
+ "|//UnaryExpressionNotPlusMinus[child::PrimaryExpression"
|
||||
+ "//PrimaryPrefix/Expression/EqualityExpression]";
|
||||
|
||||
public AvoidNegationOperatorRule() {
|
||||
setXPath(XPATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addViolation(Object data, Node node, String arg) {
|
||||
ViolationUtils.addViolationWithPrecisePosition(this, node, data,
|
||||
"java.flowcontrol.AvoidNegationOperatorRule.violation.msg");
|
||||
}
|
||||
}
|
@@ -29,8 +29,8 @@ import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
* @date 2017/04/16
|
||||
*/
|
||||
public class AbstractClassShouldStartWithAbstractNamingRule extends AbstractXpathRule {
|
||||
private static final String XPATH = "//ClassOrInterfaceDeclaration\n"
|
||||
+ " [@Abstract='true' and @Interface='false']\n" + " [not (matches(@Image,'^(Abstract|Base).*'))]";
|
||||
private static final String XPATH = "//ClassOrInterfaceDeclaration"
|
||||
+ " [@Abstract='true' and @Interface='false'][not (matches(@Image,'^(Abstract|Base).*'))]";
|
||||
|
||||
public AbstractClassShouldStartWithAbstractNamingRule() {
|
||||
setXPath(XPATH);
|
||||
|
@@ -28,7 +28,7 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
* @date 2017/04/16
|
||||
*/
|
||||
public class ArrayNamingShouldHaveBracketRule extends AbstractXpathRule {
|
||||
private static final String XPATH = "//VariableDeclaratorId\n" + "[../..[@Array = 'true']]\n"
|
||||
private static final String XPATH = "//VariableDeclaratorId[../..[@Array = 'true']]"
|
||||
+ "[../../Type/ReferenceType[@Array != 'true']]";
|
||||
|
||||
public ArrayNamingShouldHaveBracketRule() {
|
||||
|
@@ -30,10 +30,10 @@ import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
|
||||
* @date 2017/04/16
|
||||
*/
|
||||
public class BooleanPropertyShouldNotStartWithIsRule extends AbstractXpathRule {
|
||||
private static final String XPATH = "//VariableDeclaratorId\n" + "[(ancestor::ClassOrInterfaceDeclaration)[\n"
|
||||
+ "@Interface='false'\n" + "and\n" + "( ends-with(@Image, 'DO')\n" + "or ends-with(@Image, 'DTO')\n"
|
||||
+ "or ends-with(@Image, 'VO')\n" + "or ends-with(@Image, 'DAO')\n" + ")\n" + "]]\n"
|
||||
+ "[../../../FieldDeclaration/Type/PrimitiveType[@Image = 'boolean']]\n" + "[.[ starts-with(@Image, 'is')]]";
|
||||
private static final String XPATH = "//VariableDeclaratorId[(ancestor::ClassOrInterfaceDeclaration)["
|
||||
+ "@Interface='false' and ( ends-with(@Image, 'DO') or ends-with(@Image, 'DTO')"
|
||||
+ " or ends-with(@Image, 'VO') or ends-with(@Image, 'DAO'))]]"
|
||||
+ "[../../../FieldDeclaration/Type/PrimitiveType[@Image = 'boolean']][.[ starts-with(@Image, 'is')]]";
|
||||
|
||||
public BooleanPropertyShouldNotStartWithIsRule() {
|
||||
setXPath(XPATH);
|
||||
|
@@ -21,8 +21,11 @@ import com.alibaba.p3c.pmd.I18nResources;
|
||||
import com.alibaba.p3c.pmd.lang.java.rule.AbstractAliRule;
|
||||
import com.alibaba.p3c.pmd.lang.java.util.ViolationUtils;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
|
||||
|
||||
/**
|
||||
@@ -40,6 +43,12 @@ public class LowerCamelCaseVariableNamingRule extends AbstractAliRule {
|
||||
@Override
|
||||
public Object visit(final ASTVariableDeclaratorId node, Object data) {
|
||||
// Constant named does not apply to this rule
|
||||
ASTTypeDeclaration typeDeclaration = node.getFirstParentOfType(ASTTypeDeclaration.class);
|
||||
Node jjtGetChild = typeDeclaration.jjtGetChild(0);
|
||||
if (jjtGetChild instanceof ASTAnnotationTypeDeclaration) {
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
||||
ASTFieldDeclaration astFieldDeclaration = node.getFirstParentOfType(ASTFieldDeclaration.class);
|
||||
boolean isNotCheck = astFieldDeclaration != null && (astFieldDeclaration.isFinal() || astFieldDeclaration
|
||||
.isStatic());
|
||||
|
@@ -29,7 +29,7 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
* @date 2017/04/16
|
||||
*/
|
||||
public class PackageNamingRule extends AbstractXpathRule {
|
||||
private static final String XPATH = "//PackageDeclaration/Name\n"
|
||||
private static final String XPATH = "//PackageDeclaration/Name"
|
||||
+ "[not (matches(@Image, '^[a-z0-9]+(\\.[a-z][a-z0-9]*)*$'))]";
|
||||
|
||||
public PackageNamingRule() {
|
||||
|
@@ -29,9 +29,9 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
* @date 2017/04/16
|
||||
*/
|
||||
public class ServiceOrDaoClassShouldEndWithImplRule extends AbstractXpathRule {
|
||||
private static final String XPATH = "//ClassOrInterfaceDeclaration\n"
|
||||
private static final String XPATH = "//ClassOrInterfaceDeclaration"
|
||||
+ "[ .[@Interface='false'] and .[@Abstract='false'] and ./ImplementsList/ClassOrInterfaceType[ ends-with(@Image, 'Service') or "
|
||||
+ "ends-with(@Image, 'DAO')]]\n"
|
||||
+ "ends-with(@Image, 'DAO')]]"
|
||||
+ "[not(.[ ends-with(@Image, 'Impl')])]";
|
||||
|
||||
public ServiceOrDaoClassShouldEndWithImplRule() {
|
||||
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.p3c.pmd.lang.java.rule.other;
|
||||
|
||||
import com.alibaba.p3c.pmd.I18nResources;
|
||||
import com.alibaba.p3c.pmd.lang.java.rule.AbstractAliRule;
|
||||
import com.alibaba.p3c.pmd.lang.java.util.ViolationUtils;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnnotation;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.Token;
|
||||
|
||||
/**
|
||||
* [Recommended] The total number of lines for a method should not be more than 80.
|
||||
* Note: The total number of lines, including the method signature, closing brace, codes, comments,
|
||||
* blank lines, line breaks and any invisible lines, should not be more than 80.
|
||||
*
|
||||
* @author keriezhang
|
||||
* @date 2018/1/9
|
||||
*/
|
||||
public class MethodTooLongRule extends AbstractAliRule {
|
||||
|
||||
private static final int MAX_LINE_COUNT = 80;
|
||||
private static final String ANNOTATION_PREFIX = "@";
|
||||
|
||||
@Override
|
||||
public Object visit(ASTMethodDeclaration node, Object data) {
|
||||
// Include method modifiers.
|
||||
ASTClassOrInterfaceBodyDeclaration classOrInterfaceBodyDecl =
|
||||
(ASTClassOrInterfaceBodyDeclaration)node.jjtGetParent();
|
||||
|
||||
int startLine = classOrInterfaceBodyDecl.getBeginLine();
|
||||
int endLine = classOrInterfaceBodyDecl.getEndLine();
|
||||
|
||||
Node firstChild = classOrInterfaceBodyDecl.jjtGetChild(0);
|
||||
// Method has annotation
|
||||
if (firstChild instanceof ASTAnnotation) {
|
||||
Token firstToken = (Token)classOrInterfaceBodyDecl.jjtGetFirstToken();
|
||||
// If annotation is before modifier, exclude the annotation.
|
||||
if (ANNOTATION_PREFIX.equals(firstToken.image)) {
|
||||
ASTAnnotation annotation = (ASTAnnotation)firstChild;
|
||||
Token lastToken = (Token)annotation.jjtGetLastToken();
|
||||
|
||||
// First token after annotation. The same line or next line after annotation.
|
||||
Token next = lastToken.next;
|
||||
startLine = next.beginLine;
|
||||
}
|
||||
}
|
||||
|
||||
if (endLine - startLine + 1 > MAX_LINE_COUNT) {
|
||||
ViolationUtils.addViolationWithPrecisePosition(this, node, data,
|
||||
I18nResources.getMessage("java.other.MethodTooLongRule.violation.msg", node.getName()));
|
||||
}
|
||||
return super.visit(node, data);
|
||||
}
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
package com.alibaba.p3c.pmd.lang.java.rule.other;
|
||||
|
||||
import com.alibaba.p3c.pmd.lang.AbstractXpathRule;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTLiteral;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* [Mandatory] When doing date formatting, "y" should be written in lowercase for "year" in a pattern statement.
|
||||
*
|
||||
* Note: When doing date formatting, "yyyy" represents the day in which year, while "YYYY" represents the week in which
|
||||
* year (a concept introduced in JDK7). If a week is across two years, the returning "YYYY"represents the next year.
|
||||
* Some more points need to be notices:
|
||||
* Uppercase "M" stands for month.
|
||||
* Lowercase "m" stands for minute.
|
||||
* Uppercase "H" stands for 24-hour clock.
|
||||
* Lowercase "h" stands for 12-hour clock.
|
||||
*
|
||||
* Positive Example: Example pattern for date formatting:
|
||||
* new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
*
|
||||
* Counter Example: Someone applied "YYYY/MM/dd" pattern for date formatting, and the execution result of 2017/12/31 was
|
||||
* 2018/12/31, leading to a serious failure.
|
||||
*
|
||||
* @author huawen.phw
|
||||
* @date 2018/1/9
|
||||
*/
|
||||
public class UseRightCaseForDateFormatRule extends AbstractXpathRule {
|
||||
|
||||
private static final String NEW_XPATH
|
||||
= "//AllocationExpression/ClassOrInterfaceType[@Image='SimpleDateFormat']/../Arguments/ArgumentList"
|
||||
+ "/Expression/PrimaryExpression/PrimaryPrefix/*";
|
||||
private static final String LOW_CASE_4Y = "yyyy";
|
||||
private static final String LOW_CASE_2Y = "yy";
|
||||
private static final String START_QUOTE = "\"";
|
||||
|
||||
public UseRightCaseForDateFormatRule() {
|
||||
setXPath(NEW_XPATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addViolation(Object data, Node node, String arg) {
|
||||
checkNode(node, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂只检查4个y和2个y开头的日期格式化字符串参数,不考虑其他类型
|
||||
*
|
||||
* @param argNode
|
||||
* @param data
|
||||
*/
|
||||
private void checkNode(Node argNode, Object data) {
|
||||
String image = "";
|
||||
if (argNode instanceof ASTLiteral) {
|
||||
image = argNode.getImage();
|
||||
}
|
||||
// 限定只验证字符串,其他如参数、变量等均不考虑
|
||||
if (StringUtils.isEmpty(image) || !image.startsWith(START_QUOTE)) {
|
||||
return;
|
||||
}
|
||||
image = image.replace("\"", "");
|
||||
String lowerCaseTmp = image.toLowerCase();
|
||||
if (!image.startsWith(LOW_CASE_4Y) && lowerCaseTmp.startsWith(LOW_CASE_4Y)) {
|
||||
addViolationWithMessage(data, argNode,
|
||||
"java.other.UseRightCaseForDateFormatRule.rule.msg",
|
||||
new Object[] {image});
|
||||
} else if (!image.startsWith(LOW_CASE_2Y) && lowerCaseTmp.startsWith(LOW_CASE_2Y)) {
|
||||
addViolationWithMessage(data, argNode,
|
||||
"java.other.UseRightCaseForDateFormatRule.rule.msg",
|
||||
new Object[] {image});
|
||||
} else {
|
||||
//暂不考虑
|
||||
}
|
||||
}
|
||||
}
|
@@ -207,6 +207,16 @@
|
||||
<![CDATA[说明:很多if语句内的逻辑相当复杂,阅读者需要分析条件表达式的最终结果,才能明确什么样的条件执行什么样的语句,那么,如果阅读者分析逻辑表达式错误呢?]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.flowcontrol.AvoidNegationOperatorRule.violation.msg">
|
||||
<![CDATA["!"运算符不利于快速理解。]]>
|
||||
</entry>
|
||||
<entry key="java.flowcontrol.AvoidNegationOperatorRule.rule.msg">
|
||||
<![CDATA[避免采用取反逻辑运算符。]]>
|
||||
</entry>
|
||||
<entry key="java.flowcontrol.AvoidNegationOperatorRule.rule.desc">
|
||||
<![CDATA[说明: 取反逻辑不利于快速理解,并且取反逻辑写法必然存在对应的正向逻辑写法。]]>
|
||||
</entry>
|
||||
|
||||
<!-- set -->
|
||||
<entry key="java.set.ClassCastExceptionWithSubListToArrayListRule.violation.msg">
|
||||
<![CDATA[【%s】的结果不可强转成ArrayList]]>
|
||||
@@ -411,7 +421,7 @@
|
||||
<![CDATA[所有的枚举类型字段必须要有注释,说明每个数据项的用途。]]>
|
||||
</entry>
|
||||
<entry key="java.comment.EnumConstantsMustHaveCommentRule.violation.msg">
|
||||
<![CDATA[枚举字段【%s】缺少注释信息]]>
|
||||
<![CDATA[枚举【%s】的字段缺少注释信息]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.comment.RemoveCommentedCodeRule.rule.msg">
|
||||
@@ -461,6 +471,27 @@
|
||||
<![CDATA[注意 Math.random() 这个方法返回是double类型,注意取值的范围[0,1)(能够取到零值,注意除零异常),如果想获取整数类型的随机数,不要将x放大10的若干倍然后取整,直接使用Random对象的nextInt或者nextLong方法。]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.other.MethodTooLongRule.rule.msg">
|
||||
<![CDATA[单个方法的总行数不超过80行。]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.other.MethodTooLongRule.rule.desc">
|
||||
<![CDATA[
|
||||
说明:包括方法签名、结束右大括号、方法内代码、注释、空行、回车及任何不可见字符的总行数不超过80行。
|
||||
]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.other.MethodTooLongRule.violation.msg">
|
||||
<![CDATA[方法【%s】的总行数不要超过80行。]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.other.UseRightCaseForDateFormatRule.rule.msg">
|
||||
<![CDATA[日期格式化字符串[%s]使用错误,应注意使用小写‘y’表示当天所在的年,大写‘Y’代表week in which year。]]>
|
||||
</entry>
|
||||
<entry key="java.other.UseRightCaseForDateFormatRule.rule.desc">
|
||||
<![CDATA[日期格式化时,yyyy表示当天所在的年,而大写的YYYY代表是week in which year(JDK7之后引入的概念),意思是当天所在的周属于的年份,一周从周日开始,周六结束,只要本周跨年,返回的YYYY就是下一年。]]>
|
||||
</entry>
|
||||
|
||||
<!-- other -->
|
||||
<entry key="vm.other.UseQuietReferenceNotationRule.rule.msg">
|
||||
<![CDATA[后台输送给页面的变量必须加感叹号,${var}——中间加感叹号!。]]>
|
||||
|
@@ -209,6 +209,16 @@ Note: Below are the problems created by usage of Executors for thread pool creat
|
||||
<![CDATA[Note: Logic within many if statements are very complicated. Readers need to analyze the final results of the conditional expression to decide what statement is to be executed in certain conditions.]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.flowcontrol.AvoidNegationOperatorRule.violation.msg">
|
||||
<![CDATA[The negation operator is not easy to be quickly understood.]]>
|
||||
</entry>
|
||||
<entry key="java.flowcontrol.AvoidNegationOperatorRule.rule.msg">
|
||||
<![CDATA[Avoid using the negation operator '!'.]]>
|
||||
</entry>
|
||||
<entry key="java.flowcontrol.AvoidNegationOperatorRule.rule.desc">
|
||||
<![CDATA[Note: The negation operator is not easy to be quickly understood. There must be a positive way to represent the same logic.]]>
|
||||
</entry>
|
||||
|
||||
<!-- set -->
|
||||
<entry key="java.set.ClassCastExceptionWithSubListToArrayListRule.violation.msg">
|
||||
<![CDATA[The result of [%s] can't cast in class ArrayList]]>
|
||||
@@ -411,7 +421,7 @@ The format of date is 'yyyy/MM/dd'.
|
||||
<![CDATA[All enumeration type fields should be commented as Javadoc style.]]>
|
||||
</entry>
|
||||
<entry key="java.comment.EnumConstantsMustHaveCommentRule.violation.msg">
|
||||
<![CDATA[enum [%s] should have javadoc]]>
|
||||
<![CDATA[fields of enum [%s] should have javadoc]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.comment.RemoveCommentedCodeRule.rule.msg">
|
||||
@@ -462,6 +472,29 @@ Note: In order to get a more accurate time, use System.nanoTime(). In JDK8, use
|
||||
<![CDATA[The return type of Math.random() is double, value range is 0<=x<1 (0 is possible). If a random integer is required, do not multiply x by 10 then round the result. The correct way is to use nextInt or nextLong method which belong to Random Object.]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.other.MethodTooLongRule.rule.msg">
|
||||
<![CDATA[The total number of lines for a method should not be more than 80.]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.other.MethodTooLongRule.rule.desc">
|
||||
<![CDATA[
|
||||
Note: The total number of lines, including the method signature, closing brace, codes, comments, blank lines, line breaks and any invisible lines, should not be more than 80.
|
||||
]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.other.MethodTooLongRule.violation.msg">
|
||||
<![CDATA[The total number of lines for method [%s] should not be more than 80.]]>
|
||||
</entry>
|
||||
|
||||
<entry key="java.other.UseRightCaseForDateFormatRule.rule.msg">
|
||||
<![CDATA[Date format string [%s] is error,When doing date formatting, 'y' should be written in lowercase for 'year'.]]>
|
||||
</entry>
|
||||
<entry key="java.other.UseRightCaseForDateFormatRule.rule.desc">
|
||||
<![CDATA[When doing date formatting, "yyyy" represents the day in which year, while "YYYY" represents the week in which
|
||||
* year (a concept introduced in JDK7). If a week is across two years, the returning "YYYY"represents the next year.]]>
|
||||
</entry>
|
||||
|
||||
|
||||
<!--other -->
|
||||
<entry key="vm.other.UseQuietReferenceNotationRule.rule.msg">
|
||||
<![CDATA[Variables must add exclamatory mark when passing to velocity engine from backend, ${var}--add '!' after '$'.]]>
|
||||
|
@@ -64,4 +64,30 @@ Positive example:
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AvoidNegationOperatorRule"
|
||||
language="java"
|
||||
message="java.flowcontrol.AvoidNegationOperatorRule.rule.msg"
|
||||
class="com.alibaba.p3c.pmd.lang.java.rule.flowcontrol.AvoidNegationOperatorRule">
|
||||
<description>java.flowcontrol.AvoidNegationOperatorRule.rule.desc</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
Negative example:
|
||||
// Use `if (!(x >= 628))` to represent that x is less than 628.
|
||||
if (!(x >= 628)) {
|
||||
// ...
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
<example>
|
||||
<![CDATA[
|
||||
Positive example:
|
||||
// Use `if (x < 628)` to represent that x is less than 628.
|
||||
if (x < 628)) {
|
||||
// ...
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</ruleset>
|
||||
|
@@ -79,4 +79,29 @@ Positive example:
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="MethodTooLongRule" language="java"
|
||||
message="java.other.MethodTooLongRule.rule.msg"
|
||||
class="com.alibaba.p3c.pmd.lang.java.rule.other.MethodTooLongRule">
|
||||
<description>java.other.MethodTooLongRule.rule.desc</description>
|
||||
<priority>3</priority>
|
||||
</rule>
|
||||
|
||||
<rule name="UseRightCaseForDateFormatRule" language="java"
|
||||
message="java.other.UseRightCaseForDateFormatRule.rule.msg"
|
||||
class="com.alibaba.p3c.pmd.lang.java.rule.other.UseRightCaseForDateFormatRule">
|
||||
<description>java.other.UseRightCaseForDateFormatRule.rule.desc</description>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
Negative example:
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
]]>
|
||||
</example>
|
||||
<example>
|
||||
<![CDATA[
|
||||
Positive example:
|
||||
SimpleDateFormat format = new SimpleDateFormat("YYYY-mm-dd HH:mm:ss");
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</ruleset>
|
||||
|
@@ -26,7 +26,6 @@ import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
*/
|
||||
public class FlowControlRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
|
||||
private static final String RULESET = "java-ali-flowcontrol";
|
||||
|
||||
@Override
|
||||
@@ -34,5 +33,6 @@ public class FlowControlRuleTest extends SimpleAggregatorTst {
|
||||
addRule(RULESET, "SwitchStatementRule");
|
||||
addRule(RULESET, "NeedBraceRule");
|
||||
addRule(RULESET, "AvoidComplexConditionRule");
|
||||
addRule(RULESET, "AvoidNegationOperatorRule");
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
package com.alibaba.p3c.pmd.lang.java.rule.other;
|
||||
|
||||
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test for other java rules.
|
||||
@@ -26,7 +27,7 @@ import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
*/
|
||||
public class OtherRulesTest extends SimpleAggregatorTst {
|
||||
|
||||
private static final String RULESET = "java-ali-other";
|
||||
public static final String RULESET = "java-ali-other";
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
@@ -34,5 +35,14 @@ public class OtherRulesTest extends SimpleAggregatorTst {
|
||||
addRule(RULESET, "AvoidNewDateGetTimeRule");
|
||||
addRule(RULESET, "AvoidPatternCompileInMethodRule");
|
||||
addRule(RULESET, "AvoidMissUseOfMathRandomRule");
|
||||
addRule(RULESET, "MethodTooLongRule");
|
||||
addRule(RULESET,"UseRightCaseForDateFormatRule");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUseRightCaseForDateFormatRule() {
|
||||
runTests(findRule(RULESET, "UseRightCaseForDateFormatRule"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,25 @@
|
||||
package com.alibaba.p3c.pmd.lang.java.rule.other;
|
||||
|
||||
import com.alibaba.p3c.pmd.testframework.ExtendRuleTst;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author huawen.phw
|
||||
* @date 2018/2/1
|
||||
* Description:
|
||||
*/
|
||||
public class UseRightCaseForDateFormatRuleTest extends ExtendRuleTst {
|
||||
|
||||
@Test
|
||||
public void testExam1() {
|
||||
String ruleName = "UseRightCaseForDateFormatRule";
|
||||
String examFilePath = "java/" + ruleName + "Exam.java";
|
||||
String expectedVioLineNumbers = "16,26,32,34,36";
|
||||
|
||||
Rule rule = findRule(OtherRulesTest.RULESET, ruleName);
|
||||
runTest(rule, examFilePath, expectedVioLineNumbers);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
package com.alibaba.p3c.pmd.testframework;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.testframework.RuleTst;
|
||||
import net.sourceforge.pmd.testframework.TestDescriptor;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* @author huawen.phw
|
||||
* @date 2018/2/1
|
||||
* Description:
|
||||
*/
|
||||
public class ExtendRuleTst extends RuleTst {
|
||||
|
||||
|
||||
public void runTest(Rule rule, String examFilePath, String expectedVioLineNumbers) {
|
||||
TestDescriptor descriptor = extractTestsFromJavaFile(rule, examFilePath
|
||||
, expectedVioLineNumbers);
|
||||
if (descriptor != null) {
|
||||
runTest(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rule
|
||||
* @return
|
||||
*/
|
||||
public TestDescriptor extractTestsFromJavaFile(Rule rule) {
|
||||
return extractTestsFromJavaFile(rule, "java/" + getCleanRuleName(rule) + ".java");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rule
|
||||
* @param javaFilePath
|
||||
* @return
|
||||
*/
|
||||
public TestDescriptor extractTestsFromJavaFile(Rule rule, String javaFilePath) {
|
||||
return extractTestsFromJavaFile(rule, javaFilePath, "");
|
||||
}
|
||||
|
||||
public TestDescriptor extractTestsFromJavaFile(Rule rule, String javaFilePath, String expectedLineNumbers) {
|
||||
if (StringUtils.isEmpty(javaFilePath)) {
|
||||
return null;
|
||||
}
|
||||
//append file suffix
|
||||
if (!javaFilePath.toLowerCase().endsWith(".java")) {
|
||||
javaFilePath = javaFilePath + ".java";
|
||||
}
|
||||
InputStream inputStream = getClass().getResourceAsStream(javaFilePath);
|
||||
if (inputStream == null) {
|
||||
throw new RuntimeException("Couldn't find " + javaFilePath);
|
||||
}
|
||||
|
||||
String fileContents = null;
|
||||
try {
|
||||
fileContents = IOUtils.toString(inputStream, Charset.defaultCharset());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
}
|
||||
|
||||
if (fileContents == null) {
|
||||
return null;
|
||||
}
|
||||
List<Integer> expectedLineNumber = getExpectedLineNumbers(expectedLineNumbers);
|
||||
TestDescriptor descriptor = new TestDescriptor(fileContents, rule.getDescription(),
|
||||
expectedLineNumber.size(), rule);
|
||||
descriptor.setExpectedLineNumbers(expectedLineNumber);
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public List<Integer> getExpectedLineNumbers(String lineNumbers) {
|
||||
List<Integer> expectedLineNumbers = new ArrayList<>();
|
||||
for (String n : lineNumbers.split(" *, *")) {
|
||||
try {
|
||||
expectedLineNumbers.add(Integer.valueOf(n));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return expectedLineNumbers;
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.alibaba.p3c.pmd.testframework;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huawen.phw
|
||||
* @date 2018/2/1
|
||||
* Description: 扩展framework,runTest支持检查.java文件
|
||||
*/
|
||||
public class ExtendSimpleAggregatorTst extends SimpleAggregatorTst {
|
||||
|
||||
|
||||
}
|
@@ -128,63 +128,4 @@ public class CommentsMustBeJavadocFormat {
|
||||
<code-ref id="ignore-comments-behind-statements" />
|
||||
</test-code>
|
||||
|
||||
<code-fragment id="when-node-has-annotation-wrong-format"><![CDATA[
|
||||
// test when class has annotation
|
||||
@Controller
|
||||
@Rest
|
||||
public class CommentsMustBeJavadocFormat {
|
||||
// test when node has annotation
|
||||
@Test
|
||||
private String name;
|
||||
|
||||
// test when node has annotation2
|
||||
@Hello(asdf="asdf")
|
||||
@world
|
||||
private Integer age;
|
||||
|
||||
// test when method has annotation
|
||||
@Test
|
||||
@Autowired
|
||||
public void getName() {
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
<test-code>
|
||||
<description>When node has annotation and wrong comment format
|
||||
</description>
|
||||
<expected-problems>4</expected-problems>
|
||||
<expected-linenumbers>1,5,9,14</expected-linenumbers>
|
||||
<code-ref id="when-node-has-annotation-wrong-format" />
|
||||
</test-code>
|
||||
|
||||
<code-fragment id="when-node-has-annotation-right-format"><![CDATA[
|
||||
/** test when class has annotation */
|
||||
@Controller
|
||||
@Rest
|
||||
public class CommentsMustBeJavadocFormat {
|
||||
/** test when node has annotation */
|
||||
@Test
|
||||
private String name;
|
||||
|
||||
/** test when node has annotation2 */
|
||||
@Hello(asdf="asdf")
|
||||
@world
|
||||
private Integer age;
|
||||
|
||||
/** test when method has annotation */
|
||||
@Test
|
||||
@Autowired
|
||||
public void getName() {
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
<test-code>
|
||||
<description>When node has annotation and right comment format
|
||||
</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code-ref id="when-node-has-annotation-right-format" />
|
||||
</test-code>
|
||||
|
||||
</test-data>
|
||||
|
@@ -11,7 +11,7 @@ public enum Level {
|
||||
<test-code>
|
||||
<description>Enum without Comment.</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>2</expected-linenumbers>
|
||||
<expected-linenumbers>1</expected-linenumbers>
|
||||
<code-ref id="enum-without-comment" />
|
||||
</test-code>
|
||||
|
||||
|
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
<code-fragment id="unnecessary-not-expression">
|
||||
<![CDATA[
|
||||
public class Example {
|
||||
public int foo(int a, int b) {
|
||||
if (!(a > b)) {
|
||||
return -1;
|
||||
}
|
||||
if (!(a == b)) {
|
||||
return -1;
|
||||
}
|
||||
if (!(a != b)) {
|
||||
return -1;
|
||||
}
|
||||
if (!(a > 0 && b > 0)) {
|
||||
return 1;
|
||||
}
|
||||
if (!(a == 0 && b >= 0)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
<test-code>
|
||||
<description>unnecessary not operator can be removed</description>
|
||||
<expected-problems>3</expected-problems>
|
||||
<expected-linenumbers>3,6,9</expected-linenumbers>
|
||||
<code-ref id="unnecessary-not-expression"/>
|
||||
</test-code>
|
||||
</test-data>
|
@@ -124,6 +124,22 @@ public interface BizConstants {
|
||||
<expected-problems>0</expected-problems>
|
||||
<code-ref id="LowerCamelCaseVariableNamingRuleTest7" />
|
||||
</test-code>
|
||||
|
||||
<code-fragment id="LowerCamelCaseVariableNamingRuleTest8">
|
||||
<![CDATA[
|
||||
public @interface TYPE {
|
||||
int DO_NO_THING = 0;
|
||||
int DO_ONE_START_TO_END_ROUTE = 1;
|
||||
int DO_ONE_CAR_TO_START_ROUTE = 2;
|
||||
int DO_TWO_ROUTE = 3;
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
<test-code>
|
||||
<description>Variable name should be lowerCamelCase8</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code-ref id="LowerCamelCaseVariableNamingRuleTest8" />
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
||||
|
||||
|
@@ -31,19 +31,5 @@
|
||||
</test-code>
|
||||
|
||||
|
||||
<code-fragment id="PackageNamingRule2">
|
||||
<![CDATA[
|
||||
package ali88.ps.service;
|
||||
public class SomeClass {
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
<test-code>
|
||||
<description>Package Name should be lowercase</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code-ref id="PackageNamingRule2" />
|
||||
</test-code>
|
||||
|
||||
|
||||
|
||||
</test-data>
|
||||
|
@@ -0,0 +1,61 @@
|
||||
package com.alibaba.p3c.pmd.lang.java.rule.other.java;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
|
||||
/**
|
||||
* @author huawen.phw
|
||||
* @date 2018/2/1
|
||||
* Description:
|
||||
*/
|
||||
public class UseRightCaseForDateFormatRuleExam {
|
||||
|
||||
private static final String PATTERN= "yyyyMMdd";
|
||||
|
||||
public void exam1() {
|
||||
SimpleDateFormat format = new SimpleDateFormat("YYYYMMDD"); //vio
|
||||
|
||||
format = new SimpleDateFormat("yyyy/MM/dd");
|
||||
|
||||
format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
format = new SimpleDateFormat("yyyymmdd");
|
||||
|
||||
format = new SimpleDateFormat("yyyy-MM-DD");
|
||||
|
||||
format = new SimpleDateFormat("YYYY/MM/dd HH:mm:ss"); //p2 error
|
||||
|
||||
format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); //right
|
||||
|
||||
format = new SimpleDateFormat("yy-MM-DD");
|
||||
|
||||
format = new SimpleDateFormat("YY-MM-DD");//vio
|
||||
|
||||
format = new SimpleDateFormat("YY-md");//vio
|
||||
|
||||
format = new SimpleDateFormat("Yy-md"); //vio
|
||||
|
||||
format = new SimpleDateFormat("yyy-md"); //not checked
|
||||
|
||||
format = new SimpleDateFormat("Y-md"); // not checked
|
||||
|
||||
format = new SimpleDateFormat("y-md"); // not checked
|
||||
|
||||
format = new SimpleDateFormat("dd/MM-YYYY"); //not checked
|
||||
|
||||
exam_2(PATTERN);//can not checked
|
||||
|
||||
exam_2("YYYmmDD");//can not checked
|
||||
}
|
||||
|
||||
public void exam2(String formatStr) {
|
||||
SimpleDateFormat format = new SimpleDateFormat(PATTERN);//can not checked
|
||||
|
||||
format = new SimpleDateFormat(formatStr);//can not checked
|
||||
}
|
||||
|
||||
public void exam3(){
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,407 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
|
||||
<code-fragment id="method-equal-to-80-lines"><![CDATA[
|
||||
public class MethodTooLongRule {
|
||||
@Test
|
||||
public void test() {
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
// 77 lines of comment
|
||||
int i = 1;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
|
||||
<test-code>
|
||||
<description>Method equal to 80 lines</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code-ref id="method-equal-to-80-lines" />
|
||||
</test-code>
|
||||
|
||||
|
||||
<code-fragment id="method-more-than-80-lines"><![CDATA[
|
||||
public class MethodTooLongRule {
|
||||
public void test() {
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
// 78 lines of comment
|
||||
int i = 1;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
|
||||
<test-code>
|
||||
<description>Method more than 80 lines</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>2</expected-linenumbers>
|
||||
<code-ref id="method-more-than-80-lines" />
|
||||
</test-code>
|
||||
|
||||
|
||||
<code-fragment id="method-less-than-80-lines"><![CDATA[
|
||||
public class MethodTooLongRule {
|
||||
public void test() {
|
||||
int i = 1;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
<test-code>
|
||||
<description>Method less than 80 lines</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code-ref id="method-less-than-80-lines" />
|
||||
</test-code>
|
||||
|
||||
<code-fragment id="interface-method"><![CDATA[
|
||||
interface printable{
|
||||
void print();
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
<test-code>
|
||||
<description>Interface method</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code-ref id="interface-method" />
|
||||
</test-code>
|
||||
|
||||
|
||||
<code-fragment id="method-signature-multi-lines"><![CDATA[
|
||||
public class MethodTooLongRule {
|
||||
public
|
||||
void
|
||||
test() {
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
int i = 1;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
<test-code>
|
||||
<description>Method signature multi lines</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>4</expected-linenumbers>
|
||||
<code-ref id="method-signature-multi-lines" />
|
||||
</test-code>
|
||||
|
||||
|
||||
<code-fragment id="method-signature-with-annotation-multi-lines"><![CDATA[
|
||||
public class MethodTooLongRule {
|
||||
@Test public
|
||||
void
|
||||
test() {
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
// 76 lines of comment
|
||||
int i = 1;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
<test-code>
|
||||
<description>Method signature with annotation multi lines</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>4</expected-linenumbers>
|
||||
<code-ref id="method-signature-with-annotation-multi-lines" />
|
||||
</test-code>
|
||||
|
||||
</test-data>
|
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
|
||||
<code-fragment id="use-right-case-for-date-format"><![CDATA[
|
||||
import java.text.SimpleDateFormat;
|
||||
class DateFormatTest {
|
||||
public void test(){
|
||||
SimpleDateFormat format = new SimpleDateFormat("YYYYMMDD"); //vio
|
||||
format = new SimpleDateFormat("yyyy/MM/dd");
|
||||
format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
format = new SimpleDateFormat("yyyymmdd");
|
||||
format = new SimpleDateFormat("yyyy-MM-DD");
|
||||
format = new SimpleDateFormat("yy-MM-DD");
|
||||
format = new SimpleDateFormat("YY-MM-DD");
|
||||
format = new SimpleDateFormat("YYmd");
|
||||
format = new SimpleDateFormat("YYYY-M-d");
|
||||
format = new SimpleDateFormat("YYYY-dd");
|
||||
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
|
||||
<test-code>
|
||||
<description>Use right case to format date</description>
|
||||
<expected-problems>5</expected-problems>
|
||||
<expected-linenumbers>4,10,11,12,13</expected-linenumbers>
|
||||
<code-ref id="use-right-case-for-date-format" />
|
||||
</test-code>
|
||||
|
||||
</test-data>
|
Reference in New Issue
Block a user