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

move CF constants into own file #454

Merged
merged 8 commits into from
Aug 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
409 changes: 409 additions & 0 deletions src/main/java/com/cflint/CF.java

Large diffs are not rendered by default.

73 changes: 36 additions & 37 deletions src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ public void process(final String src, final String filename) throws ParseExcepti
* @return
*/
private boolean isComponentOrInterfaceScript(final String src, final List<Element> elements) {
return (src.contains("component")
&& (elements.isEmpty() || elements.get(0).getBegin() > src.indexOf("component")))
|| (src.contains("interface")
&& (elements.isEmpty() || elements.get(0).getBegin() > src.indexOf("interface")));
return (src.contains(CF.COMPONENT)
&& (elements.isEmpty() || elements.get(0).getBegin() > src.indexOf(CF.COMPONENT)))
|| (src.contains(CF.INTERFACE)
&& (elements.isEmpty() || elements.get(0).getBegin() > src.indexOf(CF.INTERFACE)));
}

protected ParserTag getFirstTagQuietly(final CFMLSource cfmlSource) {
Expand All @@ -335,7 +335,7 @@ public void processStack(final List<Element> elements, final String space, final
final CFIdentifier functionName) throws ParseException, IOException {
Element commentElement = null;
for (final Element elem : elements) {
if (elem.getName().equals("!---")) {
if (elem.getName().equals(CF.COMMENT)) {
commentElement = elem;
} else {
final Context context = new Context(filename, elem, functionName, false, handler);
Expand All @@ -353,7 +353,7 @@ public void processStack(final List<Element> elements, final String space, final
throws ParseException, IOException {
Element commentElement = null;
for (final Element elem : elements) {
if (elem.getName().equals("!---")) {
if (elem.getName().equals(CF.COMMENT)) {
commentElement = elem;
} else {
final Context subContext = context.subContext(elem);
Expand All @@ -377,33 +377,33 @@ private void process(final Element elem, final String space, final Context conte
}
try {
currentElement = elem;
if (elem.getName().equalsIgnoreCase("cfcomponent")) {
if (elem.getName().equalsIgnoreCase(CF.CFCOMPONENT)) {
final Context componentContext = context.subContext(elem);
componentContext.setInComponent(true);
componentContext.setComponentName(elem.getAttributeValue("displayname"));
componentContext.setComponentName(elem.getAttributeValue(CF.DISPLAYNAME));
componentContext.setContextType(ContextType.COMPONENT);
handler.push("component");
handler.push(CF.COMPONENT);
doStructureStart(elem, componentContext, CFCompDeclStatement.class);
} else if (elem.getName().equalsIgnoreCase("cffunction")) {
} else if (elem.getName().equalsIgnoreCase(CF.CFFUNCTION)) {
final Context functionContext = context.subContext(elem);
functionContext.setFunctionName(elem.getAttributeValue("name"));
functionContext.setFunctionName(elem.getAttributeValue(CF.NAME));
functionContext.setContextType(ContextType.FUNCTION);
handler.push("function");
handler.push(CF.FUNCTION);
doStructureStart(elem, functionContext, CFFuncDeclStatement.class);
} else if (elem.getName().equalsIgnoreCase("cfloop") && elem.getAttributeValue("query") != null) {
} else if (elem.getName().equalsIgnoreCase(CF.CFLOOP) && elem.getAttributeValue(CF.QUERY) != null) {
// Give a cfloop for query its own context and set the column
// names as variables if they are available
final Context loopContext = context.subContext(elem);
loopContext.setContextType(ContextType.QUERY_LOOP);
handler.push("cfloop");
handler.push(CF.CFLOOP);

final String qryName = elem.getAttributeValue("query");
final String qryName = elem.getAttributeValue(CF.QUERY);
handler.addVariables(handler.getQueryColumns(qryName));
doStructureStart(elem, loopContext, CFFuncDeclStatement.class);
}

if (elem.getName().equalsIgnoreCase("cfset") || elem.getName().equalsIgnoreCase("cfif")
|| elem.getName().equalsIgnoreCase("cfelseif") || elem.getName().equalsIgnoreCase("cfreturn")) {
if (elem.getName().equalsIgnoreCase(CF.CFSET) || elem.getName().equalsIgnoreCase(CF.CFIF)
|| elem.getName().equalsIgnoreCase(CF.CFELSEIF) || elem.getName().equalsIgnoreCase(CF.CFRETURN)) {
scanElement(elem, context);
final Pattern p = Pattern.compile("<\\w+\\s(.*[^/])/?>", Pattern.MULTILINE | Pattern.DOTALL);
final String expr = elem.getFirstStartTag().toString();
Expand All @@ -425,14 +425,14 @@ private void process(final Element elem, final String space, final Context conte
}
processStack(elem.getChildElements(), space + " ", context);

} else if (elem.getName().equalsIgnoreCase("cfargument")) {
} else if (elem.getName().equalsIgnoreCase(CF.CFARGUMENT)) {
scanElement(elem, context);
final String name = elem.getAttributeValue("name");
final String name = elem.getAttributeValue(CF.NAME);
if (name != null) {
handler.addArgument(name);
}
processStack(elem.getChildElements(), space + " ", context);
} else if (elem.getName().equalsIgnoreCase("cfscript")) {
} else if (elem.getName().equalsIgnoreCase(CF.CFSCRIPT)) {
scanElement(elem, context);
String cfscript = elem.getContent().toString();
if (elem.getEndTag() == null) {
Expand All @@ -454,9 +454,9 @@ private void process(final Element elem, final String space, final Context conte
final Context subcontext = context.subContext(elem);
process(scriptStatement, subcontext);
processStack(elem.getChildElements(), space + " ", context);
} else if (elem.getName().equalsIgnoreCase("cffunction")) {
} else if (elem.getName().equalsIgnoreCase(CF.CFFUNCTION)) {
final Context functionContext = context.subContext(elem);
functionContext.setFunctionName(elem.getAttributeValue("name"));
functionContext.setFunctionName(elem.getAttributeValue(CF.NAME));
functionContext.setContextType(ContextType.FUNCTION);
scanElement(elem, functionContext);
processStack(elem.getChildElements(), space + " ", functionContext);
Expand All @@ -480,10 +480,10 @@ private void process(final Element elem, final String space, final Context conte
}
}
handler.pop();
} else if (elem.getName().equalsIgnoreCase("cfcomponent")) {
} else if (elem.getName().equalsIgnoreCase(CF.CFCOMPONENT)) {
final Context componentContext = context.subContext(elem);
componentContext.setInComponent(true);
componentContext.setComponentName(elem.getAttributeValue("displayname"));
componentContext.setComponentName(elem.getAttributeValue(CF.DISPLAYNAME));
componentContext.setContextType(ContextType.COMPONENT);

scanElement(elem, componentContext);
Expand All @@ -503,7 +503,7 @@ private void process(final Element elem, final String space, final Context conte
}
}
handler.pop();
} else if (elem.getName().equalsIgnoreCase("cfquery")) {
} else if (elem.getName().equalsIgnoreCase(CF.CFQUERY)) {
scanElement(elem, context);
for (final Entry<String, CFExpression> expression : unpackTagExpressions(elem).entrySet()) {
if (expression != null) {
Expand All @@ -513,7 +513,7 @@ private void process(final Element elem, final String space, final Context conte
final List<Element> list = elem.getAllElements();
processStack(list.subList(1, list.size()), space + " ", context);
// Save any columns from the cfquery
final String qryName = elem.getAttributeValue("name");
final String qryName = elem.getAttributeValue(CF.NAME);
if (qryName != null && qryName.trim().length() > 0) {
final String qryText = elem.getTextExtractor().toString().toUpperCase();
final Matcher m = Pattern.compile(".*SELECT\\s(\\w+(\\s*,\\s*\\w+)+)\\s+FROM\\s+.*")
Expand All @@ -524,16 +524,16 @@ private void process(final Element elem, final String space, final Context conte
handler.addQueryColumnSet(qryName, cols);
}
}
} else if (elem.getName().equalsIgnoreCase("cfqueryparam")) {
} else if (elem.getName().equalsIgnoreCase(CF.CFQUERYPARAM)) {
scanElement(elem, context);
for (final Entry<String, CFExpression> expression : unpackTagExpressions(elem).entrySet()) {
if (expression != null) {
process(expression.getValue(), elem, context);
}
}
} else if (elem.getName().equalsIgnoreCase("cfinclude")) {
} else if (elem.getName().equalsIgnoreCase(CF.CFINCLUDE)) {
scanElement(elem, context);
final String path = elem.getAttributeValue("template");
final String path = elem.getAttributeValue(CF.TEMPLATE);
final File include = new File(new File(context.getFilename()).getParentFile(), path);
if (strictInclude || include.exists()) {
if (includeFileStack.contains(include)) {
Expand All @@ -544,7 +544,7 @@ private void process(final Element elem, final String space, final Context conte
includeFileStack.pop();
}
}
} else if (elem.getName().equalsIgnoreCase("cfloop") && elem.getAttributeValue("query") != null) {
} else if (elem.getName().equalsIgnoreCase(CF.CFLOOP) && elem.getAttributeValue(CF.QUERY) != null) {
scanElement(elem, context);
processStack(elem.getChildElements(), space + " ", context);
handler.pop();
Expand Down Expand Up @@ -704,13 +704,13 @@ private void process(final CFScriptStatement expression, final Context context)
try {
// TODO fix this to use getPropertyName() when it is
// available and not null.
final Field field = CFPropertyStatement.class.getDeclaredField("propertyName");
final Field field = CFPropertyStatement.class.getDeclaredField(CF.PROPERTY_NAME);
field.setAccessible(true);
CFExpression value = (CFExpression) field.get(expression);
if (value == null) {
for (final Entry<CFIdentifier, CFExpression> entry : ((CFPropertyStatement) expression)
.getAttributes().entrySet()) {
if ("name".equals(entry.getKey().getName())) {
if (CF.NAME.equals(entry.getKey().getName())) {
value = entry.getValue();
}
}
Expand All @@ -733,7 +733,7 @@ private void process(final CFScriptStatement expression, final Context context)
componentContext.setInComponent(true);
componentContext.setContextType(ContextType.COMPONENT);
for (final Entry<CFExpression, CFExpression> entry : compDeclStatement.getAttributes().entrySet()) {
if (entry.getKey() != null && entry.getKey().Decompile(0).equalsIgnoreCase("name")) {
if (entry.getKey() != null && entry.getKey().Decompile(0).equalsIgnoreCase(CF.NAME)) {
componentContext.setComponentName(entry.getValue().Decompile(0));
}
}
Expand Down Expand Up @@ -828,7 +828,7 @@ private void process(final CFScriptStatement expression, final Context context)
functionContext.setFunctionInfo(function);

registerRuleOverrides(functionContext, function.getToken());
handler.push("function");
handler.push(CF.FUNCTION);
for (final CFFunctionParameter param : function.getFormals()) {
handler.addArgument(param.getName());
}
Expand Down Expand Up @@ -998,7 +998,7 @@ protected void registerRuleOverrides(final Context context, final CFExpressionSt
*/
protected void applyRuleOverrides(final Context context, final Element commentElement) {

if (commentElement != null && "!---".equals(commentElement.getName())) {
if (commentElement != null && CF.COMMENT.equals(commentElement.getName())) {
final String mlText = commentElement.toString();
final Pattern pattern = Pattern.compile(".*\\s*@CFLintIgnore\\s+([\\w,_]+)\\s*.*", Pattern.DOTALL);
final Matcher matcher = pattern.matcher(mlText);
Expand Down Expand Up @@ -1138,7 +1138,7 @@ protected boolean checkForDisabled(final Element element, final String msgcode)
Element elem = element;
while (elem != null) {
final Element prevSibling = getPreviousSibling(elem);
if (prevSibling != null && prevSibling.getName().equals("!---")) {
if (prevSibling != null && prevSibling.getName().equals(CF.COMMENT)) {
final Pattern p = Pattern.compile(".*---\\s*CFLINT-DISABLE\\s+(.*)\\s*---.*");
final Matcher m = p.matcher(prevSibling.toString().toUpperCase().trim());
if (m.matches()) {
Expand Down Expand Up @@ -1475,5 +1475,4 @@ public void reportError(final org.antlr.v4.runtime.IntStream input,
public void setStrictIncludes(final boolean strictInclude) {
this.strictInclude = strictInclude;
}

}
11 changes: 6 additions & 5 deletions src/main/java/com/cflint/plugins/core/ArgDefChecker.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cflint.plugins.core;

import com.cflint.BugList;
import com.cflint.CF;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;
import com.cflint.tools.CFTool;
Expand All @@ -19,7 +20,7 @@ public void expression(final CFScriptStatement expression, final Context context
for (final CFFunctionParameter argument : function.getFormals()) {
// handler.addArgument(param.getName());
final String name = argument.getName();
if (!argument.toString().contains("required") && !argument.toString().contains("=")) {
if (!argument.toString().contains(CF.REQUIRED) && !argument.toString().contains("=")) {
context.addMessage("ARG_DEFAULT_MISSING", name);
}
}
Expand All @@ -28,10 +29,10 @@ public void expression(final CFScriptStatement expression, final Context context

@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 boolean required = CFTool.toBoolean(element.getAttributeValue("required"));
final String defaultExpr = element.getAttributeValue("default");
if (element.getName().equals(CF.CFARGUMENT)) {
final String name = element.getAttributeValue(CF.NAME);
final boolean required = CFTool.toBoolean(element.getAttributeValue(CF.REQUIRED));
final String defaultExpr = element.getAttributeValue(CF.DEFAULT);
if (!required && defaultExpr == null) {
element.getSource().getRow(element.getBegin());
element.getSource().getColumn(element.getBegin());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cflint.plugins.core;

import com.cflint.BugList;
import com.cflint.CF;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;
import com.cflint.tools.CFTool;
Expand All @@ -21,7 +22,7 @@ public void expression(final CFScriptStatement expression, final Context context
for (final CFFunctionParameter argument : function.getFormals()) {
final String name = argument.getName();
final boolean checked = isCheck(code, name);
if (!argument.toString().contains("required") && !argument.toString().contains("=") && !checked) {
if (!argument.toString().contains(CF.REQUIRED) && !argument.toString().contains("=") && !checked) {
context.addMessage("ARG_DEFAULT_MISSING", name);
}
}
Expand All @@ -30,10 +31,10 @@ public void expression(final CFScriptStatement expression, final Context context

@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 boolean required = CFTool.toBoolean(element.getAttributeValue("required"));
final String defaultExpr = element.getAttributeValue("default");
if (element.getName().equals(CF.CFARGUMENT)) {
final String name = element.getAttributeValue(CF.NAME);
final boolean required = CFTool.toBoolean(element.getAttributeValue(CF.REQUIRED));
final String defaultExpr = element.getAttributeValue(CF.DEFAULT);
final String code = element.getParentElement().toString();
final boolean checked = isCheck(code, name);

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/cflint/plugins/core/ArgHintChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.regex.Pattern;

import com.cflint.BugList;
import com.cflint.CF;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;
import com.cflint.tools.PrecedingCommentReader;
Expand All @@ -22,9 +23,9 @@ public class ArgHintChecker 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");
final String hint = element.getAttributeValue("hint");
if (element.getName().equals(CF.CFARGUMENT)) {
final String name = element.getAttributeValue(CF.NAME);
final String hint = element.getAttributeValue(CF.HINT);
if (hint == null || hint.length() == 0) {
context.addMessage("ARG_HINT_MISSING", name);
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/cflint/plugins/core/ArgTypeChecker.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cflint.plugins.core;

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

Expand Down Expand Up @@ -31,9 +32,9 @@ public void expression(final CFScriptStatement expression, final Context context

@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 variableType = element.getAttributeValue("type");
if (element.getName().equals(CF.CFARGUMENT)) {
final String name = element.getAttributeValue(CF.NAME);
final String variableType = element.getAttributeValue(CF.TYPE);

if (variableType == null) {
context.addMessage("ARG_TYPE_MISSING", name);
Expand Down
Loading