[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:
Andreas Dangel
2017-08-15 10:20:54 +02:00
parent cfa4e15d54
commit 7efa9021be
5 changed files with 395 additions and 364 deletions

View File

@ -12,8 +12,8 @@
since="5.0" since="5.0"
message="Avoid assignments in operands" message="Avoid assignments in operands"
class="net.sourceforge.pmd.lang.rule.XPathRule" class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#AssignmentInOperand"> externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#assignmentinoperand">
<description> <description>
Avoid assignments in operands; this can make code more complicated and harder to read. This is sometime 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 '=='. indicative of the bug where the assignment operator '=' was used instead of the equality operator '=='.
</description> </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" /> <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> </properties>
<example> <example>
<![CDATA[ <![CDATA[
var x = 2; var x = 2;
// Bad // Bad
if ((x = getX()) == 3) { if ((x = getX()) == 3) {
@ -54,16 +54,16 @@ if ((x = getX()) == 3) {
function getX() { function getX() {
return 3; return 3;
} }
]]> ]]>
</example> </example>
</rule> </rule>
<rule name="UnreachableCode" <rule name="UnreachableCode"
language="ecmascript" language="ecmascript"
since="5.0" since="5.0"
message="A ''return'', ''break'', ''continue'', or ''throw'' statement should be the last in a block." message="A ''return'', ''break'', ''continue'', or ''throw'' statement should be the last in a block."
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>
A 'return', 'break', 'continue', or 'throw' statement should be the last in a block. Statements after these 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. 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> </property>
</properties> </properties>
<example> <example>
<![CDATA[ <![CDATA[
// Ok // Ok
function foo() { function foo() {
return 1; return 1;
@ -105,7 +105,7 @@ function bar() {
since="5.0" since="5.0"
message="The numeric literal ''{0}'' will have at different value at runtime." message="The numeric literal ''{0}'' will have at different value at runtime."
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>
The numeric literal will have at different value at runtime, which can happen if you provide too much 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. 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> <properties>
<property name="xpath"> <property name="xpath">
<value> <value>
<![CDATA[ <![CDATA[
//NumberLiteral[ //NumberLiteral[
@Image != @Number @Image != @Number
and translate(@Image, "e", "E") != @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> </property>
</properties> </properties>
<example> <example>
<![CDATA[ <![CDATA[
var a = 9; // Ok var a = 9; // Ok
var b = 999999999999999; // Ok var b = 999999999999999; // Ok
var c = 999999999999999999999; // Not good var c = 999999999999999999999; // Not good
@ -141,7 +141,7 @@ var z = 1.12345678901234567; // Not good
since="5.0" since="5.0"
message="A function should not mix 'return' statements with and without a result." message="A function should not mix 'return' statements with and without a result."
class="net.sourceforge.pmd.lang.ecmascript.rule.basic.ConsistentReturnRule" 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> <description>
ECMAScript does provide for return types on functions, and therefore there is no solid rule as to their usage. 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 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> </description>
<priority>2</priority> <priority>2</priority>
<example> <example>
<![CDATA[ <![CDATA[
// Ok // Ok
function foo() { function foo() {
if (condition1) { if (condition1) {
@ -174,7 +174,7 @@ function bar() {
since="5.0" since="5.0"
message="The for-in loop variable ''{0}'' should be explicitly scoped with 'var' to avoid pollution." message="The for-in loop variable ''{0}'' should be explicitly scoped with 'var' to avoid pollution."
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>
A for-in loop in which the variable name is not explicitly scoped to the enclosing scope with the 'var' keyword can 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 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> <properties>
<property name="xpath"> <property name="xpath">
<value> <value>
<![CDATA[ <![CDATA[
//ForInLoop[not(child::VariableDeclaration)]/Name[1] //ForInLoop[not(child::VariableDeclaration)]/Name[1]
]]> ]]>
</value> </value>
</property> </property>
</properties> </properties>
<example> <example>
<![CDATA[ <![CDATA[
// Ok // Ok
function foo() { function foo() {
var p = 'clean'; var p = 'clean';
@ -230,16 +230,16 @@ function bar() {
since="5.0" since="5.0"
message="Use '==='/'!==' to compare with true/false or Numbers" message="Use '==='/'!==' to compare with true/false or Numbers"
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>
Using == in condition may lead to unexpected results, as the variables are automatically casted to be of the 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. same type. The === operator avoids the casting.
</description> </description>
<priority>3</priority> <priority>3</priority>
<properties> <properties>
<property name="xpath"> <property name="xpath">
<value> <value>
<![CDATA[ <![CDATA[
//InfixExpression[(@Image = "==" or @Image = "!=") //InfixExpression[(@Image = "==" or @Image = "!=")
and and
(child::KeywordLiteral[@Image = "true" or @Image = "false"] (child::KeywordLiteral[@Image = "true" or @Image = "false"]
@ -251,7 +251,7 @@ function bar() {
</property> </property>
</properties> </properties>
<example> <example>
<![CDATA[ <![CDATA[
// Ok // Ok
if (someVar === true) { if (someVar === true) {
... ...
@ -268,7 +268,6 @@ if (someVar == true) {
if (someVar != 3) { if (someVar != 3) {
... ...
} }
]]> ]]>
</example> </example>
</rule> </rule>
@ -278,7 +277,7 @@ if (someVar != 3) {
language="ecmascript" language="ecmascript"
since="5.0" since="5.0"
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>
This rule helps to avoid using accidently global variables by simply missing the "var" declaration. 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. Global variables can lead to side-effects that are hard to debug.
@ -311,7 +310,7 @@ function(arg) {
language="ecmascript" language="ecmascript"
since="5.1" since="5.1"
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>
This rule helps improve code portability due to differences in browser treatment of trailing commas in object or array literals. This rule helps improve code portability due to differences in browser treatment of trailing commas in object or array literals.
</description> </description>
@ -320,9 +319,9 @@ This rule helps improve code portability due to differences in browser treatment
<property name="xpath"> <property name="xpath">
<value> <value>
<![CDATA[ <![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> </value>
</property> </property>
@ -346,22 +345,35 @@ function(arg) {
message="Always provide a base when using parseInt() functions" message="Always provide a base when using parseInt() functions"
language="ecmascript" since="5.0.1" language="ecmascript" since="5.0.1"
class="net.sourceforge.pmd.lang.rule.XPathRule" class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/basic.html#UseBaseWithParseInt"> externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_basic.html#usebasewithparseint">
<description>TODO</description> <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> <priority>1</priority>
<properties> <properties>
<property name="xpath"> <property name="xpath">
<value><![CDATA[ <value>
<![CDATA[
//FunctionCall/Name[ //FunctionCall/Name[
@Image = 'parseInt' @Image = 'parseInt'
and and
count(../*) < 3 count(../*) < 3
] ]
]]></value> ]]>
</value>
</property> </property>
</properties> </properties>
<example><![CDATA[ <example>
parseInt("10",base); <![CDATA[
]]></example> parseInt("010"); // unclear, could be interpreted as 10 or 7 (with a base of 7)
parseInt("10", 10); // good
]]>
</example>
</rule> </rule>
</ruleset> </ruleset>

View File

@ -13,7 +13,7 @@ The Braces Ruleset contains a collection of braces rules.
since="5.0" since="5.0"
message="Avoid using if statements without curly braces" message="Avoid using if statements without curly braces"
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>
Avoid using if statements without using curly braces. Avoid using if statements without using curly braces.
</description> </description>
@ -21,14 +21,14 @@ Avoid using if statements without using curly braces.
<properties> <properties>
<property name="xpath"> <property name="xpath">
<value> <value>
<![CDATA[ <![CDATA[
//IfStatement[@Else = "false" and not(child::Scope)] //IfStatement[@Else = "false" and not(child::Scope)]
]]> ]]>
</value> </value>
</property> </property>
</properties> </properties>
<example> <example>
<![CDATA[ <![CDATA[
// Ok // Ok
if (foo) { if (foo) {
x++; x++;
@ -37,7 +37,7 @@ if (foo) {
// Bad // Bad
if (foo) if (foo)
x++; x++;
]]> ]]>
</example> </example>
</rule> </rule>
@ -46,7 +46,7 @@ if (foo)
since="5.0" since="5.0"
message="Avoid using 'if...else' statements without curly braces" message="Avoid using 'if...else' statements without curly braces"
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>
Avoid using if..else statements without using curly braces. Avoid using if..else statements without using curly braces.
</description> </description>
@ -58,7 +58,7 @@ Avoid using if..else statements without using curly braces.
//ExpressionStatement[parent::IfStatement[@Else = "true"]] //ExpressionStatement[parent::IfStatement[@Else = "true"]]
[not(child::Scope)] [not(child::Scope)]
[not(child::IfStatement)] [not(child::IfStatement)]
]]> ]]>
</value> </value>
</property> </property>
</properties> </properties>
@ -85,7 +85,7 @@ else
since="5.0" since="5.0"
message="Avoid using 'while' statements without curly braces" message="Avoid using 'while' statements without curly braces"
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>
Avoid using 'while' statements without using curly braces. Avoid using 'while' statements without using curly braces.
</description> </description>
@ -118,7 +118,7 @@ while (true)
since="5.0" since="5.0"
message="Avoid using 'for' statements without curly braces" message="Avoid using 'for' statements without curly braces"
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>
Avoid using 'for' statements without using curly braces. Avoid using 'for' statements without using curly braces.
</description> </description>
@ -127,9 +127,9 @@ Avoid using 'for' statements without using curly braces.
<property name="xpath"> <property name="xpath">
<value> <value>
<![CDATA[ <![CDATA[
//ForLoop[not(child::Scope)] //ForLoop[not(child::Scope)]
| |
//ForInLoop[not(child::Scope)] //ForInLoop[not(child::Scope)]
]]> ]]>
</value> </value>
</property> </property>

View File

@ -12,22 +12,28 @@ They are held here to allow people to include them as they see fit within their
<rule name="AvoidWithStatement" <rule name="AvoidWithStatement"
message="Avoid using with - it's bad news" 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" 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> <description>Avoid using with - it's bad news</description>
<priority>1</priority>
<properties> <properties>
<property name="xpath"> <property name="xpath">
<value><![CDATA[ <value>
<![CDATA[
//WithStatement //WithStatement
]]></value> ]]>
</value>
</property> </property>
</properties> </properties>
<priority>1</priority> <example>
<example><![CDATA[ <![CDATA[
with (object) { with (object) {
property = 3; // Might be on object, might be on window: who knows. property = 3; // Might be on object, might be on window: who knows.
} }
]]></example> ]]>
</example>
</rule> </rule>
</ruleset> </ruleset>

View File

@ -2,4 +2,8 @@
# BSD-style license; for more info see http://pmd.sourceforge.net/license.html # 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

View File

@ -13,24 +13,24 @@ The Unnecessary Ruleset contains a collection of rules for unnecessary code.
since="5.0" since="5.0"
message="Unnecessary parentheses." message="Unnecessary parentheses."
class="net.sourceforge.pmd.lang.rule.XPathRule" 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> <description>Unnecessary parentheses should be removed.</description>
<priority>4</priority> <priority>4</priority>
<properties> <properties>
<property name="xpath"> <property name="xpath">
<value> <value>
<![CDATA[ <![CDATA[
//ParenthesizedExpression/ParenthesizedExpression //ParenthesizedExpression/ParenthesizedExpression
]]> ]]>
</value> </value>
</property> </property>
</properties> </properties>
<example> <example>
<![CDATA[ <![CDATA[
var x = 1; // Ok var x = 1; // Ok
var y = (1 + 1); // Ok var y = (1 + 1); // Ok
var z = ((1 + 1)); // Bad var z = ((1 + 1)); // Bad
]]> ]]>
</example> </example>
</rule> </rule>
@ -39,26 +39,28 @@ var z = ((1 + 1)); // Bad
since="5.0" since="5.0"
message="Unnecessary block." message="Unnecessary block."
class="net.sourceforge.pmd.lang.rule.XPathRule" class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/unnecessary.html#UnnecessaryBlock"> 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 <description>
introduce a new variable scope. Blocks do not behave like this in ECMAScipt, and using them can An unnecessary Block is present. Such Blocks are often used in other languages to
be misleading. Considering removing this unnecessary Block.</description> 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> <priority>3</priority>
<properties> <properties>
<property name="xpath"> <property name="xpath">
<value> <value>
<![CDATA[ <![CDATA[
//Block[not(parent::FunctionNode or parent::IfStatement or parent::ForLoop or parent::ForInLoop //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)] 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)] or parent::WhileLoop or parent::DoLoop or parent::TryStatement or parent::CatchClause)]
]]> ]]>
</value> </value>
</property> </property>
</properties> </properties>
<example> <example>
<![CDATA[ <![CDATA[
if (foo) { if (foo) {
// Ok // Ok
} }
@ -67,7 +69,7 @@ if (bar) {
// Bad // Bad
} }
} }
]]> ]]>
</example> </example>
</rule> </rule>
@ -76,19 +78,25 @@ if (bar) {
since="5.5.0" since="5.5.0"
message="The else block is unnecessary" message="The else block is unnecessary"
class="net.sourceforge.pmd.lang.rule.XPathRule" class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/rules/ecmascript/unnecessary.html#NoElseReturn"> 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. <description>
Then the content of the else block can be put outside. 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: &lt;http://eslint.org/docs/rules/no-else-return>
</description> </description>
<priority>3</priority> <priority>3</priority>
<properties> <properties>
<property name="xpath"><value><![CDATA[ <property name="xpath">
<value>
<![CDATA[
//IfStatement[@Else="true"][Scope[1]/ReturnStatement] //IfStatement[@Else="true"][Scope[1]/ReturnStatement]
]]></value></property> ]]>
</value>
</property>
</properties> </properties>
<example><![CDATA[ <example>
<![CDATA[
// Bad: // Bad:
if (x) { if (x) {
return y; return y;
@ -101,7 +109,8 @@ if (x) {
return y; return y;
} }
return z; return z;
]]></example> ]]>
</example>
</rule> </rule>
</ruleset> </ruleset>