[javascript] Move rule AvoidTrailingComma to errorprone

This commit is contained in:
Andreas Dangel
2017-11-01 18:32:44 +01:00
parent 593226ce2a
commit fb79716cfa
6 changed files with 38 additions and 38 deletions

View File

@ -61,42 +61,6 @@ function getX() {
</example> </example>
</rule> </rule>
<rule name="AvoidTrailingComma"
message="Avoid trailing commas in object or array literals"
language="ecmascript"
since="5.1"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_codestyle.html#avoidtrailingcomma">
<description>
This rule helps improve code portability due to differences in browser treatment of trailing commas in object or array literals.
</description>
<priority>1</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//ObjectLiteral[$allowObjectLiteral = "false" and @TrailingComma = 'true']
|
//ArrayLiteral[$allowArrayLiteral = "false" and @TrailingComma = 'true']
]]>
</value>
</property>
<property name="allowObjectLiteral" type="Boolean" value="false" description="Allow a trailing comma within an object literal" />
<property name="allowArrayLiteral" type="Boolean" value="false" description="Allow a trailing comma within an array literal" />
</properties>
<example>
<![CDATA[
function(arg) {
var obj1 = { a : 1 }; // Ok
var arr1 = [ 1, 2 ]; // Ok
var obj2 = { a : 1, }; // Syntax error in some browsers!
var arr2 = [ 1, 2, ]; // Length 2 or 3 depending on the browser!
}
]]>
</example>
</rule>
<rule name="ForLoopsMustUseBraces" <rule name="ForLoopsMustUseBraces"
language="ecmascript" language="ecmascript"
since="5.0" since="5.0"

View File

@ -9,6 +9,42 @@
</description> </description>
<rule name="AvoidTrailingComma"
message="Avoid trailing commas in object or array literals"
language="ecmascript"
since="5.1"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_errorprone.html#avoidtrailingcomma">
<description>
This rule helps improve code portability due to differences in browser treatment of trailing commas in object or array literals.
</description>
<priority>1</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//ObjectLiteral[$allowObjectLiteral = "false" and @TrailingComma = 'true']
|
//ArrayLiteral[$allowArrayLiteral = "false" and @TrailingComma = 'true']
]]>
</value>
</property>
<property name="allowObjectLiteral" type="Boolean" value="false" description="Allow a trailing comma within an object literal" />
<property name="allowArrayLiteral" type="Boolean" value="false" description="Allow a trailing comma within an array literal" />
</properties>
<example>
<![CDATA[
function(arg) {
var obj1 = { a : 1 }; // Ok
var arr1 = [ 1, 2 ]; // Ok
var obj2 = { a : 1, }; // Syntax error in some browsers!
var arr2 = [ 1, 2, ]; // Length 2 or 3 depending on the browser!
}
]]>
</example>
</rule>
<rule name="EqualComparison" <rule name="EqualComparison"
language="ecmascript" language="ecmascript"
since="5.0" since="5.0"

View File

@ -8,9 +8,9 @@
<description>Rules concerning basic ECMAScript guidelines.</description> <description>Rules concerning basic ECMAScript guidelines.</description>
<rule ref="category/ecmascript/codestyle.xml/AssignmentInOperand" deprecated="true" /> <rule ref="category/ecmascript/codestyle.xml/AssignmentInOperand" deprecated="true" />
<rule ref="category/ecmascript/codestyle.xml/AvoidTrailingComma" deprecated="true" />"
<rule ref="category/ecmascript/codestyle.xml/UnreachableCode" deprecated="true" /> <rule ref="category/ecmascript/codestyle.xml/UnreachableCode" deprecated="true" />
<rule ref="category/ecmascript/errorprone.xml/AvoidTrailingComma" deprecated="true" />"
<rule ref="category/ecmascript/errorprone.xml/EqualComparison" deprecated="true" /> <rule ref="category/ecmascript/errorprone.xml/EqualComparison" deprecated="true" />
<rule ref="category/ecmascript/errorprone.xml/InnaccurateNumericLiteral" deprecated="true" /> <rule ref="category/ecmascript/errorprone.xml/InnaccurateNumericLiteral" deprecated="true" />

View File

@ -13,7 +13,6 @@ public class CodeStyleRulesTest extends SimpleAggregatorTst {
@Override @Override
public void setUp() { public void setUp() {
addRule(RULESET, "AssignmentInOperand"); addRule(RULESET, "AssignmentInOperand");
addRule(RULESET, "AvoidTrailingComma");
addRule(RULESET, "ForLoopsMustUseBraces"); addRule(RULESET, "ForLoopsMustUseBraces");
addRule(RULESET, "IfElseStmtsMustUseBraces"); addRule(RULESET, "IfElseStmtsMustUseBraces");
addRule(RULESET, "IfStmtsMustUseBraces"); addRule(RULESET, "IfStmtsMustUseBraces");

View File

@ -12,6 +12,7 @@ public class ErrorProneRulesTest extends SimpleAggregatorTst {
@Override @Override
public void setUp() { public void setUp() {
addRule(RULESET, "AvoidTrailingComma");
addRule(RULESET, "EqualComparison"); addRule(RULESET, "EqualComparison");
addRule(RULESET, "InnaccurateNumericLiteral"); addRule(RULESET, "InnaccurateNumericLiteral");
} }