Port VM rule
This commit is contained in:
@ -4,19 +4,33 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.vm.rule.design;
|
||||
|
||||
import net.sourceforge.pmd.lang.vm.ast.ASTprocess;
|
||||
import net.sourceforge.pmd.lang.vm.rule.AbstractStatisticalVmRule;
|
||||
import net.sourceforge.pmd.stat.DataPoint;
|
||||
import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;
|
||||
|
||||
public class ExcessiveTemplateLengthRule extends AbstractStatisticalVmRule {
|
||||
import net.sourceforge.pmd.lang.rule.internal.CommonPropertyDescriptors;
|
||||
import net.sourceforge.pmd.lang.vm.ast.ASTprocess;
|
||||
import net.sourceforge.pmd.lang.vm.rule.AbstractVmRule;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
|
||||
public class ExcessiveTemplateLengthRule extends AbstractVmRule {
|
||||
|
||||
private static final PropertyDescriptor<Integer> REPORT_LEVEL =
|
||||
CommonPropertyDescriptors.reportLevelProperty()
|
||||
.desc("Threshold above which a node is reported")
|
||||
.require(positive())
|
||||
.defaultValue(1000)
|
||||
.build();
|
||||
|
||||
ExcessiveTemplateLengthRule() {
|
||||
definePropertyDescriptor(REPORT_LEVEL);
|
||||
addRuleChainVisit(ASTprocess.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(final ASTprocess node, final Object data) {
|
||||
final DataPoint point = new DataPoint();
|
||||
point.setNode(node);
|
||||
point.setScore(1.0 * (node.getEndLine() - node.getBeginLine()));
|
||||
point.setMessage(getMessage());
|
||||
addDataPoint(point);
|
||||
return node.childrenAccept(this, data);
|
||||
|
||||
if (node.getEndLine() - node.getBeginLine() >= getProperty(REPORT_LEVEL)) {
|
||||
addViolation(data, node);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -40,9 +40,6 @@ Sometimes two consecutive 'if' statements can be consolidated by separating thei
|
||||
The template is too long. It should be broken up into smaller pieces.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="1000"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule name="NoInlineJavaScript"
|
||||
|
Reference in New Issue
Block a user