Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Mar 4, 2017
1 parent 6ee7ed3 commit aaaba7e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/cflint/plugins/CFLintScannerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public String getParameter(final String name) {
}
return null;
}
public String getParameterNotNull(final String name) {
if (name != null) {
return params.get(name.toLowerCase());
}
return "";
}

public int currentLine(final CFExpression expression, final Context context) {
return expression.getLine() + context.startLine() - 1;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/cflint/plugins/core/CFScopes.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public boolean isCFScoped(final String variable) {
final String[] parts = parts(variable);
return scopes.contains(parts[0].toLowerCase());
}
public String getScope(final String variable) {
final String[] parts = parts(variable);
if(scopes.contains(parts[0].toLowerCase())){
return parts[0].toLowerCase();
}
return "variables";
}


public boolean isScoped(final String variable, final String scope) {
final String[] parts = parts(variable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public void checkNameForBugs(final Context context, final String fullVariable, f
if (excludeFromAnalyse(variable)) {
return;
}

int minVarLength = ValidName.MIN_VAR_LENGTH;
int maxVarLength = ValidName.MAX_VAR_LENGTH;
int maxVarWords = ValidName.MAX_VAR_WORDS;
Expand All @@ -141,16 +140,17 @@ public void checkNameForBugs(final Context context, final String fullVariable, f
}

final CFScopes scope = new CFScopes();
final String varScope = scope.getScope(fullVariable);
final ValidName name = new ValidName(minVarLength, maxVarLength, maxVarWords);

if (name.isInvalid(variable)) {
context.getParent(ContextType.Function).addUniqueMessage("VAR_INVALID_NAME", variable, this, line);
}
if (!scope.isCFScoped(variable) && name.isUpperCase(variable)) {
if (!getParameterNotNull("IgnoreAllCapsInScopes").toLowerCase().contains(varScope))
context.getParent(ContextType.Function).addUniqueMessage("VAR_ALLCAPS_NAME", variable, this, line);
}
if (scope.isCFScoped(variable) && name.isUpperCase(variable) && (getParameter("IgnoreUpperCaseScopes") == null
|| !getParameter("IgnoreUpperCaseScopes").contains(variable))) {
if (scope.isCFScoped(variable) && name.isUpperCase(variable) && !getParameterNotNull("IgnoreUpperCaseScopes").contains(variable)) {
context.getParent(ContextType.Function).addUniqueMessage("SCOPE_ALLCAPS_NAME", variable, this, line);
}
if (name.tooShort(variable)) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/cflint.definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,10 @@
{
"name": "IgnoreUpperCaseScopes",
"value": "CGI,URL"
},
{
"name": "IgnoreAllCapsInScopes",
"value": "this"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
component {
this.ROOMRESERVATIONS.SINGLE = 1;
this.ROOMRESERVATIONS.DOUBLE = 2;

this.YES = 1;
this.NO = 2;

VARIABLE = 10;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[ {
"severity" : "INFO",
"id" : "VAR_ALLCAPS_NAME",
"message" : "VAR_ALLCAPS_NAME",
"category" : "CFLINT",
"abbrev" : "VA",
"locations" : [ {
"file" : "src/test/resources/com/cflint/tests/VariableNameChecker/sample_239.cfc",
"fileName" : "sample_239.cfc",
"function" : "",
"column" : "0",
"line" : "8",
"message" : "Variable VARIABLE should not be upper case.",
"variable" : "VARIABLE",
"expression" : ""
} ]
} ]

0 comments on commit aaaba7e

Please sign in to comment.