Skip to content

Commit

Permalink
Avoid scanning empty expressions. Closes #222
Browse files Browse the repository at this point in the history
  • Loading branch information
denuno committed Dec 7, 2016
1 parent 38e35d5 commit a303ef4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ protected void doStructureStart(final Element elem, final Context context,
}

protected void scanExpression(final CFScriptStatement expression, Context context, final Element elem) {
if(expression == null)
return;
for (final CFLintScanner plugin : extensions) {
try {
plugin.expression(expression, context, bugs);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/cflint/config/ConfigUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;

public class ConfigUtils {
Expand Down Expand Up @@ -79,6 +80,7 @@ public static String marshalJson(final Object obj)
final ObjectMapper objectMapper = new ObjectMapper();
final JaxbAnnotationModule module = new JaxbAnnotationModule();
objectMapper.registerModule(module);
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.writeValue(sw, obj);
return sw.toString();
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/cflint/TestCFBugs_SimpleComplexity.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ public void testNonComplexNameScriptBased() throws ParseException, IOException {
assertEquals(0, result.size());
}

@Test
public void testIfStatementNoElse() throws ParseException, IOException {
final String cfcSrc = "component {\r\n"+
" public void function foo() {\r\n"+
" if (something) {\r\n"+
" doSomething();\r\n"+
" }\r\n"+
" }\r\n"+
"}";
cfBugs.process(cfcSrc, "test");
Collection<List<BugInfo>> result = cfBugs.getBugs().getBugList().values();
assertEquals(0, result.size());
}

@Test
public void testComplexScriptBased() throws ParseException, IOException {
final String cfcSrc = "component {\r\n"
Expand Down

0 comments on commit a303ef4

Please sign in to comment.