From 15b19e93f16b390705e15be924b5a9635375b790 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 21:10:40 -0400 Subject: [PATCH 01/20] configure abort checker --- src/main/java/com/cflint/plugins/core/AbortChecker.java | 6 +----- src/main/resources/cflint.definition.json | 3 ++- src/main/resources/cflint.definition.xml | 1 + 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/cflint/plugins/core/AbortChecker.java b/src/main/java/com/cflint/plugins/core/AbortChecker.java index 06c88e051..ea01ca7ee 100644 --- a/src/main/java/com/cflint/plugins/core/AbortChecker.java +++ b/src/main/java/com/cflint/plugins/core/AbortChecker.java @@ -16,11 +16,7 @@ public class AbortChecker extends CFLintScannerAdapter { @Override public void expression(final CFScriptStatement expression, final Context context, final BugList bugs) { if (expression instanceof CFAbortStatement) { - int lineNo = ((CFAbortStatement) expression).getLine() + context.startLine() - 1; - bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("AVOID_USING_ABORT") - .setSeverity(severity).setFilename(context.getFilename()) - .setMessage("Abort statement at line " + lineNo + ". Avoid using abort in production code.") - .build()); + context.addMessage("AVOID_USING_ABORT", null); } } } \ No newline at end of file diff --git a/src/main/resources/cflint.definition.json b/src/main/resources/cflint.definition.json index 6f71180d6..28247dfdc 100644 --- a/src/main/resources/cflint.definition.json +++ b/src/main/resources/cflint.definition.json @@ -184,7 +184,8 @@ "message": [ { "code": "AVOID_USING_ABORT", - "severity": "INFO" + "severity": "INFO", + "messageText" : "Avoid using abort in production code."; } ], "parameter": [ diff --git a/src/main/resources/cflint.definition.xml b/src/main/resources/cflint.definition.xml index 0ae90b857..27281ee58 100644 --- a/src/main/resources/cflint.definition.xml +++ b/src/main/resources/cflint.definition.xml @@ -90,6 +90,7 @@ INFO + Avoid using abort in production code. From 8550adf130e7b622f73b150090c2929a139c542f Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 21:15:02 -0400 Subject: [PATCH 02/20] Argument hint checker uses the config. --- src/main/java/com/cflint/plugins/core/ArgHintChecker.java | 6 +----- src/main/resources/cflint.definition.json | 3 ++- src/main/resources/cflint.definition.xml | 1 + 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/cflint/plugins/core/ArgHintChecker.java b/src/main/java/com/cflint/plugins/core/ArgHintChecker.java index 22ef3e762..ef304704d 100644 --- a/src/main/java/com/cflint/plugins/core/ArgHintChecker.java +++ b/src/main/java/com/cflint/plugins/core/ArgHintChecker.java @@ -16,11 +16,7 @@ public void element(final Element element, final Context context, final BugList final String name = element.getAttributeValue("name"); final String hint = element.getAttributeValue("hint"); if (hint == null || hint.length() == 0) { - int begLine = element.getSource().getRow(element.getBegin()); - bugs.add(new BugInfo.BugInfoBuilder().setLine(begLine).setMessageCode("ARG_HINT_MISSING") - .setSeverity(severity).setFilename(context.getFilename()).setFunction(context.getFunctionName()) - .setMessage("Argument " + name + " is missing a hint.") - .build()); + context.addMessage("ARG_HINT_MISSING", name); } } } diff --git a/src/main/resources/cflint.definition.json b/src/main/resources/cflint.definition.json index 28247dfdc..607fbdb7f 100644 --- a/src/main/resources/cflint.definition.json +++ b/src/main/resources/cflint.definition.json @@ -296,7 +296,8 @@ "message": [ { "code": "ARG_HINT_MISSING", - "severity": "INFO" + "severity": "INFO", + "messageText" : "Argument ${variable} is missing a hint." } ], "parameter": [ diff --git a/src/main/resources/cflint.definition.xml b/src/main/resources/cflint.definition.xml index 27281ee58..2a46bf080 100644 --- a/src/main/resources/cflint.definition.xml +++ b/src/main/resources/cflint.definition.xml @@ -134,6 +134,7 @@ + Argument ${variable} is missing a hint. INFO From e56db9ca565e6e79c8719f2e6dccbacba7c8f571 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 21:17:34 -0400 Subject: [PATCH 03/20] cleanup --- src/main/java/com/cflint/plugins/core/AbortChecker.java | 1 - src/main/java/com/cflint/plugins/core/ArgDefChecker.java | 2 -- src/main/java/com/cflint/plugins/core/ArgHintChecker.java | 2 -- src/main/resources/cflint.definition.xml | 4 ++-- 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/cflint/plugins/core/AbortChecker.java b/src/main/java/com/cflint/plugins/core/AbortChecker.java index ea01ca7ee..6a4bb16c1 100644 --- a/src/main/java/com/cflint/plugins/core/AbortChecker.java +++ b/src/main/java/com/cflint/plugins/core/AbortChecker.java @@ -1,6 +1,5 @@ package com.cflint.plugins.core; -import com.cflint.BugInfo; import com.cflint.BugList; import com.cflint.plugins.CFLintScannerAdapter; import com.cflint.plugins.Context; diff --git a/src/main/java/com/cflint/plugins/core/ArgDefChecker.java b/src/main/java/com/cflint/plugins/core/ArgDefChecker.java index b20f25ab2..77a8b1ead 100644 --- a/src/main/java/com/cflint/plugins/core/ArgDefChecker.java +++ b/src/main/java/com/cflint/plugins/core/ArgDefChecker.java @@ -20,8 +20,6 @@ public void expression(final CFScriptStatement expression, final Context context // handler.addArgument(param.getName()); final String name = argument.getName(); if (!argument.toString().contains("required") && !argument.toString().contains("=")) { - function.getLine(); - function.getColumn(); context.addMessage("ARG_DEFAULT_MISSING", name); } } diff --git a/src/main/java/com/cflint/plugins/core/ArgHintChecker.java b/src/main/java/com/cflint/plugins/core/ArgHintChecker.java index ef304704d..7f10a53f1 100644 --- a/src/main/java/com/cflint/plugins/core/ArgHintChecker.java +++ b/src/main/java/com/cflint/plugins/core/ArgHintChecker.java @@ -1,6 +1,5 @@ package com.cflint.plugins.core; -import com.cflint.BugInfo; import com.cflint.BugList; import com.cflint.plugins.CFLintScannerAdapter; import com.cflint.plugins.Context; @@ -8,7 +7,6 @@ import net.htmlparser.jericho.Element; public class ArgHintChecker extends CFLintScannerAdapter { - final String severity = "INFO"; @Override public void element(final Element element, final Context context, final BugList bugs) { diff --git a/src/main/resources/cflint.definition.xml b/src/main/resources/cflint.definition.xml index 2a46bf080..9a0bdb061 100644 --- a/src/main/resources/cflint.definition.xml +++ b/src/main/resources/cflint.definition.xml @@ -83,13 +83,13 @@ Avoid Leaving <${tagName}> tags in committed code. Did you accidently leave a cfabort in the code? - INFO + WARNING - INFO + WARNING Avoid using abort in production code. From fe12344479d43f29cf6fb9f98b343bd7ff4d8f9a Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 21:38:19 -0400 Subject: [PATCH 04/20] ArgTypeChecker parameterized --- .../cflint/plugins/core/ArgTypeChecker.java | 32 +++---------------- src/main/resources/cflint.definition.json | 6 ++-- src/main/resources/cflint.definition.xml | 2 ++ .../java/com/cflint/TestCFBugs_ArgsType.java | 14 ++++++-- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/cflint/plugins/core/ArgTypeChecker.java b/src/main/java/com/cflint/plugins/core/ArgTypeChecker.java index 72f188576..ec8052592 100644 --- a/src/main/java/com/cflint/plugins/core/ArgTypeChecker.java +++ b/src/main/java/com/cflint/plugins/core/ArgTypeChecker.java @@ -1,6 +1,5 @@ package com.cflint.plugins.core; -import com.cflint.BugInfo; import com.cflint.BugList; import com.cflint.plugins.CFLintScannerAdapter; import com.cflint.plugins.Context; @@ -11,32 +10,21 @@ import net.htmlparser.jericho.Element; public class ArgTypeChecker extends CFLintScannerAdapter { - public static final String ARGUMENT = "Argument "; - final String severity = "WARNING"; @Override public void expression(final CFScriptStatement expression, final Context context, final BugList bugs) { if (expression instanceof CFFuncDeclStatement) { final CFFuncDeclStatement function = (CFFuncDeclStatement) expression; - final int begLine = function.getLine(); for (final CFFunctionParameter argument : function.getFormals()) { final String name = argument.getName(); final String variableType = argument.getType(); if (variableType == null) { - bugs.add(new BugInfo.BugInfoBuilder().setLine(begLine).setMessageCode("ARG_TYPE_MISSING") - .setSeverity(severity).setFilename(context.getFilename()).setFunction(context.getFunctionName()) - .setMessage(ARGUMENT + name + " is missing a type.") - .setVariable(name) - .build()); + context.addMessage("ARG_TYPE_MISSING", name); } else if (variableType.equals("any")) { - bugs.add(new BugInfo.BugInfoBuilder().setLine(begLine).setMessageCode("ARG_TYPE_ANY") - .setSeverity(severity).setFilename(context.getFilename()).setFunction(context.getFunctionName()) - .setMessage(ARGUMENT + name + " is any. Please change to be the correct type.") - .setVariable(name) - .build()); + context.addMessage("ARG_TYPE_ANY", name); } } } @@ -47,24 +35,14 @@ public void element(final Element element, final Context context, final BugList if (element.getName().equals("cfargument")) { final String name = element.getAttributeValue("name"); final String variableType = element.getAttributeValue("type"); - int begLine = element.getSource().getRow(element.getBegin()); if (variableType == null) { - bugs.add(new BugInfo.BugInfoBuilder().setLine(begLine).setMessageCode("ARG_TYPE_MISSING") - .setSeverity(severity).setFilename(context.getFilename()).setFunction(context.getFunctionName()) - .setMessage(ARGUMENT + name + " is missing a type.") - .setVariable(name) - .build()); + context.addMessage("ARG_TYPE_MISSING", name); } else if (variableType.equals("any")) { - bugs.add(new BugInfo.BugInfoBuilder().setLine(begLine).setMessageCode("ARG_TYPE_ANY") - .setSeverity(severity).setFilename(context.getFilename()) - .setFunction(context.getFunctionName()) - .setMessage(ARGUMENT + name + " is any. Please change to be the correct type.") - .setVariable(name) - .build()); + context.addMessage("ARG_TYPE_ANY", name); } } } -} +} \ No newline at end of file diff --git a/src/main/resources/cflint.definition.json b/src/main/resources/cflint.definition.json index 607fbdb7f..f74eea44f 100644 --- a/src/main/resources/cflint.definition.json +++ b/src/main/resources/cflint.definition.json @@ -310,11 +310,13 @@ "message": [ { "code": "ARG_TYPE_MISSING", - "severity": "WARNING" + "severity": "WARNING", + "messageText": "ARGUMENT ${variable} is missing a type." }, { "code": "ARG_TYPE_ANY", - "severity": "INFO" + "severity": "WARNING" + "messageText": "Argument ${variable} is any. Please change to be the correct type." } ], "parameter": [ diff --git a/src/main/resources/cflint.definition.xml b/src/main/resources/cflint.definition.xml index 9a0bdb061..54e7a8a0a 100644 --- a/src/main/resources/cflint.definition.xml +++ b/src/main/resources/cflint.definition.xml @@ -140,9 +140,11 @@ + ARGUMENT ${variable} is missing a type. WARNING + Argument ${variable} is any. Please change to be the correct type. INFO diff --git a/src/test/java/com/cflint/TestCFBugs_ArgsType.java b/src/test/java/com/cflint/TestCFBugs_ArgsType.java index c494f565c..baddc8862 100644 --- a/src/test/java/com/cflint/TestCFBugs_ArgsType.java +++ b/src/test/java/com/cflint/TestCFBugs_ArgsType.java @@ -27,11 +27,11 @@ public void setUp() { conf.getRules().add(pluginRule); final PluginMessage pluginMessageMissing = new PluginMessage("ARG_TYPE_MISSING"); pluginMessageMissing.setSeverity("WARNING"); - pluginMessageMissing.setMessageText("Argument ${variable} is missing a hint."); + pluginMessageMissing.setMessageText("Argument ${variable} is missing a type."); pluginRule.getMessages().add(pluginMessageMissing); final PluginMessage pluginMessageAny = new PluginMessage("ARG_TYPE_ANY"); - pluginMessageAny.setSeverity("INFO"); - pluginMessageAny.setMessageText("Argument ${variable} is any, please use correct type."); + pluginMessageAny.setSeverity("WARNING"); + pluginMessageAny.setMessageText("Argument ${variable} is any. Please change to be the correct type."); pluginRule.getMessages().add(pluginMessageAny); cfBugs = new CFLint(conf, new ArgTypeChecker()); @@ -49,6 +49,8 @@ public void testMissingType() throws ParseException, IOException { assertEquals(1, result.size()); assertEquals("ARG_TYPE_MISSING", result.get(0).getMessageCode()); assertEquals(3, result.get(0).getLine()); + assertEquals("WARNING", result.get(0).getSeverity()); + assertEquals("Argument xyz is missing a type.", result.get(0).getMessage()); } @Test @@ -62,6 +64,8 @@ public void testMissingTypeNoTags() throws ParseException, IOException { assertEquals(1, result.size()); assertEquals("ARG_TYPE_MISSING", result.get(0).getMessageCode()); assertEquals(2, result.get(0).getLine()); + assertEquals("WARNING", result.get(0).getSeverity()); + assertEquals("Argument arg1 is missing a type.", result.get(0).getMessage()); } @Test @@ -76,6 +80,8 @@ public void testTypeAny() throws ParseException, IOException { assertEquals(1, result.size()); assertEquals("ARG_TYPE_ANY", result.get(0).getMessageCode()); assertEquals(3, result.get(0).getLine()); + assertEquals("WARNING", result.get(0).getSeverity()); + assertEquals("Argument xyz is any. Please change to be the correct type.", result.get(0).getMessage()); } @Test @@ -89,6 +95,8 @@ public void testTypeAnyNoTags() throws ParseException, IOException { assertEquals(1, result.size()); assertEquals("ARG_TYPE_ANY", result.get(0).getMessageCode()); assertEquals(2, result.get(0).getLine()); + assertEquals("WARNING", result.get(0).getSeverity()); + assertEquals("Argument arg1 is any. Please change to be the correct type.", result.get(0).getMessage()); } } From 9fa09a80223ee79e789d28a53308b56b27ef4bd1 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 21:47:21 -0400 Subject: [PATCH 05/20] ArrayNewChecker parameterize message. --- .../com/cflint/plugins/core/ArrayNewChecker.java | 14 ++------------ src/main/resources/cflint.definition.json | 1 + src/main/resources/cflint.definition.xml | 1 + src/test/java/com/cflint/TestArrayNewChecker.java | 6 ++++++ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/cflint/plugins/core/ArrayNewChecker.java b/src/main/java/com/cflint/plugins/core/ArrayNewChecker.java index bd89b7ac4..9666ba01a 100644 --- a/src/main/java/com/cflint/plugins/core/ArrayNewChecker.java +++ b/src/main/java/com/cflint/plugins/core/ArrayNewChecker.java @@ -1,6 +1,5 @@ package com.cflint.plugins.core; -import com.cflint.BugInfo; import com.cflint.BugList; import com.cflint.plugins.CFLintScannerAdapter; import com.cflint.plugins.Context; @@ -12,16 +11,14 @@ @Extension public class ArrayNewChecker extends CFLintScannerAdapter { - final String severity = "INFO"; @Override public void expression(final CFScriptStatement expression, final Context context, final BugList bugs) { if (expression instanceof CFExpressionStatement) { String code = ((CFExpressionStatement) expression).getExpression().Decompile(0); - int lineNo = ((CFExpressionStatement) expression).getLine() + context.startLine() - 1; if (code.toLowerCase().contains("arraynew(1)")) { - arrayNew(lineNo, context, bugs); + context.addMessage("AVOID_USING_ARRAYNEW", null); } } } @@ -30,18 +27,11 @@ public void expression(final CFScriptStatement expression, final Context context public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals("cfset")) { String content = element.getStartTag().getTagContent().toString(); - int lineNo = element.getSource().getRow(element.getBegin()); if (content.toLowerCase().contains("arraynew(1)")) { - arrayNew(lineNo, context, bugs); + context.addMessage("AVOID_USING_ARRAYNEW", null); } } } - protected void arrayNew(final int lineNo, final Context context, final BugList bugs) { - bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("AVOID_USING_ARRAYNEW") - .setSeverity(severity).setFilename(context.getFilename()) - .setMessage("ArrayNew statement at line " + lineNo + ". Use implict array construction instead (= []).") - .build()); - } } \ No newline at end of file diff --git a/src/main/resources/cflint.definition.json b/src/main/resources/cflint.definition.json index f74eea44f..f0db5807d 100644 --- a/src/main/resources/cflint.definition.json +++ b/src/main/resources/cflint.definition.json @@ -476,6 +476,7 @@ "className": "ArrayNewChecker", "message": [ { + "messageText": "Use implict array construction instead (= []).", "code": "AVOID_USING_ARRAYNEW", "severity": "INFO" } diff --git a/src/main/resources/cflint.definition.xml b/src/main/resources/cflint.definition.xml index 54e7a8a0a..b0e075828 100644 --- a/src/main/resources/cflint.definition.xml +++ b/src/main/resources/cflint.definition.xml @@ -209,6 +209,7 @@ + Use implict array construction instead (= []). INFO diff --git a/src/test/java/com/cflint/TestArrayNewChecker.java b/src/test/java/com/cflint/TestArrayNewChecker.java index c4a6845e1..0c054e87b 100644 --- a/src/test/java/com/cflint/TestArrayNewChecker.java +++ b/src/test/java/com/cflint/TestArrayNewChecker.java @@ -27,6 +27,8 @@ public void setUp() { conf.getRules().add(pluginRule); final PluginMessage pluginMessage = new PluginMessage("AVOID_USING_ARRAYNEW"); pluginMessage.setSeverity("INFO"); + pluginMessage.setMessageText("Use implict array construction instead (= [])."); + pluginRule.getMessages().add(pluginMessage); cfBugs = new CFLint(conf, new ArrayNewChecker()); } @@ -42,6 +44,8 @@ public void testArrayNewInScript() throws ParseException, IOException { assertEquals(1, result.size()); assertEquals("AVOID_USING_ARRAYNEW", result.get(0).getMessageCode()); assertEquals(3, result.get(0).getLine()); + assertEquals("INFO", result.get(0).getSeverity()); + assertEquals("Use implict array construction instead (= []).", result.get(0).getMessage()); } @Test @@ -65,6 +69,8 @@ public void testArrayNewInTag() throws ParseException, IOException { assertEquals(1, result.size()); assertEquals("AVOID_USING_ARRAYNEW", result.get(0).getMessageCode()); assertEquals(2, result.get(0).getLine()); + assertEquals("INFO", result.get(0).getSeverity()); + assertEquals("Use implict array construction instead (= []).", result.get(0).getMessage()); } } From 40e64a434e18af427a54a9ec1edb1e4cdf8a759b Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 21:52:48 -0400 Subject: [PATCH 06/20] BooleanExpressionChecker parameterized --- .../core/BooleanExpressionChecker.java | 19 ++++++++----------- src/main/resources/cflint.definition.json | 1 + src/main/resources/cflint.definition.xml | 1 + .../cflint/TestBooleanExpressionChecker.java | 2 ++ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/cflint/plugins/core/BooleanExpressionChecker.java b/src/main/java/com/cflint/plugins/core/BooleanExpressionChecker.java index 4061815aa..ce01d659f 100644 --- a/src/main/java/com/cflint/plugins/core/BooleanExpressionChecker.java +++ b/src/main/java/com/cflint/plugins/core/BooleanExpressionChecker.java @@ -1,6 +1,5 @@ package com.cflint.plugins.core; -import com.cflint.BugInfo; import com.cflint.BugList; import com.cflint.plugins.CFLintScannerAdapter; import com.cflint.plugins.Context; @@ -9,10 +8,15 @@ import cfml.parsing.cfscript.CFExpression; public class BooleanExpressionChecker extends CFLintScannerAdapter { - final String severity = "INFO"; - protected int lastLineNo = -1; + //Reset the last line number + @Override + public void startFile(String fileName, BugList bugs) { + super.startFile(fileName, bugs); + lastLineNo = -1; + } + @Override public void expression(final CFExpression expression, final Context context, final BugList bugs) { if (expression instanceof CFBinaryExpression) { @@ -23,7 +27,7 @@ public void expression(final CFExpression expression, final Context context, fin // Only report issue once per line if (lastLineNo != lineNo) { - booleanExpression(lineNo, context, bugs); + context.addMessage("EXPLICIT_BOOLEAN_CHECK", null); lastLineNo = lineNo; } } @@ -36,11 +40,4 @@ protected boolean hasExplicitBooleanCheck(final String code) { || code.contains("== false") || code.contains("eq false") || code.contains("is false") || code.contains("!= false"); } - public void booleanExpression(final int lineNo, final Context context, final BugList bugs) { - bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("EXPLICIT_BOOLEAN_CHECK") - .setSeverity(severity).setFilename(context.getFilename()) - .setMessage("Explicit check of boolean expession at " + lineNo + " is not needed.") - .build()); - } - } diff --git a/src/main/resources/cflint.definition.json b/src/main/resources/cflint.definition.json index f0db5807d..37857f6ab 100644 --- a/src/main/resources/cflint.definition.json +++ b/src/main/resources/cflint.definition.json @@ -499,6 +499,7 @@ "className": "BooleanExpressionChecker", "message": [ { + "messageText" : "Explicit check of boolean expession is not needed.", "code": "EXPLICIT_BOOLEAN_CHECK", "severity": "INFO" } diff --git a/src/main/resources/cflint.definition.xml b/src/main/resources/cflint.definition.xml index b0e075828..f52081e46 100644 --- a/src/main/resources/cflint.definition.xml +++ b/src/main/resources/cflint.definition.xml @@ -220,6 +220,7 @@ + Explicit check of boolean expession is not needed. INFO diff --git a/src/test/java/com/cflint/TestBooleanExpressionChecker.java b/src/test/java/com/cflint/TestBooleanExpressionChecker.java index fc661c0b0..e2916e40a 100644 --- a/src/test/java/com/cflint/TestBooleanExpressionChecker.java +++ b/src/test/java/com/cflint/TestBooleanExpressionChecker.java @@ -27,6 +27,8 @@ public void setUp() { conf.getRules().add(pluginRule); final PluginMessage pluginMessage = new PluginMessage("EXPLICIT_BOOLEAN_CHECK"); pluginMessage.setSeverity("INFO"); + pluginMessage.setMessageText("Explicit check of boolean expession is not needed."); + pluginRule.getMessages().add(pluginMessage); cfBugs = new CFLint(conf, new BooleanExpressionChecker()); } From 91464f605892a27ade24a6ccf5fba78c2150e41c Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 22:11:20 -0400 Subject: [PATCH 07/20] fix json formatting --- src/main/resources/cflint.definition.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/cflint.definition.json b/src/main/resources/cflint.definition.json index 37857f6ab..93e9b8754 100644 --- a/src/main/resources/cflint.definition.json +++ b/src/main/resources/cflint.definition.json @@ -185,7 +185,7 @@ { "code": "AVOID_USING_ABORT", "severity": "INFO", - "messageText" : "Avoid using abort in production code."; + "messageText" : "Avoid using abort in production code." } ], "parameter": [ @@ -315,7 +315,7 @@ }, { "code": "ARG_TYPE_ANY", - "severity": "WARNING" + "severity": "WARNING", "messageText": "Argument ${variable} is any. Please change to be the correct type." } ], From 770e2deb45331decfd138cf7f2f67c3632d6fca0 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 22:11:39 -0400 Subject: [PATCH 08/20] WriteDumpChecker formatting --- .../cflint/plugins/core/WriteDumpChecker.java | 10 ++-------- .../cflint/tests/WriteDumpChecker/.cflintrc.xml | 1 + .../cflint/tests/WriteDumpChecker/writeDump.cfc | 9 +++++++++ .../WriteDumpChecker/writeDump.expected.txt | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/com/cflint/tests/WriteDumpChecker/.cflintrc.xml create mode 100644 src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.cfc create mode 100644 src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt diff --git a/src/main/java/com/cflint/plugins/core/WriteDumpChecker.java b/src/main/java/com/cflint/plugins/core/WriteDumpChecker.java index 589ee7c3e..63ddcfac4 100644 --- a/src/main/java/com/cflint/plugins/core/WriteDumpChecker.java +++ b/src/main/java/com/cflint/plugins/core/WriteDumpChecker.java @@ -19,18 +19,12 @@ public void expression(final CFExpression expression, final Context context, if(expression instanceof CFFunctionExpression){ final CFFunctionExpression functionExpression = (CFFunctionExpression) expression; - if(functionExpression.getFunctionName().equals("writeDump")){ + if(functionExpression.getFunctionName().equalsIgnoreCase("writeDump")){ final int lineNo = functionExpression.getLine() + context.startLine() - 1; - writeDump(lineNo, context, bugs); + context.addMessage("AVOID_USING_WRITEDUMP", null); } } } - protected void writeDump(final int lineNo, final Context context, final BugList bugs) { - bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("AVOID_USING_WRITEDUMP") - .setSeverity(severity).setFilename(context.getFilename()) - .setMessage("WriteDump statement at line " + lineNo + ". Avoid using writeDump in production code.") - .build()); - } } \ No newline at end of file diff --git a/src/test/resources/com/cflint/tests/WriteDumpChecker/.cflintrc.xml b/src/test/resources/com/cflint/tests/WriteDumpChecker/.cflintrc.xml new file mode 100644 index 000000000..cfd5ea5f1 --- /dev/null +++ b/src/test/resources/com/cflint/tests/WriteDumpChecker/.cflintrc.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.cfc b/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.cfc new file mode 100644 index 000000000..65581d502 --- /dev/null +++ b/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.cfc @@ -0,0 +1,9 @@ + + + + + + writeDump(name); + + + \ No newline at end of file diff --git a/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt b/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt new file mode 100644 index 000000000..45c8635a9 --- /dev/null +++ b/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt @@ -0,0 +1,17 @@ +[ { + "severity" : "INFO", + "id" : "AVOID_USING_WRITEDUMP", + "message" : "AVOID_USING_WRITEDUMP", + "category" : "CFLINT", + "abbrev" : "AU", + "locations" : [ { + "file" : "src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.cfc", + "fileName" : "writeDump.cfc", + "function" : "helloWorld", + "column" : "7", + "line" : "6", + "message" : "Avoid using the writeDump function in production code.", + "variable" : "", + "expression" : "writeDump(name)" + } ] +} ] \ No newline at end of file From 49aef4d5857a221ccd5b24f280cf6f97e88661c6 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 22:17:38 -0400 Subject: [PATCH 09/20] WriteDumpChecker replaced with FunctionXChecker --- .../cflint/plugins/core/WriteDumpChecker.java | 30 ------------------- src/main/resources/cflint.definition.json | 2 +- .../WriteDumpChecker/writeDump.expected.txt | 2 +- 3 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/com/cflint/plugins/core/WriteDumpChecker.java diff --git a/src/main/java/com/cflint/plugins/core/WriteDumpChecker.java b/src/main/java/com/cflint/plugins/core/WriteDumpChecker.java deleted file mode 100644 index 63ddcfac4..000000000 --- a/src/main/java/com/cflint/plugins/core/WriteDumpChecker.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.cflint.plugins.core; - -import com.cflint.BugInfo; -import com.cflint.BugList; -import com.cflint.plugins.CFLintScannerAdapter; -import com.cflint.plugins.Context; - -import cfml.parsing.cfscript.CFExpression; -import cfml.parsing.cfscript.CFFunctionExpression; -import ro.fortsoft.pf4j.Extension; - -@Extension -public class WriteDumpChecker extends CFLintScannerAdapter { - final String severity = "INFO"; - - @Override - public void expression(final CFExpression expression, final Context context, - final BugList bugs) { - - if(expression instanceof CFFunctionExpression){ - final CFFunctionExpression functionExpression = (CFFunctionExpression) expression; - if(functionExpression.getFunctionName().equalsIgnoreCase("writeDump")){ - final int lineNo = functionExpression.getLine() + context.startLine() - 1; - context.addMessage("AVOID_USING_WRITEDUMP", null); - } - } - - } - -} \ No newline at end of file diff --git a/src/main/resources/cflint.definition.json b/src/main/resources/cflint.definition.json index 93e9b8754..a16947634 100644 --- a/src/main/resources/cflint.definition.json +++ b/src/main/resources/cflint.definition.json @@ -422,7 +422,7 @@ }, { "name": "WriteDumpChecker", - "className": "WriteDumpChecker", + "className": "FunctionXChecker", "message": [ { "code": "AVOID_USING_WRITEDUMP", diff --git a/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt b/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt index 45c8635a9..1b38f5de1 100644 --- a/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt +++ b/src/test/resources/com/cflint/tests/WriteDumpChecker/writeDump.expected.txt @@ -11,7 +11,7 @@ "column" : "7", "line" : "6", "message" : "Avoid using the writeDump function in production code.", - "variable" : "", + "variable" : "writeDump", "expression" : "writeDump(name)" } ] } ] \ No newline at end of file From 7050563ec44a0df48def139ae6601c23fc21bd6a Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 22:31:48 -0400 Subject: [PATCH 10/20] structure listeners support context.addMessagE() --- src/main/java/com/cflint/CFLint.java | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/com/cflint/CFLint.java b/src/main/java/com/cflint/CFLint.java index a1155d605..703dc019f 100644 --- a/src/main/java/com/cflint/CFLint.java +++ b/src/main/java/com/cflint/CFLint.java @@ -306,6 +306,10 @@ private void process(final Element elem, final String space, Context context) for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) { try{ structurePlugin.startComponent(context, bugs); + for(final ContextMessage message : context.getMessages()){ + reportRule(elem, null, context, (CFLintScanner)structurePlugin, message); + } + context.getMessages().clear(); }catch(Exception e){ e.printStackTrace(); } @@ -322,6 +326,10 @@ else if (elem.getName().equalsIgnoreCase("cffunction")) { for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) { try{ structurePlugin.startFunction(context, bugs); + for(final ContextMessage message : context.getMessages()){ + reportRule(elem, null, context, (CFLintScanner)structurePlugin, message); + } + context.getMessages().clear(); }catch(Exception e){ e.printStackTrace(); } @@ -413,6 +421,11 @@ else if (elem.getName().equalsIgnoreCase("cffunction")) { for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) { try{ structurePlugin.endFunction(context, bugs); + for(final ContextMessage message : context.getMessages()){ + reportRule(elem, null, context, (CFLintScanner)structurePlugin, message); + } + context.getMessages().clear(); + }catch(Exception e){ e.printStackTrace(); } @@ -424,6 +437,10 @@ else if (elem.getName().equalsIgnoreCase("cffunction")) { for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) { try{ structurePlugin.endComponent(context, bugs); + for(final ContextMessage message : context.getMessages()){ + reportRule(elem, null, context, (CFLintScanner)structurePlugin, message); + } + context.getMessages().clear(); }catch(Exception e){ e.printStackTrace(); } @@ -491,6 +508,10 @@ private void process(final CFScriptStatement expression, final String filename, for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) { try{ structurePlugin.startComponent(context, bugs); + for(final ContextMessage message : context.getMessages()){ + reportRule(elem, null, context, (CFLintScanner)structurePlugin, message); + } + context.getMessages().clear(); }catch(Exception e){ e.printStackTrace(); } @@ -508,6 +529,10 @@ else if (expression instanceof CFFuncDeclStatement) { for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) { try{ structurePlugin.startFunction(context, bugs); + for(final ContextMessage message : context.getMessages()){ + reportRule(elem, null, context, (CFLintScanner)structurePlugin, message); + } + context.getMessages().clear(); }catch(Exception e){ e.printStackTrace(); } @@ -542,6 +567,10 @@ else if (expression instanceof CFFuncDeclStatement) { for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) { try{ structurePlugin.endComponent(context, bugs); + for(final ContextMessage message : context.getMessages()){ + reportRule(elem, null, context, (CFLintScanner)structurePlugin, message); + } + context.getMessages().clear(); }catch(Exception e){ e.printStackTrace(); } @@ -585,6 +614,10 @@ else if (expression instanceof CFFuncDeclStatement) { for (final CFLintStructureListener structurePlugin : getStructureListeners(extensions)) { try{ structurePlugin.endFunction(context, bugs); + for(final ContextMessage message : context.getMessages()){ + reportRule(elem, null, context, (CFLintScanner)structurePlugin, message); + } + context.getMessages().clear(); }catch(Exception e){ e.printStackTrace(); } From d0a80c067c7603de219992b92585333fe7046737 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 22:32:05 -0400 Subject: [PATCH 11/20] cleanup UnusedArgumentChecker --- .../plugins/core/UnusedArgumentChecker.java | 23 ++++--------------- src/main/resources/cflint.definition.json | 1 + src/main/resources/cflint.definition.xml | 1 + 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java b/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java index 1ea0ee471..5c824b3f0 100644 --- a/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java +++ b/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java @@ -1,12 +1,9 @@ package com.cflint.plugins.core; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.List; +import java.util.LinkedHashMap; import java.util.Map; -import com.cflint.BugInfo; import com.cflint.BugList; import com.cflint.plugins.CFLintScannerAdapter; import com.cflint.plugins.Context; @@ -20,9 +17,9 @@ import net.htmlparser.jericho.Element; public class UnusedArgumentChecker extends CFLintScannerAdapter { - final String severity = "INFO"; - protected Map methodArguments = new HashMap(); + //Use linked hash map to preserve the order of the elements. + protected Map methodArguments = new LinkedHashMap(); protected Map argumentLineNo = new HashMap(); @Override @@ -83,25 +80,13 @@ public void startFunction(Context context, BugList bugs) { @Override public void endFunction(Context context, BugList bugs) { // sort by line number - final List presortbugs = new ArrayList(); for (Map.Entry method : methodArguments.entrySet()) { Boolean used = method.getValue(); if (!used) { final String name = method.getKey(); - final Integer lineNo = argumentLineNo.get(name); - presortbugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("UNUSED_METHOD_ARGUMENT") - .setSeverity(severity).setFilename(context.getFilename()) - .setMessage("Argument " + name + " is not used in function " + context.getFunctionName() + ", consider removing it.") - .setFunction(context.getFunctionName()) - .setVariable(name) - .build()); + context.addMessage("UNUSED_METHOD_ARGUMENT", name); } } - // Sort the bugs by line/col before adding to the list of bugs. - Collections.sort(presortbugs); - for(BugInfo bugInfo : presortbugs ){ - bugs.add(bugInfo); - } } } diff --git a/src/main/resources/cflint.definition.json b/src/main/resources/cflint.definition.json index a16947634..7fb749732 100644 --- a/src/main/resources/cflint.definition.json +++ b/src/main/resources/cflint.definition.json @@ -772,6 +772,7 @@ "message": [ { "code": "UNUSED_METHOD_ARGUMENT", + "messageText": "Argument ${variable} is not used in function, consider removing it.", "severity": "INFO" } ], diff --git a/src/main/resources/cflint.definition.xml b/src/main/resources/cflint.definition.xml index f52081e46..a80de8123 100644 --- a/src/main/resources/cflint.definition.xml +++ b/src/main/resources/cflint.definition.xml @@ -355,6 +355,7 @@ INFO + Argument ${variable} is not used in function, consider removing it. From b359daeebde7174372630d9cd1f5c6d1df4a8c64 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 11 May 2016 22:49:52 -0400 Subject: [PATCH 12/20] support line numbers on Context.addMessage(). --- src/main/java/com/cflint/CFLint.java | 7 ++++++- src/main/java/com/cflint/plugins/Context.java | 11 +++++++++++ .../cflint/plugins/core/UnusedArgumentChecker.java | 2 +- .../java/com/cflint/TestUnusedArgumentChecker.java | 1 + .../UnusedArgument/UnusedArgument_152b.expected.txt | 4 ++-- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cflint/CFLint.java b/src/main/java/com/cflint/CFLint.java index 703dc019f..6b433d643 100644 --- a/src/main/java/com/cflint/CFLint.java +++ b/src/main/java/com/cflint/CFLint.java @@ -866,7 +866,12 @@ else if(elem != null){ if (expression instanceof CFExpression){ bugs.add(bldr.build((CFExpression)expression, elem)); }else{ - bugs.add(bldr.build((CFParsedStatement)expression, elem)); + BugInfo bug = bldr.build((CFParsedStatement)expression, elem); + if(msg.getLine() != null){ + bug.setLine(msg.getLine()); + bug.setColumn(0); + } + bugs.add(bug); } } diff --git a/src/main/java/com/cflint/plugins/Context.java b/src/main/java/com/cflint/plugins/Context.java index a57f3fcea..da2a45f64 100644 --- a/src/main/java/com/cflint/plugins/Context.java +++ b/src/main/java/com/cflint/plugins/Context.java @@ -119,22 +119,33 @@ public List getMessages() { public void addMessage(String messageCode, String variable) { messages.add(new ContextMessage(messageCode,variable)); } + public void addMessage(String messageCode, String variable, Integer line) { + messages.add(new ContextMessage(messageCode,variable,line)); + } public static class ContextMessage{ String messageCode; String variable; + Integer line; public ContextMessage(String messageCode, String variable) { super(); this.messageCode = messageCode; this.variable = variable; } + public ContextMessage(String messageCode, String variable,Integer line) { + this(messageCode,variable); + this.line = line; + } public String getMessageCode() { return messageCode; } public String getVariable() { return variable; } + public Integer getLine() { + return line; + } } public Context subContext(final Element elem){ diff --git a/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java b/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java index 5c824b3f0..f7cbad067 100644 --- a/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java +++ b/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java @@ -84,7 +84,7 @@ public void endFunction(Context context, BugList bugs) { Boolean used = method.getValue(); if (!used) { final String name = method.getKey(); - context.addMessage("UNUSED_METHOD_ARGUMENT", name); + context.addMessage("UNUSED_METHOD_ARGUMENT", name,argumentLineNo.get(name)); } } } diff --git a/src/test/java/com/cflint/TestUnusedArgumentChecker.java b/src/test/java/com/cflint/TestUnusedArgumentChecker.java index 8c2fc18b1..4aca325dd 100644 --- a/src/test/java/com/cflint/TestUnusedArgumentChecker.java +++ b/src/test/java/com/cflint/TestUnusedArgumentChecker.java @@ -28,6 +28,7 @@ public void setUp() { conf.getRules().add(pluginRule); final PluginMessage pluginMessage = new PluginMessage("UNUSED_METHOD_ARGUMENT"); pluginMessage.setSeverity("INFO"); + pluginRule.getMessages().add(pluginMessage); cfBugs = new CFLint(conf, new UnusedArgumentChecker()); } diff --git a/src/test/resources/com/cflint/tests/UnusedArgument/UnusedArgument_152b.expected.txt b/src/test/resources/com/cflint/tests/UnusedArgument/UnusedArgument_152b.expected.txt index 3e871b878..605828ecb 100644 --- a/src/test/resources/com/cflint/tests/UnusedArgument/UnusedArgument_152b.expected.txt +++ b/src/test/resources/com/cflint/tests/UnusedArgument/UnusedArgument_152b.expected.txt @@ -10,8 +10,8 @@ "function" : "helloWorld", "column" : "0", "line" : "6", - "message" : "Argument xyzzy is not used in function helloWorld, consider removing it.", + "message" : "Argument xyzzy is not used in function, consider removing it.", "variable" : "xyzzy", - "expression" : "" + "expression" : "/r/n /r/n Date: Sat, 14 May 2016 18:06:45 -0600 Subject: [PATCH 13/20] adds some null checks and whatnot --- .../com/cflint/plugins/core/ArgumentNameChecker.java | 11 +++++++++-- .../cflint/plugins/core/SimpleComplexityChecker.java | 6 ++++++ .../cflint/plugins/core/UnusedArgumentChecker.java | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cflint/plugins/core/ArgumentNameChecker.java b/src/main/java/com/cflint/plugins/core/ArgumentNameChecker.java index 7975892a6..5bf42b73d 100644 --- a/src/main/java/com/cflint/plugins/core/ArgumentNameChecker.java +++ b/src/main/java/com/cflint/plugins/core/ArgumentNameChecker.java @@ -33,8 +33,15 @@ public void element(final Element element, final Context context, final BugList if (element.getName().equals("cfargument")) { final int lineNo = context.startLine(); final String name = element.getAttributeValue("name"); - - checkNameForBugs(name, context.getFilename(), context.getFunctionName(), lineNo, bugs); + if(name != null && name.length() > 0) { + checkNameForBugs(name, context.getFilename(), context.getFunctionName(), lineNo, bugs); + } else { + bugs.add(new BugInfo.BugInfoBuilder().setLine(lineNo).setMessageCode("ARGUMENT_INVALID_NAME") + .setSeverity("ERROR").setFilename(context.getFilename()).setFunction(context.getFunctionName()) + .setMessage(ARGUMENT + " is missing a name.") + .setVariable("") + .build()); + } } } diff --git a/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java b/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java index 74ce67283..7b127e94d 100644 --- a/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java +++ b/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java @@ -33,6 +33,12 @@ public void expression(final CFScriptStatement expression, final Context context functionLineNo = function.getLine(); complexity = 0; alreadyTooComplex = false; + } + else if (expression == null){ + bugs.add(new BugInfo.BugInfoBuilder().setLine(context.startLine()).setMessageCode("PARSE_ERROR") + .setSeverity("ERROR").setFilename(context.getFilename()).setFunction(context.getFunctionName()) + .setMessage("Unable to parse expression.") + .build()); } // Not using instanceof to avoid double counting else if (expression.getClass().equals(CFIfStatement.class) || diff --git a/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java b/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java index 1ea0ee471..fa0e3e185 100644 --- a/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java +++ b/src/main/java/com/cflint/plugins/core/UnusedArgumentChecker.java @@ -28,7 +28,8 @@ public class UnusedArgumentChecker extends CFLintScannerAdapter { @Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals("cfargument")) { - final String name = element.getAttributeValue("name").toLowerCase(); + final String name = element.getAttributeValue("name") != null ? + element.getAttributeValue("name").toLowerCase() : ""; methodArguments.put(name, false); setArgumentLineNo(name, context.startLine()); } From 97cf583589d42a89d0a6247a6300dafe0e6c57b4 Mon Sep 17 00:00:00 2001 From: denuno Date: Sat, 14 May 2016 18:14:58 -0600 Subject: [PATCH 14/20] bump version and pull in latest cfml.parsing --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 6b39618ba..30d82e2f4 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.github.cflint CFLint - 0.7.1 + 0.7.2 CFLint @@ -51,18 +51,18 @@ com.github.cfparser cfparser - 2.2.2 + 2.2.3 pom com.github.cfparser cfml.parsing - 2.2.2 + 2.2.3 com.github.cfparser cfml.dictionary - 2.2.2 + 2.2.3 junit From 9466b1d89750c0cbe12c398eab749ac6e587f45d Mon Sep 17 00:00:00 2001 From: denuno Date: Sat, 14 May 2016 18:29:37 -0600 Subject: [PATCH 15/20] fix test that was expecting 'var somevar.somevar=something' to be a parse error, since it isn't anymore --- src/test/java/com/cflint/TestCFBugs_ParseError.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/cflint/TestCFBugs_ParseError.java b/src/test/java/com/cflint/TestCFBugs_ParseError.java index 0f4008c2a..80374bfab 100644 --- a/src/test/java/com/cflint/TestCFBugs_ParseError.java +++ b/src/test/java/com/cflint/TestCFBugs_ParseError.java @@ -33,11 +33,9 @@ public void testSimpleCFSET() throws ParseException, IOException{ "\r\n" + ""; cfBugs.process(cfcSrc,"test"); - List result = cfBugs.getBugs().getBugList().values().iterator().next(); + List result = cfBugs.getBugs().getFlatBugList(); System.out.println(result); - assertEquals(1,result.size()); - assertEquals("PARSE_ERROR",result.get(0).getMessageCode()); - assertEquals(4,result.get(0).getLine()); + assertEquals(0,result.size()); } @Test From fb8cf55b7adf6966bbaebde2d3122606a777c0ec Mon Sep 17 00:00:00 2001 From: denuno Date: Sat, 14 May 2016 19:14:23 -0600 Subject: [PATCH 16/20] bump versions for gradle --- build.gradle | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 99c78be8a..ae3d8ea2f 100644 --- a/build.gradle +++ b/build.gradle @@ -32,11 +32,12 @@ targetCompatibility = 1.7 repositories { maven { url "https://oss.sonatype.org/content/repositories/snapshots" } maven { url "http://repo.maven.apache.org/maven2" } + maven { url "http://cfmlprojects.org/artifacts" } } dependencies { - compile group: 'com.github.cfparser', name: 'cfparser', version:'2.2.1' - compile group: 'com.github.cfparser', name: 'cfml.parsing', version:'2.2.1' - compile group: 'com.github.cfparser', name: 'cfml.dictionary', version:'2.2.1' + compile group: 'com.github.cfparser', name: 'cfparser', version:'2.2.3' + compile group: 'com.github.cfparser', name: 'cfml.parsing', version:'2.2.3' + compile group: 'com.github.cfparser', name: 'cfml.dictionary', version:'2.2.3' compile group: 'junit', name: 'junit', version:'4.12' compile group: 'org.jdom', name: 'jdom', version:'1.1.3' compile group: 'org.antlr', name: 'antlr4-runtime', version:'4.5.2-1' From 044015c4c1220d71349bb97f3116c53f3da9de67 Mon Sep 17 00:00:00 2001 From: denuno Date: Sat, 14 May 2016 20:41:39 -0600 Subject: [PATCH 17/20] fix error that happens when variable name is a $ --- src/main/java/com/cflint/BugInfo.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cflint/BugInfo.java b/src/main/java/com/cflint/BugInfo.java index 47cad5b2d..78b8f4c94 100644 --- a/src/main/java/com/cflint/BugInfo.java +++ b/src/main/java/com/cflint/BugInfo.java @@ -144,7 +144,8 @@ private final String notNull(String in){ private void doMessageText(final Element elem) { String message = notNull(bugInfo.getMessage()); - message = message.replaceAll("\\$\\{variable\\}",notNull(bugInfo.getVariable())); + String variable = notNull(bugInfo.getVariable()); + message = message.replace("${variable}",variable); if(message.contains("{tag}") && elem != null){ message = message.replaceAll("\\$\\{tag\\}",notNull(elem.getName())); } From e2ced9c4bcbbe8885dfc14980d697d873834ba7f Mon Sep 17 00:00:00 2001 From: denuno Date: Sat, 14 May 2016 20:41:39 -0600 Subject: [PATCH 18/20] fix error that happens when variable name is a $ --- src/main/java/com/cflint/BugInfo.java | 3 ++- .../com/cflint/plugins/core/SimpleComplexityChecker.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cflint/BugInfo.java b/src/main/java/com/cflint/BugInfo.java index 47cad5b2d..78b8f4c94 100644 --- a/src/main/java/com/cflint/BugInfo.java +++ b/src/main/java/com/cflint/BugInfo.java @@ -144,7 +144,8 @@ private final String notNull(String in){ private void doMessageText(final Element elem) { String message = notNull(bugInfo.getMessage()); - message = message.replaceAll("\\$\\{variable\\}",notNull(bugInfo.getVariable())); + String variable = notNull(bugInfo.getVariable()); + message = message.replace("${variable}",variable); if(message.contains("{tag}") && elem != null){ message = message.replaceAll("\\$\\{tag\\}",notNull(elem.getName())); } diff --git a/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java b/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java index 7b127e94d..6b786623f 100644 --- a/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java +++ b/src/main/java/com/cflint/plugins/core/SimpleComplexityChecker.java @@ -35,9 +35,9 @@ public void expression(final CFScriptStatement expression, final Context context alreadyTooComplex = false; } else if (expression == null){ - bugs.add(new BugInfo.BugInfoBuilder().setLine(context.startLine()).setMessageCode("PARSE_ERROR") - .setSeverity("ERROR").setFilename(context.getFilename()).setFunction(context.getFunctionName()) - .setMessage("Unable to parse expression.") + bugs.add(new BugInfo.BugInfoBuilder().setLine(context.startLine()).setMessageCode("PARSE_NOTHING") + .setSeverity("WARNING").setFilename(context.getFilename()).setFunction(context.getFunctionName()) + .setMessage("Nothing to parse") .build()); } // Not using instanceof to avoid double counting From 6364c5527b65737ae33105a502fb762b279aed58 Mon Sep 17 00:00:00 2001 From: denuno Date: Fri, 20 May 2016 11:00:18 -0600 Subject: [PATCH 19/20] bump version --- build.gradle | 6 +++--- pom.xml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index ae3d8ea2f..6869621ae 100644 --- a/build.gradle +++ b/build.gradle @@ -35,9 +35,9 @@ repositories { maven { url "http://cfmlprojects.org/artifacts" } } dependencies { - compile group: 'com.github.cfparser', name: 'cfparser', version:'2.2.3' - compile group: 'com.github.cfparser', name: 'cfml.parsing', version:'2.2.3' - compile group: 'com.github.cfparser', name: 'cfml.dictionary', version:'2.2.3' + compile group: 'com.github.cfparser', name: 'cfparser', version:'2.2.4' + compile group: 'com.github.cfparser', name: 'cfml.parsing', version:'2.2.4' + compile group: 'com.github.cfparser', name: 'cfml.dictionary', version:'2.2.4' compile group: 'junit', name: 'junit', version:'4.12' compile group: 'org.jdom', name: 'jdom', version:'1.1.3' compile group: 'org.antlr', name: 'antlr4-runtime', version:'4.5.2-1' diff --git a/pom.xml b/pom.xml index 30d82e2f4..7654e826e 100644 --- a/pom.xml +++ b/pom.xml @@ -51,18 +51,18 @@ com.github.cfparser cfparser - 2.2.3 + 2.2.5 pom com.github.cfparser cfml.parsing - 2.2.3 + 2.2.5 com.github.cfparser cfml.dictionary - 2.2.3 + 2.2.5 junit From 8f74474ffd532a2a54e4c796d5f2c8147cb06bbb Mon Sep 17 00:00:00 2001 From: denuno Date: Sat, 21 May 2016 17:46:54 -0600 Subject: [PATCH 20/20] bumped versions cfparser --- build.gradle | 6 +++--- pom.xml | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 6869621ae..5f6d46e7f 100644 --- a/build.gradle +++ b/build.gradle @@ -35,9 +35,9 @@ repositories { maven { url "http://cfmlprojects.org/artifacts" } } dependencies { - compile group: 'com.github.cfparser', name: 'cfparser', version:'2.2.4' - compile group: 'com.github.cfparser', name: 'cfml.parsing', version:'2.2.4' - compile group: 'com.github.cfparser', name: 'cfml.dictionary', version:'2.2.4' + compile group: 'com.github.cfparser', name: 'cfparser', version:'2.2.6' + compile group: 'com.github.cfparser', name: 'cfml.parsing', version:'2.2.6' + compile group: 'com.github.cfparser', name: 'cfml.dictionary', version:'2.2.6' compile group: 'junit', name: 'junit', version:'4.12' compile group: 'org.jdom', name: 'jdom', version:'1.1.3' compile group: 'org.antlr', name: 'antlr4-runtime', version:'4.5.2-1' diff --git a/pom.xml b/pom.xml index 7654e826e..f3846ce81 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,12 @@ cfparser https://github.com/jjames967 + + Denny Valliant + valliantster@gmail.com + cfparser + https://github.com/denuno + @@ -35,8 +41,16 @@ git@github.com:cflint/CFLint.git + + + cfmlprojects + cfmlprojects + http://cfmlprojects.org/artifacts + + + - + The New BSD License http://www.opensource.org/licenses/bsd-license.html repo @@ -57,12 +71,12 @@ com.github.cfparser cfml.parsing - 2.2.5 + 2.2.6 com.github.cfparser cfml.dictionary - 2.2.5 + 2.2.6 junit