|
3 | 3 | <cfset this.name = "CodeChecker" /> |
4 | 4 |
|
5 | 5 | <cffunction name="init" access="public" output="false" returntype="any" hint="I initialize the component."> |
6 | | - <cfargument name="categories" default="_ALL" type="string" hint="I am a comma separated list of categories, _ALL for all categories" /> |
| 6 | + <cfargument name="categories" default="" type="string" hint="I am a comma separated list of categories, _ALL for all categories" /> |
7 | 7 | <cfscript> |
8 | 8 | variables.results = []; |
9 | | - variables.objRules = new Rules( categories=ARGUMENTS.categories ); |
| 9 | + variables.objRules = new Rules(); |
10 | 10 | variables.rules = variables.objRules.get(); |
11 | 11 | variables.categories = ARGUMENTS.categories; |
| 12 | + |
12 | 13 | return this; |
13 | 14 | </cfscript> |
14 | 15 | </cffunction> |
|
38 | 39 |
|
39 | 40 | <cfset readFile(filepath=local.filePath)> |
40 | 41 |
|
41 | | - <cfif ListFind( variables.categories, 'QueryParamScanner')> |
| 42 | + <cfif variables.categories is "_ALL" or ListFind( variables.categories, 'QueryParamScanner')> |
42 | 43 | <cfset runQueryParamScanner(filepath=local.filePath)> |
43 | 44 | </cfif> |
44 | | - <cfif ListFind( variables.categories, 'VarScoper')> |
| 45 | + <cfif variables.categories is "_ALL" or ListFind( variables.categories, 'VarScoper')> |
45 | 46 | <cfset runVarScoper(filepath=local.filePath)> |
46 | 47 | </cfif> |
47 | 48 | </cfloop> |
|
50 | 51 |
|
51 | 52 | <cfset readFile(filepath=local.filePath)> |
52 | 53 |
|
53 | | - <cfif ListFind( variables.categories, 'QueryParamScanner')> |
| 54 | + <cfif variables.categories is "_ALL" or ListFind( variables.categories, 'QueryParamScanner')> |
54 | 55 | <cfset runQueryParamScanner(filepath=local.filePath)> |
55 | 56 | </cfif> |
56 | | - <cfif ListFind( variables.categories, 'VarScoper')> |
| 57 | + <cfif variables.categories is "_ALL" or ListFind( variables.categories, 'VarScoper')> |
57 | 58 | <cfset runVarScoper(filepath=local.filePath)> |
58 | 59 | </cfif> |
59 | 60 | </cfif> |
|
75 | 76 | <cfset local.line = fileReadLine( local.dataFile ) /> |
76 | 77 |
|
77 | 78 | <!--- run rules on each line ---> |
78 | | - <cfset runRules(filepath=arguments.filepath, line=local.line, linenumber=local.lineNumber) /> |
| 79 | + <cfset runRules(filepath=arguments.filepath, line=local.line, linenumber=local.lineNumber, categories=variables.categories) /> |
79 | 80 |
|
80 | 81 | <cfif fileIsEOF( local.dataFile )> |
81 | 82 | <!--- run rules on whole file. useful for rules where you are just testing the existence of something. ---> |
|
90 | 91 | <cfargument name="filepath" type="string" required="true" default="" hint="I am the file path for which to review." /> |
91 | 92 | <cfargument name="line" type="string" required="false" hint="I am the line of code for which to review." /> |
92 | 93 | <cfargument name="linenumber" type="numeric" required="false" hint="I am the line number of the code for which to review." /> |
93 | | - |
| 94 | + <cfargument name="categories" default="" type="string" hint="I am a comma separated list of categories, _ALL for all categories" /> |
94 | 95 | <cfset var local = {} /> |
95 | 96 |
|
96 | 97 | <cfset local.standardizedfilepath = Replace(arguments.filepath, "\", "/", "all")> |
|
99 | 100 | <cfset local.fileextension = ListLast(local.file, ".")> |
100 | 101 |
|
101 | 102 | <cfloop array="#variables.rules#" index="local.ruleitem"> |
102 | | - <cfif NOT ListFindNoCase(local.ruleitem.extensions, local.fileextension, ",")> |
103 | | - <cfcontinue /> |
104 | | - </cfif> |
105 | | - <cfif StructKeyExists(arguments,"line") AND NOT local.ruleitem.bulkcheck AND NOT ListLen(local.ruleitem.tagname,"|")> |
106 | | - <cfinvoke component="#local.ruleitem.componentname#" method="#local.ruleitem.functionname#" line="#arguments.line#" passonmatch="#local.ruleitem.passonmatch#" pattern="#local.ruleitem.pattern#" returnvariable="local.codeCheckerReturn" /> |
107 | | - <cfif NOT local.codeCheckerReturn> |
108 | | - <cfset recordResult(directory=local.directory, file=local.file, rule=local.ruleitem.name, message=local.ruleitem.message, linenumber=arguments.linenumber, category=local.ruleitem.category, severity=local.ruleitem.severity)> |
| 103 | + <cfif ARGUMENTS.categories is "_ALL" or ListFind( ARGUMENTS.categories, local.ruleitem["category"] )> |
| 104 | + <cfif NOT ListFindNoCase(local.ruleitem.extensions, local.fileextension, ",")> |
| 105 | + <cfcontinue /> |
109 | 106 | </cfif> |
110 | | - <cfelseif StructKeyExists(arguments,"line") AND NOT local.ruleitem.bulkcheck AND ListLen(local.ruleitem.tagname,"|")> |
111 | | - <cfif REFindNoCase("<#Replace(local.ruleitem.tagname,'|','|<')#", arguments.line)> |
| 107 | + <cfif StructKeyExists(arguments,"line") AND NOT local.ruleitem.bulkcheck AND NOT ListLen(local.ruleitem.tagname,"|")> |
112 | 108 | <cfinvoke component="#local.ruleitem.componentname#" method="#local.ruleitem.functionname#" line="#arguments.line#" passonmatch="#local.ruleitem.passonmatch#" pattern="#local.ruleitem.pattern#" returnvariable="local.codeCheckerReturn" /> |
113 | 109 | <cfif NOT local.codeCheckerReturn> |
114 | 110 | <cfset recordResult(directory=local.directory, file=local.file, rule=local.ruleitem.name, message=local.ruleitem.message, linenumber=arguments.linenumber, category=local.ruleitem.category, severity=local.ruleitem.severity)> |
115 | 111 | </cfif> |
| 112 | + <cfelseif StructKeyExists(arguments,"line") AND NOT local.ruleitem.bulkcheck AND ListLen(local.ruleitem.tagname,"|")> |
| 113 | + <cfif REFindNoCase("<#Replace(local.ruleitem.tagname,'|','|<')#", arguments.line)> |
| 114 | + <cfinvoke component="#local.ruleitem.componentname#" method="#local.ruleitem.functionname#" line="#arguments.line#" passonmatch="#local.ruleitem.passonmatch#" pattern="#local.ruleitem.pattern#" returnvariable="local.codeCheckerReturn" /> |
| 115 | + <cfif NOT local.codeCheckerReturn> |
| 116 | + <cfset recordResult(directory=local.directory, file=local.file, rule=local.ruleitem.name, message=local.ruleitem.message, linenumber=arguments.linenumber, category=local.ruleitem.category, severity=local.ruleitem.severity)> |
| 117 | + </cfif> |
| 118 | + </cfif> |
| 119 | + <cfelseif NOT StructKeyExists(arguments,"line") AND local.ruleitem.bulkcheck> |
| 120 | + <!--- TODO: support dynamic path to jre-utils component ---> |
| 121 | + <cfset local.objJREUtils = createObject("component","services.QueryParamScanner.jre-utils").init()> |
| 122 | + <cfset local.dataFile = FileRead(arguments.filepath)> |
| 123 | + <cfset local.matches = local.objJREUtils.get( local.dataFile , local.ruleitem.pattern )/> |
| 124 | + <cfif ( local.ruleitem.passonmatch AND NOT ArrayLen(local.matches) ) OR ( ArrayLen(local.matches) AND NOT local.ruleitem.passonmatch )> |
| 125 | + <!--- TODO: report actual line number ---> |
| 126 | + <cfset recordResult(directory=local.directory, file=local.file, rule=local.ruleitem.name, message=local.ruleitem.message, linenumber=-1, category=local.ruleitem.category, severity=local.ruleitem.severity)> |
| 127 | + </cfif> |
| 128 | + <cfelse> |
| 129 | + <cfcontinue /> |
116 | 130 | </cfif> |
117 | | - <cfelseif NOT StructKeyExists(arguments,"line") AND local.ruleitem.bulkcheck> |
118 | | - <!--- TODO: support dynamic path to jre-utils component ---> |
119 | | - <cfset local.objJREUtils = createObject("component","services.QueryParamScanner.jre-utils").init()> |
120 | | - <cfset local.dataFile = FileRead(arguments.filepath)> |
121 | | - <cfset local.matches = local.objJREUtils.get( local.dataFile , local.ruleitem.pattern )/> |
122 | | - <cfif ( local.ruleitem.passonmatch AND NOT ArrayLen(local.matches) ) OR ( ArrayLen(local.matches) AND NOT local.ruleitem.passonmatch )> |
123 | | - <!--- TODO: report actual line number ---> |
124 | | - <cfset recordResult(directory=local.directory, file=local.file, rule=local.ruleitem.name, message=local.ruleitem.message, linenumber=-1, category=local.ruleitem.category, severity=local.ruleitem.severity)> |
125 | | - </cfif> |
126 | | - <cfelse> |
127 | | - <cfcontinue /> |
128 | 131 | </cfif> |
129 | 132 | </cfloop> |
130 | 133 | </cffunction> |
|
0 commit comments