Skip to content

Commit

Permalink
fixed #248, set component name correctly in the context.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Mar 8, 2017
1 parent 1c3c2d5 commit 997d4c0
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/cflint/BugInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ private void doMessageText(final Element elem) {

if (bugInfo.component != null) {
message = message.replace("${component}", bugInfo.component);
}else{
message = message.replace("${component}", "unknown");
}

if (message.contains("{tag}") && elem != null) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ private void process(final CFScriptStatement expression, Context context) {
final Context componentContext = context.subContext(null);
componentContext.setInComponent(true);
componentContext.setContextType(ContextType.Component);
for(Entry<CFExpression, CFExpression> entry:compDeclStatement.getAttributes().entrySet()){
if(entry.getKey()!=null && entry.getKey().Decompile(0).equalsIgnoreCase("name")){
componentContext.setComponentName(entry.getValue().Decompile(0));
}
}
// componentContext.setComponentName(compDeclStatement.get); //
// TODO

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/cflint/plugins/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.cflint.BugInfo;
import com.cflint.StackHandler;
import com.cflint.plugins.Context.ContextType;
import com.cflint.tools.ObjectEquals;

import cfml.parsing.cfscript.CFIdentifier;
Expand Down Expand Up @@ -353,5 +354,10 @@ public ContextType getContextType() {

public void setContextType(ContextType contextType) {
this.contextType = contextType;
if(contextType == ContextType.Component && componentName==null){
if(filename != null && filename.trim().length()>0){
componentName= new File(filename.trim()).getName().replaceAll("[.]\\w+", "");
}
}
}
}
37 changes: 37 additions & 0 deletions src/test/resources/com/cflint/tests/ComponentNameChecker/.cflintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"output" : [ ],
"rule" : [ ],
"excludes" : [ ],
"includes" : [ {
"code" : "COMPONENT_INVALID_NAME",
"messageText" : null,
"severity" : null
},{
"code" : "COMPONENT_ALLCAPS_NAME",
"messageText" : null,
"severity" : null
},{
"code" : "COMPONENT_TOO_SHORT",
"messageText" : null,
"severity" : null
},{
"code" : "COMPONENT_TOO_LONG",
"messageText" : null,
"severity" : null
},{
"code" : "COMPONENT_TOO_WORDY",
"messageText" : null,
"severity" : null
},{
"code" : "COMPONENT_IS_TEMPORARY",
"messageText" : null,
"severity" : null
},{
"code" : "COMPONENT_HAS_PREFIX_OR_POSTFIX",
"messageText" : null,
"severity" : null
}
],
"inheritParent" : false,
"inheritPlugins" : true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
component {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[ {
"severity" : "INFO",
"id" : "COMPONENT_INVALID_NAME",
"message" : "COMPONENT_INVALID_NAME",
"category" : "CFLINT",
"abbrev" : "CI",
"locations" : [ {
"file" : "src\\test\\resources\\com\\cflint\\tests\\ComponentNameChecker\\foo.cfc",
"fileName" : "foo.cfc",
"function" : "",
"column" : "0",
"line" : "1",
"message" : "Component name ${component} is not a valid name. Please use CamelCase and start with a capital letter.",
"variable" : "",
"expression" : "component {\n}"
} ]
} ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
component name="foo2"{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[ {
"severity" : "INFO",
"id" : "COMPONENT_INVALID_NAME",
"message" : "COMPONENT_INVALID_NAME",
"category" : "CFLINT",
"abbrev" : "CI",
"locations" : [ {
"file" : "src/test/resources/com/cflint/tests/ComponentNameChecker/foofoo.cfc",
"fileName" : "foofoo.cfc",
"function" : "",
"column" : "0",
"line" : "1",
"message" : "Component name 'foo2' is not a valid name. Please use CamelCase and start with a capital letter.",
"variable" : "",
"expression" : "component name='foo2' {/n}"
} ]
} ]

0 comments on commit 997d4c0

Please sign in to comment.