-
Notifications
You must be signed in to change notification settings - Fork 84
/
cflint-to-findbugs.xsl
245 lines (232 loc) · 8.83 KB
/
cflint-to-findbugs.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?xml version="1.0" encoding="UTF-8"?>
<!-- CFLint XML to FindBugs XML (https://github.com/findbugsproject/findbugs/blob/master/findbugs/etc/bugcollection.xsd) -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" standalone="yes" encoding="UTF-8" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:variable name="version" select="/issues/@version"/>
<xsl:variable name="timestamp" select="/issues/@timestamp"/>
<BugCollection sequence="0" release="">
<xsl:attribute name="timestamp">
<xsl:value-of select="$timestamp"/>
</xsl:attribute>
<xsl:attribute name="analysisTimestamp">
<xsl:value-of select="$timestamp"/>
</xsl:attribute>
<xsl:attribute name="version">
<xsl:value-of select="$version"/>
</xsl:attribute>
<Project projectName=""/>
<xsl:apply-templates select="/issues/issue" />
<xsl:call-template name="category" />
<xsl:call-template name="pattern" />
<Errors/>
<xsl:call-template name="summary" />
<ClassFeatures/>
<History/>
</BugCollection>
</xsl:template>
<xsl:template name="summary">
<FindBugsSummary timestamp="" num_packages="0">
<xsl:attribute name="timestamp">
<xsl:value-of select="/issues/@timestamp"/>
</xsl:attribute>
<xsl:attribute name="total_bugs">
<xsl:value-of select="sum(/issues/counts/count[@code]/@count)"/>
</xsl:attribute>
<xsl:attribute name="total_classes">
<xsl:value-of select="/issues/counts/@totalfiles"/>
</xsl:attribute>
<xsl:attribute name="total_size">
<xsl:value-of select="/issues/counts/@totallines"/>
</xsl:attribute>
<xsl:attribute name="priority_1">
<xsl:value-of select="count(/issues/issue[@severity = 'FATAL' or @severity = 'Fatal' or @severity = 'CRITICAL' or @severity = 'Critical'])"/>
</xsl:attribute>
<xsl:attribute name="priority_2">
<xsl:value-of select="count(/issues/issue[@severity = 'ERROR' or @severity = 'Error' or @severity = 'WARNING' or @severity = 'Warning' or @severity = 'CAUTION' or @severity = 'Caution' ])"/>
</xsl:attribute>
<xsl:attribute name="priority_3">
<xsl:value-of select="count(/issues/issue[@severity = 'INFO' or @severity = 'Info' or @severity = 'COSMETIC' or @severity = 'Cosmetic'])"/>
</xsl:attribute>
<xsl:for-each select="/issues/issue/location[@file]">
<xsl:if test="count(preceding::*[./@file = current()/@file]) = 0">
<FileStats>
<xsl:attribute name="path">
<xsl:value-of select="@file" />
</xsl:attribute>
<xsl:attribute name="bugCount">
<xsl:value-of select="count(//@file[.=current()/@file])" />
</xsl:attribute>
</FileStats>
</xsl:if>
</xsl:for-each>
</FindBugsSummary>
</xsl:template>
<xsl:template name="category">
<xsl:for-each select="/issues/issue[@category]">
<xsl:variable name="cat" select="@category"/>
<xsl:if test="not(preceding-sibling::issue[@category=$cat])">
<BugCategory>
<xsl:attribute name="category">
<xsl:value-of select="$cat"/>
</xsl:attribute>
<Description>
<xsl:value-of select="$cat"/>
</Description>
</BugCategory>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="pattern">
<xsl:for-each select="/issues/issue[@message]">
<xsl:variable name="msg" select="@message"/>
<xsl:if test="not(preceding-sibling::issue[@message=$msg])">
<xsl:for-each select="/issues/issue[@message=$msg][1]">
<BugPattern>
<xsl:attribute name="abbrev">
<xsl:value-of select="@abbrev"/>
</xsl:attribute>
<xsl:attribute name="category">
<xsl:value-of select="@category"/>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="@message"/>
</xsl:attribute>
<ShortDescription><xsl:value-of select="@message"/></ShortDescription>
<Details>
<xsl:choose>
<xsl:when test="@message='MISSING_VAR'">
<xsl:text>Variable assigned without a scope. This puts in a large scope that is usually intended. Suggest using the 'var name' statement of explicit 'LOCAL.name' statement.</xsl:text>
</xsl:when>
<xsl:when test="@message='NESTED_CFOUTPUT'">
<xsl:text>Nested <cfquery/> tags, the outer tag has an @query attribute, it should also specify the @group attribute.</xsl:text>
</xsl:when>
<xsl:when test="@message='QUERYNEW_DATATYPE'">
<xsl:text>QueryNew should specify the datatypes of the columns.</xsl:text>
</xsl:when>
<xsl:when test="@message='ARG_VAR_CONFLICT'">
<xsl:text>Variable is varr'd with the same name as one of the arguments. This is confusing or incorrect.</xsl:text>
</xsl:when>
<xsl:when test="@message='ARG_VAR_MIXED'">
<xsl:text>Variable referenced both as an unscoped (local) and an argument.</xsl:text>
</xsl:when>
<xsl:when test="@message='ARG_DEFAULT_MISSING'">
<xsl:text>Arguments that are not required should specify a default value (@default)</xsl:text>
</xsl:when>
<xsl:when test="@message='OUTPUT_ATTR'">
<xsl:text>Functions should specify @output="false"</xsl:text>
</xsl:when>
</xsl:choose>
</Details>
</BugPattern>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="issue/location">
<BugInstance>
<xsl:attribute name="type">
<xsl:value-of select="../@id" />
</xsl:attribute>
<xsl:attribute name="priority">
<xsl:choose>
<xsl:when test="../@severity = 'FATAL' or ../@severity = 'Fatal'">1</xsl:when>
<xsl:when test="../@severity = 'CRITICAL' or ../@severity = 'Critical'">2</xsl:when>
<xsl:when test="../@severity = 'ERROR' or ../@severity = 'Error'">3</xsl:when>
<xsl:when test="../@severity = 'WARNING' or ../@severity = 'Warning'">4</xsl:when>
<xsl:when test="../@severity = 'CAUTION' or ../@severity = 'Caution'">5</xsl:when>
<xsl:when test="../@severity = 'INFO' or ../@severity = 'Info'">6</xsl:when>
<xsl:when test="../@severity = 'COSMETIC' or ../@severity = 'Cosmetic'">7</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="abbrev">
<xsl:value-of select="../@abbrev" />
</xsl:attribute>
<xsl:attribute name="category">
<xsl:value-of select="../@category" />
</xsl:attribute>
<ShortMessage>
<xsl:value-of select="@message"/>
</ShortMessage>
<LongMessage>
<xsl:value-of select="@message"/>
<xsl:choose>
<xsl:when test="../@message='MISSING_VAR'">
<xsl:text> Use var or the local scope, or otherwise clarify the scope</xsl:text>
</xsl:when>
</xsl:choose>
</LongMessage>
<Class>
<xsl:attribute name="classname">
<xsl:value-of select="@file" />
</xsl:attribute>
<SourceLine startBytecode="0" endBytecode="0">
<xsl:attribute name="classname">
<xsl:value-of select="@file" />
</xsl:attribute>
<xsl:attribute name="start">
<xsl:value-of select="@line" />
</xsl:attribute>
<xsl:attribute name="end">
<xsl:value-of select="@line" />
</xsl:attribute>
<xsl:attribute name="sourcefile">
<xsl:value-of select="@fileName" />
</xsl:attribute>
<xsl:attribute name="sourcepath">
<xsl:value-of select="@file" />
</xsl:attribute>
<Message>
<xsl:text>At line: </xsl:text>
<xsl:value-of select="@line" />
<xsl:text>, at column: </xsl:text>
<xsl:value-of select="@column" />
</Message>
</SourceLine>
</Class>
<xsl:if test="@function and string-length(@function)!=0">
<Method signature="" isStatic="false">
<xsl:attribute name="classname">
<xsl:value-of select="@file" />
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="@function" />
</xsl:attribute>
<SourceLine startBytecode="0" endBytecode="0">
<xsl:attribute name="classname">
<xsl:value-of select="@file" />
</xsl:attribute>
<xsl:attribute name="start">
<xsl:value-of select="@line" />
</xsl:attribute>
<xsl:attribute name="end">
<xsl:value-of select="@line" />
</xsl:attribute>
<xsl:attribute name="sourcefile">
<xsl:value-of select="@fileName" />
</xsl:attribute>
<xsl:attribute name="sourcepath">
<xsl:value-of select="@file" />
</xsl:attribute>
<Message>
<xsl:text>In function </xsl:text>
<xsl:value-of select="@function"/>
<xsl:text>()</xsl:text>
</Message>
</SourceLine>
</Method>
</xsl:if>
<xsl:if test="Expression and not(Expression = 'null')">
<LocalVariable register="0" pc="0" role="">
<xsl:attribute name="name">
<xsl:value-of select="Expression" />
</xsl:attribute>
<Message>
<xsl:text>Expression: </xsl:text>
<xsl:value-of select="Expression" />
</Message>
</LocalVariable>
</xsl:if>
</BugInstance>
</xsl:template>
</xsl:stylesheet>