Port VM rule

This commit is contained in:
Clément Fournier
2019-04-02 08:46:20 +02:00
parent 0ede213953
commit ab1b50a3f6
2 changed files with 24 additions and 13 deletions

View File

@ -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;
}
}

View File

@ -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"