From 0330cc74a4f2d2ad77360892809a97bde85aeb2d Mon Sep 17 00:00:00 2001
From: Nico Bihan <42357253+nbihan-mediware@users.noreply.github.com>
Date: Fri, 8 Feb 2019 17:05:10 -0600
Subject: [PATCH] Upgrade to CFlint 1.4.1 (#5)
---
pom.xml | 4 +-
.../plugin/coldfusion/ColdFusionSensor.java | 17 ++--
.../sonar/plugin/coldfusion/rules.xml | 89 +++++++++----------
.../com/wellsky/ColdfusionSensorTest.java | 13 +--
4 files changed, 65 insertions(+), 58 deletions(-)
diff --git a/pom.xml b/pom.xml
index 2b9b5c1..4221eca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.stepstone.sonar.plugin
sonar-coldfusion-plugin
sonar-plugin
- 1.6.8-SNAPSHOT
+ 1.7.0-SNAPSHOT
SonarQube Coldfusion Analyzer
Enables scanning of ColdFusion source files
@@ -40,7 +40,7 @@
1.8
1.8
6.7.6
- 1.2.3
+ 1.4.1
diff --git a/src/main/java/com/stepstone/sonar/plugin/coldfusion/ColdFusionSensor.java b/src/main/java/com/stepstone/sonar/plugin/coldfusion/ColdFusionSensor.java
index d0da4cd..61c73d2 100644
--- a/src/main/java/com/stepstone/sonar/plugin/coldfusion/ColdFusionSensor.java
+++ b/src/main/java/com/stepstone/sonar/plugin/coldfusion/ColdFusionSensor.java
@@ -26,7 +26,6 @@
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Metric;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -39,7 +38,10 @@
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
public class ColdFusionSensor implements Sensor {
@@ -75,9 +77,12 @@ public void execute(SensorContext context) {
private void analyze(SensorContext context) throws IOException, XMLStreamException {
File configFile = generateCflintConfig();
- new CFLintAnalyzer(context).analyze(configFile);
- //when analysis is done we delete the created file
- deleteFile(configFile);
+ try {
+ new CFLintAnalyzer(context).analyze(configFile);
+ } finally {
+ //when analysis is done we delete the created file
+ deleteFile(configFile);
+ }
}
private File generateCflintConfig() throws IOException, XMLStreamException {
@@ -105,7 +110,7 @@ private void importResults(SensorContext sensorContext) throws IOException {
private void measureProcessor(SensorContext context) {
LOGGER.info("Starting measure processor");
- ExecutorService executorService = Executors.newFixedThreadPool(2);
+ ExecutorService executorService = Executors.newSingleThreadExecutor();
List> callableTasks = new ArrayList<>();
for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(ColdFusionPlugin.LANGUAGE_KEY))) {
diff --git a/src/main/resources/com/stepstone/sonar/plugin/coldfusion/rules.xml b/src/main/resources/com/stepstone/sonar/plugin/coldfusion/rules.xml
index 94799a0..c69fbc0 100644
--- a/src/main/resources/com/stepstone/sonar/plugin/coldfusion/rules.xml
+++ b/src/main/resources/com/stepstone/sonar/plugin/coldfusion/rules.xml
@@ -13,7 +13,7 @@
Variable declared in both var and argument scopes.
MAJOR
SINGLE
-
]]>
+ Variable should not be declared in both local and argument scopes. ]]>
bug
@@ -21,7 +21,7 @@
Variable referenced in local and argument scopes.
MAJOR
SINGLE
- ]]>
+ Variable should not be referenced in local and argument scope. ]]>
bug
@@ -29,14 +29,14 @@
Missing default switch statement.
MAJOR
SINGLE
- ]]>
+ Not having a Default statement defined for a switch could pose potential issues. ]]>
GLOBAL_VAR
Global variable exists.
CRITICAL
SINGLE
- ]]>
+ Identifier is global. Referencing in a CFC or function should be avoided. ]]>
bug
@@ -44,29 +44,29 @@
Nested cfoutput with cfquery tag.
MINOR
SINGLE
- ]]>
+ Nested CFOutput, outer CFOutput has @query
. ]]>
OUTPUT_ATTR
Tag should have output='false'.
MAJOR
SINGLE
- ]]>
+
should have @output='false' ]]>
QUERYPARAM_REQ
SetSql() statement should use .addParam().
BLOCKER
SINGLE
- ]]>
+ setSql() statement should use .addParam() instead of #'s name="variable" ]]>
security
CFQUERYPARAM_REQ
- cfquery should use
+ cfquery should use cfqueryparam
BLOCKER
SINGLE
- ]]>
+
should use
for variable 'variable'. ]]>
security
@@ -82,7 +82,7 @@
Variable is not declared with a var statement.
CRITICAL
SINGLE
- ]]>
+ Variable is not declared with a var statement. ]]>
bug
@@ -90,7 +90,7 @@
Avoid use of cfdump tags.
MAJOR
SINGLE
- ]]>
+ Avoid leaving
tags in committed code. Debug information should be omitted from release code ]]>
security
@@ -98,7 +98,7 @@
Avoid use of cfexecute tags.
CRITICAL
SINGLE
- ]]>
+ Avoid leaving
tags in committed code. CFexecute can be used as an attack vector and is slow. ]]>
security
@@ -107,14 +107,14 @@
MAJOR
SINGLE
Avoid using the isDate()
built-in function. It is too permissive. Use isValid()
instead. ]]>
- security
+ bug
AVOID_USING_CFABORT_TAG
Avoid use of cfabort tags.
CRITICAL
SINGLE
- ]]>
+ Avoid leaving
tags in committed code. ]]>
bug
@@ -122,7 +122,7 @@
Avoid use of abort statements.
CRITICAL
SINGLE
- ]]>
+ Avoid using abort in production code. ]]>
bug
@@ -130,7 +130,7 @@
Avoid use of cfinsert tags.
CRITICAL
SINGLE
- ]]>
+ Avoid using
tags. Use cfquery and cfstoredproc instead. ]]>
bug
@@ -146,7 +146,7 @@
Avoid use of cfupdate tags.
MAJOR
SINGLE
- ]]>
+ Avoid using
tags. Use cfquery and cfstoredproc instead. ]]>
bug
@@ -154,7 +154,7 @@
Avoid use of cfinclude tags.
CRITICAL
SINGLE
- ]]>
+ Avoid using
tags. Use components instead. ]]>
@@ -183,14 +183,14 @@
Argument is missing a hint.
MINOR
SINGLE
- Use JavaDoc style annotations on cfscript functions. ]]>
+ Argument is missing a hint. Use javadoc style annotations on cfscript functions. ]]>
ARG_TYPE_MISSING
Component is missing a type.
BLOCKER
SINGLE
- ]]>
+ Argument variable is missing a type. ]]>
bug
@@ -206,14 +206,14 @@
Method is too long.
MAJOR
SINGLE
- ]]>
+ Function should be fewer than 100 lines. ]]>
EXCESSIVE_COMPONENT_LENGTH
Component is too long.
MAJOR
SINGLE
- ]]>
+ Component should be fewer than 500 lines. ]]>
FUNCTION_TYPE_MISSING
@@ -236,21 +236,21 @@
Function has too many arguments.
MAJOR
SINGLE
- ]]>
+ Function has too many arguments. Should be fewer than 10. ]]>
EXCESSIVE_FUNCTIONS
Too many functions.
- MAJOR
+ MINOR
SINGLE
- ]]>
+ Component has too many functions. Should be fewer than 10. ]]>
FUNCTION_TOO_COMPLEX
Function is too complex.
CRITICAL
SINGLE
- ]]>
+ Function is too complex. Consider breaking the function into smaller functions. ]]>
AVOID_USING_WRITEDUMP
@@ -272,7 +272,7 @@
Avoid use of isdebugmode statements.
MINOR
SINGLE
- ]]>
+ Avoid using the IsDebugMode function in production code. ]]>
AVOID_USING_ARRAYNEW
@@ -293,14 +293,14 @@
Checking boolean expression explicitly.
MAJOR
SINGLE
- ]]>
+ Explicit check of boolean expression is not needed. ]]>
VAR_INVALID_NAME
Variable has invalid name.
CRITICAL
SINGLE
- ]]>
+ Variable is not a valid name. Please use camelCase or underscores. ]]>
bug
@@ -308,7 +308,7 @@
Variable name is allcaps.
MINOR
SINGLE
- ]]>
+ Variable should not be upper case. ]]>
VAR_TOO_SHORT
@@ -343,7 +343,7 @@
Variable name has prefix or postfix.
MINOR
SINGLE
- ]]>
+ Variable has prefix or postfix variable and could be named better. ]]>
ARGUMENT_MISSING_NAME
@@ -357,7 +357,7 @@
Argument has invalid name.
CRITICAL
SINGLE
- ]]>
+ Please use camelCase or underscores. ]]>
bug
@@ -493,21 +493,21 @@
Component name looks temporary.
MAJOR
SINGLE
- ]]>
+ Component name component could be named better. ]]>
COMPONENT_HAS_PREFIX_OR_POSTFIX
Component name has prefix or postfix.
MINOR
SINGLE
- ]]>
+ Component name has prefix or postfix and could be named better. ]]>
FILE_SHOULD_START_WITH_LOWERCASE
CFM File starts with upper case.
MINOR
SINGLE
- ]]>
+ Filename starts with an upper case letter. Only components (.cfc files) should start with an upper case letter. ]]>
AVOID_USING_CREATEOBJECT
@@ -543,7 +543,7 @@
Using comparison where assignment was probably meant.
CRITICAL
SINGLE
- ]]>
+ Comparing instead of Assigning ]]>
bug
@@ -559,7 +559,7 @@
Variable scope name is allcaps.
MINOR
SINGLE
- ]]>
+ Scope variable should not be upper case. ]]>
AVOID_USING_CFSETTING_DEBUG
@@ -569,14 +569,6 @@
]]>
security
-
- MISSING_SEMI
- No semicolon!
- CRITICAL
- SINGLE
- ]]>
- bug
-
UNQUOTED_STRUCT_KEY
Unquoted struct key
@@ -650,4 +642,11 @@
]]>
bug
+
+ STRUCT_ARRAY_NOTATION
+ Use array notation
+ MAJOR
+ SINGLE
+ Unquoted struct key variable is not case-sensitive. Using array notation is recommended. ]]>
+
diff --git a/src/test/java/com/wellsky/ColdfusionSensorTest.java b/src/test/java/com/wellsky/ColdfusionSensorTest.java
index 7489adf..555c53e 100644
--- a/src/test/java/com/wellsky/ColdfusionSensorTest.java
+++ b/src/test/java/com/wellsky/ColdfusionSensorTest.java
@@ -66,13 +66,16 @@ public void testBasicCFMAnalysis() {
sensor.execute(context);
Integer nloc = 0;
- for (InputFile inputFile : context.fileSystem().inputFiles()) {
- Measure measureNloc = context.measure(inputFile.key(),CoreMetrics.NCLOC);
- if(measureNloc!=null) {
- nloc += measureNloc.value();
- }
+ Integer comments = 0;
+ for (InputFile o : context.fileSystem().inputFiles()) {
+ Measure measureNloc = context.measure(o.key(),CoreMetrics.NCLOC.key());
+ Measure measureComment = context.measure(o.key(),CoreMetrics.COMMENT_LINES.key());
+ nloc+=measureNloc.value();
+ comments+=measureComment.value();
}
assertThat(nloc).isEqualTo(36);
+ assertThat(comments).isEqualTo(9);
+
}
private void addFilesToFs() {