PMD Rulesets index: Current Rulesets
List of rulesets and rules contained in each ruleset.
- Braces: The Braces Ruleset contains a collection of braces rules.
- Controversial Ecmascript: The Controversial ruleset contains rules that, for whatever reason, are considered controversial.They are held here to allow people to include them as they see fit within their custom rulesets.
- Unnecessary: The Unnecessary Ruleset contains a collection of rules for unnecessary code.
Basic Ecmascript (ecmascript)
- AssignmentInOperand: Avoid assignments in operands; this can make code more complicated and harder to read. This is sometimeindicative of the bug where the assignment operator ‘=’ was used instead of the equality operator ‘==’.
- UnreachableCode: A ‘return’, ‘break’, ‘continue’, or ‘throw’ statement should be the last in a block. Statements after thesewill never execute. This is a bug, or extremely poor style.
- InnaccurateNumericLiteral: The numeric literal will have at different value at runtime, which can happen if you provide too muchprecision in a floating point number. This may result in numeric calculations being in error.
- ConsistentReturn: 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 returnusage is likely a bug, or at best poor style.
- ScopeForInVariable: A for-in loop in which the variable name is not explicitly scoped to the enclosing scope with the ‘var’ keyword canrefer to a variable in an enclosing scope outside the nearest enclosing scope. This will overwrite theexisting value of the variable in the outer scope when the body of the for-in is evaluated. When the for-in loophas finished, the variable will contain the last value used in the for-in, and the original value from beforethe for-in loop will be gone. Since the for-in variable name is most likely intended to be a temporary name, itis better to explicitly scope the variable name to the nearest enclosing scope with ‘var’.
- EqualComparison: 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.
- GlobalVariable: 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.
- AvoidTrailingComma: This rule helps improve code portability due to differences in browser treatment of trailing commas in object or array literals.
Controversial Ecmascript (ecmascript)
- UnnecessaryBlock: 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.