use of net.sourceforge.pmd.lang.ecmascript.ast.ASTFunctionNode in project pmd by pmd.
the class ConsistentReturnRule method visit.
@Override
public Object visit(ASTFunctionNode functionNode, Object data) {
List<ASTReturnStatement> returnStatements = functionNode.findDescendantsOfType(ASTReturnStatement.class);
Boolean hasResult = null;
for (ASTReturnStatement returnStatement : returnStatements) {
// Return for this function?
if (functionNode == returnStatement.getFirstParentOfType(ASTFunctionNode.class)) {
if (hasResult == null) {
hasResult = Boolean.valueOf(returnStatement.hasResult());
} else {
// Return has different result from previous return?
if (hasResult.booleanValue() != returnStatement.hasResult()) {
addViolation(data, functionNode);
break;
}
}
}
}
return data;
}
use of net.sourceforge.pmd.lang.ecmascript.ast.ASTFunctionNode in project pmd by pmd.
the class ReportTest method testExclusionsInReportWithNOPMDEcmascript.
@Test
public void testExclusionsInReportWithNOPMDEcmascript() throws Exception {
Report rpt = new Report();
Rule rule = new AbstractEcmascriptRule() {
@Override
public Object visit(ASTFunctionNode node, Object data) {
EcmascriptRuleViolationFactory.INSTANCE.addViolation((RuleContext) data, this, node, "Test", null);
return super.visit(node, data);
}
};
String code = "function(x) // NOPMD test suppress\n" + "{ x = 1; }";
runTestFromString(code, rule, rpt, LanguageRegistry.getLanguage(EcmascriptLanguageModule.NAME).getDefaultVersion());
assertTrue(rpt.isEmpty());
assertEquals(1, rpt.getSuppressedRuleViolations().size());
}
Aggregations