Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This pull adds some null checks and bumps the cfml.parsing dependencies #168

Merged
merged 22 commits into from
May 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.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'
Expand Down
24 changes: 19 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.cflint</groupId>
<artifactId>CFLint</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>

<name>CFLint</name>
<description>
Expand All @@ -27,6 +27,12 @@
<organization>cfparser</organization>
<organizationUrl>https://github.com/jjames967</organizationUrl>
</developer>
<developer>
<name>Denny Valliant</name>
<email>[email protected]</email>
<organization>cfparser</organization>
<organizationUrl>https://github.com/denuno</organizationUrl>
</developer>
</developers>

<scm>
Expand All @@ -35,8 +41,16 @@
<url>[email protected]:cflint/CFLint.git</url>
</scm>

<repositories>
<repository>
<id>cfmlprojects</id>
<name>cfmlprojects</name>
<url>http://cfmlprojects.org/artifacts</url>
</repository>
</repositories>

<licenses>
<license>
<license>
<name>The New BSD License</name>
<url>http://www.opensource.org/licenses/bsd-license.html</url>
<distribution>repo</distribution>
Expand All @@ -51,18 +65,18 @@
<dependency>
<groupId>com.github.cfparser</groupId>
<artifactId>cfparser</artifactId>
<version>2.2.2</version>
<version>2.2.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.github.cfparser</groupId>
<artifactId>cfml.parsing</artifactId>
<version>2.2.2</version>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>com.github.cfparser</groupId>
<artifactId>cfml.dictionary</artifactId>
<version>2.2.2</version>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/cflint/BugInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
40 changes: 39 additions & 1 deletion src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -833,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);
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/cflint/plugins/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,33 @@ public List<ContextMessage> 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){
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/com/cflint/plugins/core/AbortChecker.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,11 +15,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);
}
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/cflint/plugins/core/ArgDefChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/com/cflint/plugins/core/ArgHintChecker.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package com.cflint.plugins.core;

import com.cflint.BugInfo;
import com.cflint.BugList;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;

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) {
if (element.getName().equals("cfargument")) {
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);
}
}
}
Expand Down
32 changes: 5 additions & 27 deletions src/main/java/com/cflint/plugins/core/ArgTypeChecker.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
}
Expand All @@ -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);
}
}
}

}
}
11 changes: 9 additions & 2 deletions src/main/java/com/cflint/plugins/core/ArgumentNameChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

Expand Down
Loading