[doc] [javascript] Adjust externalInfoUrl properties to new site - Part 6
Note: I also took the chance to fix tab damage
This commit is contained in:
@ -12,8 +12,8 @@
|
||||
since="5.0"
|
||||
message="Avoid assignments in operands"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#AssignmentInOperand">
|
||||
<description>
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#assignmentinoperand">
|
||||
<description>
|
||||
Avoid assignments in operands; this can make code more complicated and harder to read. This is sometime
|
||||
indicative of the bug where the assignment operator '=' was used instead of the equality operator '=='.
|
||||
</description>
|
||||
@ -44,7 +44,7 @@ indicative of the bug where the assignment operator '=' was used instead of the
|
||||
<property name="allowIncrementDecrement" type="Boolean" value="false" description="Allow increment or decrement operators within the conditional expression of an if, for, or while statement" />
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
var x = 2;
|
||||
// Bad
|
||||
if ((x = getX()) == 3) {
|
||||
@ -54,16 +54,16 @@ if ((x = getX()) == 3) {
|
||||
function getX() {
|
||||
return 3;
|
||||
}
|
||||
]]>
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</rule>
|
||||
|
||||
<rule name="UnreachableCode"
|
||||
language="ecmascript"
|
||||
since="5.0"
|
||||
message="A ''return'', ''break'', ''continue'', or ''throw'' statement should be the last in a block."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#UnreachableCode">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#unreachablecode">
|
||||
<description>
|
||||
A 'return', 'break', 'continue', or 'throw' statement should be the last in a block. Statements after these
|
||||
will never execute. This is a bug, or extremely poor style.
|
||||
@ -85,7 +85,7 @@ will never execute. This is a bug, or extremely poor style.
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
// Ok
|
||||
function foo() {
|
||||
return 1;
|
||||
@ -105,7 +105,7 @@ function bar() {
|
||||
since="5.0"
|
||||
message="The numeric literal ''{0}'' will have at different value at runtime."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#InnaccurateNumericLiteral">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#innaccuratenumericliteral">
|
||||
<description>
|
||||
The numeric literal will have at different value at runtime, which can happen if you provide too much
|
||||
precision in a floating point number. This may result in numeric calculations being in error.
|
||||
@ -114,7 +114,7 @@ precision in a floating point number. This may result in numeric calculations b
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
//NumberLiteral[
|
||||
@Image != @Number
|
||||
and translate(@Image, "e", "E") != @Number
|
||||
@ -125,7 +125,7 @@ precision in a floating point number. This may result in numeric calculations b
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
var a = 9; // Ok
|
||||
var b = 999999999999999; // Ok
|
||||
var c = 999999999999999999999; // Not good
|
||||
@ -141,7 +141,7 @@ var z = 1.12345678901234567; // Not good
|
||||
since="5.0"
|
||||
message="A function should not mix 'return' statements with and without a result."
|
||||
class="net.sourceforge.pmd.lang.ecmascript.rule.basic.ConsistentReturnRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#ConsistentReturn">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#consistentreturn">
|
||||
<description>
|
||||
ECMAScript does provide for return types on functions, and therefore there is no solid rule as to their usage.
|
||||
However, when a function does use returns they should all have a value, or all with no value. Mixed return
|
||||
@ -149,7 +149,7 @@ usage is likely a bug, or at best poor style.
|
||||
</description>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
// Ok
|
||||
function foo() {
|
||||
if (condition1) {
|
||||
@ -174,7 +174,7 @@ function bar() {
|
||||
since="5.0"
|
||||
message="The for-in loop variable ''{0}'' should be explicitly scoped with 'var' to avoid pollution."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#ScopeForInVariable">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#scopeforinvariable">
|
||||
<description>
|
||||
A for-in loop in which the variable name is not explicitly scoped to the enclosing scope with the 'var' keyword can
|
||||
refer to a variable in an enclosing scope outside the nearest enclosing scope. This will overwrite the
|
||||
@ -187,14 +187,14 @@ is better to explicitly scope the variable name to the nearest enclosing scope w
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ForInLoop[not(child::VariableDeclaration)]/Name[1]
|
||||
<![CDATA[
|
||||
//ForInLoop[not(child::VariableDeclaration)]/Name[1]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
// Ok
|
||||
function foo() {
|
||||
var p = 'clean';
|
||||
@ -230,16 +230,16 @@ function bar() {
|
||||
since="5.0"
|
||||
message="Use '==='/'!==' to compare with true/false or Numbers"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#EqualComparison">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#equalcomparison">
|
||||
<description>
|
||||
Using == in condition may lead to unexpected results, as the variables are automatically casted to be of the
|
||||
same type. The === operator avoids the casting.
|
||||
Using == in condition may lead to unexpected results, as the variables are automatically casted to be of the
|
||||
same type. The === operator avoids the casting.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
//InfixExpression[(@Image = "==" or @Image = "!=")
|
||||
and
|
||||
(child::KeywordLiteral[@Image = "true" or @Image = "false"]
|
||||
@ -251,7 +251,7 @@ function bar() {
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
// Ok
|
||||
if (someVar === true) {
|
||||
...
|
||||
@ -268,7 +268,6 @@ if (someVar == true) {
|
||||
if (someVar != 3) {
|
||||
...
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
@ -278,7 +277,7 @@ if (someVar != 3) {
|
||||
language="ecmascript"
|
||||
since="5.0"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#GlobalVariable">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#globalvariable">
|
||||
<description>
|
||||
This rule helps to avoid using accidently global variables by simply missing the "var" declaration.
|
||||
Global variables can lead to side-effects that are hard to debug.
|
||||
@ -311,7 +310,7 @@ function(arg) {
|
||||
language="ecmascript"
|
||||
since="5.1"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#AvoidTrailingComma">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#avoidtrailingcomma">
|
||||
<description>
|
||||
This rule helps improve code portability due to differences in browser treatment of trailing commas in object or array literals.
|
||||
</description>
|
||||
@ -320,9 +319,9 @@ This rule helps improve code portability due to differences in browser treatment
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ObjectLiteral[$allowObjectLiteral = "false" and @TrailingComma = 'true']
|
||||
//ObjectLiteral[$allowObjectLiteral = "false" and @TrailingComma = 'true']
|
||||
|
|
||||
//ArrayLiteral[$allowArrayLiteral = "false" and @TrailingComma = 'true']
|
||||
//ArrayLiteral[$allowArrayLiteral = "false" and @TrailingComma = 'true']
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -346,22 +345,35 @@ function(arg) {
|
||||
message="Always provide a base when using parseInt() functions"
|
||||
language="ecmascript" since="5.0.1"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#UseBaseWithParseInt">
|
||||
<description>TODO</description>
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#usebasewithparseint">
|
||||
<description>
|
||||
This rule checks for usages of parseInt. While the second parameter is optional and usually defaults
|
||||
to 10 (base/radix is 10 for a decimal number), different implementations may behave differently.
|
||||
It also improves readability, if the base is given.
|
||||
|
||||
See also: [parseInt()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
|
||||
</description>
|
||||
<priority>1</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value><![CDATA[
|
||||
<value>
|
||||
<![CDATA[
|
||||
//FunctionCall/Name[
|
||||
@Image = 'parseInt'
|
||||
and
|
||||
count(../*) < 3
|
||||
]
|
||||
]]></value>
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example><![CDATA[
|
||||
parseInt("10",base);
|
||||
]]></example>
|
||||
<example>
|
||||
<![CDATA[
|
||||
parseInt("010"); // unclear, could be interpreted as 10 or 7 (with a base of 7)
|
||||
|
||||
parseInt("10", 10); // good
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
@ -13,7 +13,7 @@ The Braces Ruleset contains a collection of braces rules.
|
||||
since="5.0"
|
||||
message="Avoid using if statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/braces.html#IfStmtsMustUseBraces">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_braces.html#ifstmtsmustusebraces">
|
||||
<description>
|
||||
Avoid using if statements without using curly braces.
|
||||
</description>
|
||||
@ -21,14 +21,14 @@ Avoid using if statements without using curly braces.
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
//IfStatement[@Else = "false" and not(child::Scope)]
|
||||
]]>
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
// Ok
|
||||
if (foo) {
|
||||
x++;
|
||||
@ -37,7 +37,7 @@ if (foo) {
|
||||
// Bad
|
||||
if (foo)
|
||||
x++;
|
||||
]]>
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
@ -46,7 +46,7 @@ if (foo)
|
||||
since="5.0"
|
||||
message="Avoid using 'if...else' statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/braces.html#IfElseStmtsMustUseBraces">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_braces.html#ifelsestmtsmustusebraces">
|
||||
<description>
|
||||
Avoid using if..else statements without using curly braces.
|
||||
</description>
|
||||
@ -58,7 +58,7 @@ Avoid using if..else statements without using curly braces.
|
||||
//ExpressionStatement[parent::IfStatement[@Else = "true"]]
|
||||
[not(child::Scope)]
|
||||
[not(child::IfStatement)]
|
||||
]]>
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
@ -85,7 +85,7 @@ else
|
||||
since="5.0"
|
||||
message="Avoid using 'while' statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/braces.html#WhileLoopsMustUseBraces">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_braces.html#whileloopsmustusebraces">
|
||||
<description>
|
||||
Avoid using 'while' statements without using curly braces.
|
||||
</description>
|
||||
@ -118,7 +118,7 @@ while (true)
|
||||
since="5.0"
|
||||
message="Avoid using 'for' statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/braces.html#ForLoopsMustUseBraces">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_braces.html#forloopsmustusebraces">
|
||||
<description>
|
||||
Avoid using 'for' statements without using curly braces.
|
||||
</description>
|
||||
@ -127,9 +127,9 @@ Avoid using 'for' statements without using curly braces.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ForLoop[not(child::Scope)]
|
||||
//ForLoop[not(child::Scope)]
|
||||
|
|
||||
//ForInLoop[not(child::Scope)]
|
||||
//ForInLoop[not(child::Scope)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -12,22 +12,28 @@ They are held here to allow people to include them as they see fit within their
|
||||
|
||||
<rule name="AvoidWithStatement"
|
||||
message="Avoid using with - it's bad news"
|
||||
language="ecmascript" since="5.0.1"
|
||||
language="ecmascript"
|
||||
since="5.0.1"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#AvoidWithStatement">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_controversial.html#avoidwithstatement">
|
||||
<description>Avoid using with - it's bad news</description>
|
||||
<priority>1</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value><![CDATA[
|
||||
<value>
|
||||
<![CDATA[
|
||||
//WithStatement
|
||||
]]></value>
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>1</priority>
|
||||
<example><![CDATA[
|
||||
<example>
|
||||
<![CDATA[
|
||||
with (object) {
|
||||
property = 3; // Might be on object, might be on window: who knows.
|
||||
}
|
||||
]]></example>
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
@ -2,4 +2,8 @@
|
||||
# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
#
|
||||
|
||||
rulesets.filenames=rulesets/ecmascript/basic.xml,rulesets/ecmascript/braces.xml,rulesets/ecmascript/unnecessary.xml
|
||||
rulesets.filenames=\
|
||||
rulesets/ecmascript/basic.xml,\
|
||||
rulesets/ecmascript/braces.xml,\
|
||||
rulesets/ecmascript/controversial.xml,\
|
||||
rulesets/ecmascript/unnecessary.xml
|
||||
|
@ -13,24 +13,24 @@ The Unnecessary Ruleset contains a collection of rules for unnecessary code.
|
||||
since="5.0"
|
||||
message="Unnecessary parentheses."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/unnecessary.html#UnnecessaryParentheses">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_unnecessary.html#unnecessaryparentheses">
|
||||
<description>Unnecessary parentheses should be removed.</description>
|
||||
<priority>4</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
//ParenthesizedExpression/ParenthesizedExpression
|
||||
]]>
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
var x = 1; // Ok
|
||||
var y = (1 + 1); // Ok
|
||||
var z = ((1 + 1)); // Bad
|
||||
]]>
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
@ -39,26 +39,28 @@ var z = ((1 + 1)); // Bad
|
||||
since="5.0"
|
||||
message="Unnecessary block."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/unnecessary.html#UnnecessaryBlock">
|
||||
<description>An unnecessary Block is present. Such Blocks are often used in other languages to
|
||||
introduce a new variable scope. Blocks do not behave like this in ECMAScipt, and using them can
|
||||
be misleading. Considering removing this unnecessary Block.</description>
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_unnecessary.html#unnecessaryblock">
|
||||
<description>
|
||||
An unnecessary Block is present. Such Blocks are often used in other languages to
|
||||
introduce a new variable scope. Blocks do not behave like this in ECMAScipt, and using them can
|
||||
be misleading. Considering removing this unnecessary Block.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//Block[not(parent::FunctionNode or parent::IfStatement or parent::ForLoop or parent::ForInLoop
|
||||
<![CDATA[
|
||||
//Block[not(parent::FunctionNode or parent::IfStatement or parent::ForLoop or parent::ForInLoop
|
||||
or parent::WhileLoop or parent::DoLoop or parent::TryStatement or parent::CatchClause)]
|
||||
|
|
||||
//Scope[not(parent::FunctionNode or parent::IfStatement or parent::ForLoop or parent::ForInLoop
|
||||
//Scope[not(parent::FunctionNode or parent::IfStatement or parent::ForLoop or parent::ForInLoop
|
||||
or parent::WhileLoop or parent::DoLoop or parent::TryStatement or parent::CatchClause)]
|
||||
]]>
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
<![CDATA[
|
||||
if (foo) {
|
||||
// Ok
|
||||
}
|
||||
@ -67,7 +69,7 @@ if (bar) {
|
||||
// Bad
|
||||
}
|
||||
}
|
||||
]]>
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
@ -76,19 +78,25 @@ if (bar) {
|
||||
since="5.5.0"
|
||||
message="The else block is unnecessary"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/unnecessary.html#NoElseReturn">
|
||||
<description>The else block in a if-else-construct is unnecessary if the `if` block contains a return.
|
||||
Then the content of the else block can be put outside.
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_unnecessary.html#noelsereturn">
|
||||
<description>
|
||||
The else block in a if-else-construct is unnecessary if the `if` block contains a return.
|
||||
Then the content of the else block can be put outside.
|
||||
|
||||
See also: http://eslint.org/docs/rules/no-else-return
|
||||
See also: <http://eslint.org/docs/rules/no-else-return>
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath"><value><![CDATA[
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement[@Else="true"][Scope[1]/ReturnStatement]
|
||||
]]></value></property>
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example><![CDATA[
|
||||
<example>
|
||||
<![CDATA[
|
||||
// Bad:
|
||||
if (x) {
|
||||
return y;
|
||||
@ -101,7 +109,8 @@ if (x) {
|
||||
return y;
|
||||
}
|
||||
return z;
|
||||
]]></example>
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
Reference in New Issue
Block a user