danger-codenarc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module Codenarc
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,86 @@
1
+ require "nokogiri"
2
+
3
+ module Danger
4
+ # Shows errors and warnings from codenarc
5
+ # You'll need [codenarc](http://codenarc.sourceforge.net/) installed and
6
+ # generating a XML report file to use this plugin. This plugin does not run
7
+ # codenarc for you.
8
+ #
9
+ # @example Showing summary
10
+ #
11
+ # danger-codenarc.report 'CodeNarcXmlReport.xml'
12
+ #
13
+ #
14
+ # @see IntrepidPursuits/danger-codenarc
15
+ # @tags codenarc, groovy
16
+ #
17
+ class DangerCodenarc < Plugin
18
+ # The project root, which will be used to make the paths relative.
19
+ # Defaults to `pwd`.
20
+ # @return [String] project_root value
21
+ # attr_accessor :project_root
22
+ def project_root
23
+ root = @project_root || Dir.pwd
24
+ root += "/" unless root.end_with? "/"
25
+ root
26
+ end
27
+
28
+ # Defines if the test summary will be sticky or not.
29
+ # Defaults to `false`.
30
+ # @return [Boolean] sticky
31
+ # attr_accessor :sticky_summary
32
+ def sticky_summary
33
+ @sticky_summary || false
34
+ end
35
+
36
+ # Reads a puppet-lint summary file and reports it.
37
+ #
38
+ # @param [String] file_path Path for puppet-lint report.
39
+ # @return [void]
40
+ def report(file_path)
41
+ raise "Summary file not found" unless File.file?(file_path)
42
+
43
+ run_summary(file_path)
44
+ end
45
+
46
+ private
47
+
48
+ def run_summary(report_file)
49
+ doc = Nokogiri::XML(File.open(report_file))
50
+
51
+ # Create Summary
52
+ pkg_summary = doc.xpath("//PackageSummary")[0]
53
+ tf = pkg_summary.attr("totalFiles")
54
+ fwv = pkg_summary.attr("filesWithViolations")
55
+ p1_count = pkg_summary.attr("priority1")
56
+ p2_count = pkg_summary.attr("priority2")
57
+ p3_count = pkg_summary.attr("priority3")
58
+ summary = "CodeNarc scanned #{tf} files. Found #{fwv} files with violations. #{p1_count} P1 violations, #{p2_count} P2 violations, and #{p3_count} P3 violations"
59
+ message(summary, sticky: sticky_summary)
60
+
61
+ # Iterate Packages
62
+ doc.xpath("//Package").each do |pack_el|
63
+ pack_el.xpath("File").each do |file_el|
64
+ file_el.xpath("Violation").each do |violation|
65
+ package_path = pack_el.attr("path")
66
+ filename = file_el.attr("name")
67
+ line_num = violation.attr("lineNumber")
68
+ priority = violation.attr("priority")
69
+ rule = violation.attr("ruleName")
70
+ is_err = (priority == 1)
71
+
72
+ violation_text = violation.xpath("Message")[0].text.strip!
73
+ source_line = " #{violation.xpath("SourceLine")[0].text.strip!}"
74
+ violation_message = "#{package_path}/#{filename}#L#{line_num} - P#{priority} [#{rule}] - #{violation_text}\n#{source_line}"
75
+
76
+ if is_err
77
+ fail(violation_message, sticky: false)
78
+ else
79
+ warn(violation_message, sticky: false)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1 @@
1
+ require "codenarc/gem_version"
@@ -0,0 +1 @@
1
+ require "codenarc/plugin"
@@ -0,0 +1,29 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerCodenarc do
5
+ it "should be a plugin" do
6
+ expect(Danger::DangerCodenarc.new(nil)).to be_a Danger::Plugin
7
+ end
8
+
9
+ # TODO: Add more ... ya know... tests.
10
+ describe "with Dangerfile" do
11
+ before do
12
+ @dangerfile = testing_dangerfile
13
+ @my_plugin = @dangerfile.codenarc
14
+ end
15
+
16
+ it "Counts p2 and p3 as warnings" do
17
+ report_path = File.expand_path('../support/example.xml', __FILE__)
18
+ @my_plugin.report(report_path)
19
+ expect(@dangerfile.status_report[:warnings].size).to eq(78)
20
+ end
21
+
22
+ it "Counts p1 as errors" do
23
+ report_path = File.expand_path('../support/example.xml', __FILE__)
24
+ @my_plugin.report(report_path)
25
+ expect(@dangerfile.status_report[:errors].size).to eq(0)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,65 @@
1
+ require "pathname"
2
+ ROOT = Pathname.new(File.expand_path("../../", __FILE__))
3
+ $:.unshift((ROOT + "lib").to_s)
4
+ $:.unshift((ROOT + "spec").to_s)
5
+
6
+ require "bundler/setup"
7
+ require "pry"
8
+
9
+ require "rspec"
10
+ require "danger"
11
+
12
+ if `git remote -v` == ''
13
+ puts "You cannot run tests without setting a local git remote on this repo"
14
+ puts "It's a weird side-effect of Danger's internals."
15
+ exit(0)
16
+ end
17
+
18
+ # Use coloured output, it's the best.
19
+ RSpec.configure do |config|
20
+ config.filter_gems_from_backtrace "bundler"
21
+ config.color = true
22
+ config.tty = true
23
+ end
24
+
25
+ require "danger_plugin"
26
+
27
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
28
+ # If you are expanding these files, see if it's already been done ^.
29
+
30
+ # A silent version of the user interface,
31
+ # it comes with an extra function `.string` which will
32
+ # strip all ANSI colours from the string.
33
+
34
+ # rubocop:disable Lint/NestedMethodDefinition
35
+ def testing_ui
36
+ @output = StringIO.new
37
+ def @output.winsize
38
+ [20, 9999]
39
+ end
40
+
41
+ cork = Cork::Board.new(out: @output)
42
+ def cork.string
43
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
44
+ end
45
+ cork
46
+ end
47
+ # rubocop:enable Lint/NestedMethodDefinition
48
+
49
+ # Example environment (ENV) that would come from
50
+ # running a PR on TravisCI
51
+ def testing_env
52
+ {
53
+ "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
54
+ "TRAVIS_PULL_REQUEST" => "800",
55
+ "TRAVIS_REPO_SLUG" => "artsy/eigen",
56
+ "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
57
+ "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
58
+ }
59
+ end
60
+
61
+ # A stubbed out Dangerfile for use in tests
62
+ def testing_dangerfile
63
+ env = Danger::EnvironmentManager.new(testing_env)
64
+ Danger::Dangerfile.new(env, testing_ui)
65
+ end
@@ -0,0 +1,1892 @@
1
+ <CodeNarc url="http://www.codenarc.org" version="1.2.1">
2
+ <Report timestamp="Aug 8, 2018 9:32:31 PM"/>
3
+ <Project title="Sample Project">
4
+ <SourceDirectory>src/test/groovy/org/codenarc/rule</SourceDirectory>
5
+ </Project>
6
+ <PackageSummary totalFiles="380" filesWithViolations="34" priority1="0" priority2="60" priority3="18"/>
7
+ <Package path="" totalFiles="10" filesWithViolations="4" priority1="0" priority2="0" priority3="14">
8
+ <File name="AbstractAstVisitorRuleTest.groovy">
9
+ <Violation ruleName="UnnecessaryObjectReferences" priority="3" lineNumber="184">
10
+ <SourceLine>
11
+ <![CDATA[
12
+ rule.doNotApplyToClassNames = 'Xxx' // doNotApply = NO
13
+ ]]>
14
+ </SourceLine>
15
+ <Message>
16
+ <![CDATA[
17
+ The code could be more concise by using a with() or identity() block
18
+ ]]>
19
+ </Message>
20
+ </Violation>
21
+ <Violation ruleName="UnnecessaryObjectReferences" priority="3" lineNumber="187">
22
+ <SourceLine>
23
+ <![CDATA[
24
+ rule.applyToClassNames = 'Xxx' // apply = NO
25
+ ]]>
26
+ </SourceLine>
27
+ <Message>
28
+ <![CDATA[
29
+ The code could be more concise by using a with() or identity() block
30
+ ]]>
31
+ </Message>
32
+ </Violation>
33
+ <Violation ruleName="UnnecessaryObjectReferences" priority="3" lineNumber="188">
34
+ <SourceLine>
35
+ <![CDATA[
36
+ rule.doNotApplyToClassNames = 'Xxx' // doNotApply = NO
37
+ ]]>
38
+ </SourceLine>
39
+ <Message>
40
+ <![CDATA[
41
+ The code could be more concise by using a with() or identity() block
42
+ ]]>
43
+ </Message>
44
+ </Violation>
45
+ </File>
46
+ <File name="AbstractEnhanceableAstVisitorRuleTest.groovy">
47
+ <Violation ruleName="MisorderedStaticImports" priority="3" lineNumber="22">
48
+ <SourceLine>
49
+ <![CDATA[
50
+ import static org.codenarc.rule.AbstractEnhanceableAstVisitorRule.ENHANCED_MODE_SYSTEM_PROPERTY
51
+ ]]>
52
+ </SourceLine>
53
+ <Message>
54
+ <![CDATA[ Static imports should appear before normal imports ]]>
55
+ </Message>
56
+ </Violation>
57
+ <Violation ruleName="MisorderedStaticImports" priority="3" lineNumber="23">
58
+ <SourceLine>
59
+ <![CDATA[
60
+ import static org.codenarc.source.SourceCode.DEFAULT_COMPILER_PHASE
61
+ ]]>
62
+ </SourceLine>
63
+ <Message>
64
+ <![CDATA[ Static imports should appear before normal imports ]]>
65
+ </Message>
66
+ </Violation>
67
+ </File>
68
+ <File name="AbstractRuleTest.groovy">
69
+ <Violation ruleName="UnnecessaryObjectReferences" priority="3" lineNumber="137">
70
+ <SourceLine>
71
+ <![CDATA[
72
+ rule.doNotApplyToFilesMatching = NO_MATCH // doNotApply = NO
73
+ ]]>
74
+ </SourceLine>
75
+ <Message>
76
+ <![CDATA[
77
+ The code could be more concise by using a with() or identity() block
78
+ ]]>
79
+ </Message>
80
+ </Violation>
81
+ <Violation ruleName="UnnecessaryObjectReferences" priority="3" lineNumber="140">
82
+ <SourceLine>
83
+ <![CDATA[
84
+ rule.applyToFilesMatching = NO_MATCH // apply = NO
85
+ ]]>
86
+ </SourceLine>
87
+ <Message>
88
+ <![CDATA[
89
+ The code could be more concise by using a with() or identity() block
90
+ ]]>
91
+ </Message>
92
+ </Violation>
93
+ <Violation ruleName="UnnecessaryObjectReferences" priority="3" lineNumber="141">
94
+ <SourceLine>
95
+ <![CDATA[
96
+ rule.doNotApplyToFilesMatching = NO_MATCH // doNotApply = NO
97
+ ]]>
98
+ </SourceLine>
99
+ <Message>
100
+ <![CDATA[
101
+ The code could be more concise by using a with() or identity() block
102
+ ]]>
103
+ </Message>
104
+ </Violation>
105
+ <Violation ruleName="UnnecessaryObjectReferences" priority="3" lineNumber="177">
106
+ <SourceLine>
107
+ <![CDATA[
108
+ rule.applyToFileNames = 'org/codenarc/MyOtherTest.groovy'
109
+ ]]>
110
+ </SourceLine>
111
+ <Message>
112
+ <![CDATA[
113
+ The code could be more concise by using a with() or identity() block
114
+ ]]>
115
+ </Message>
116
+ </Violation>
117
+ <Violation ruleName="UnnecessaryObjectReferences" priority="3" lineNumber="225">
118
+ <SourceLine>
119
+ <![CDATA[
120
+ rule.doNotApplyToFileNames = 'Xxx.groovy' // doNotApply = NO
121
+ ]]>
122
+ </SourceLine>
123
+ <Message>
124
+ <![CDATA[
125
+ The code could be more concise by using a with() or identity() block
126
+ ]]>
127
+ </Message>
128
+ </Violation>
129
+ <Violation ruleName="UnnecessaryObjectReferences" priority="3" lineNumber="228">
130
+ <SourceLine>
131
+ <![CDATA[
132
+ rule.applyToFileNames = 'Xxx.groovy' // apply = NO
133
+ ]]>
134
+ </SourceLine>
135
+ <Message>
136
+ <![CDATA[
137
+ The code could be more concise by using a with() or identity() block
138
+ ]]>
139
+ </Message>
140
+ </Violation>
141
+ <Violation ruleName="UnnecessaryObjectReferences" priority="3" lineNumber="229">
142
+ <SourceLine>
143
+ <![CDATA[
144
+ rule.doNotApplyToFileNames = 'Xxx.groovy' // doNotApply = NO
145
+ ]]>
146
+ </SourceLine>
147
+ <Message>
148
+ <![CDATA[
149
+ The code could be more concise by using a with() or identity() block
150
+ ]]>
151
+ </Message>
152
+ </Violation>
153
+ </File>
154
+ <File name="InlineViolationsParserTest.groovy">
155
+ <Violation ruleName="MisorderedStaticImports" priority="3" lineNumber="20">
156
+ <SourceLine>
157
+ <![CDATA[
158
+ import static org.codenarc.rule.InlineViolationsParser.inlineViolation
159
+ ]]>
160
+ </SourceLine>
161
+ <Message>
162
+ <![CDATA[ Static imports should appear before normal imports ]]>
163
+ </Message>
164
+ </Violation>
165
+ <Violation ruleName="UnnecessaryReturnKeyword" priority="3" lineNumber="199">
166
+ <SourceLine>
167
+ <![CDATA[
168
+ return [lineNumber: lineNumber, sourceLineText: sourceLineText, messageText: messageText]
169
+ ]]>
170
+ </SourceLine>
171
+ <Message>
172
+ <![CDATA[
173
+ The return keyword is not needed and can be removed
174
+ ]]>
175
+ </Message>
176
+ </Violation>
177
+ </File>
178
+ </Package>
179
+ <Package path="basic" totalFiles="44" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
180
+ <Package path="braces" totalFiles="4" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
181
+ <Package path="concurrency" totalFiles="26" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
182
+ <Package path="convention" totalFiles="24" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
183
+ <Package path="design" totalFiles="23" filesWithViolations="2" priority1="0" priority2="1" priority3="1">
184
+ <File name="NestedForLoopRuleTest.groovy">
185
+ <Violation ruleName="UnnecessaryReturnKeyword" priority="3" lineNumber="106">
186
+ <SourceLine>
187
+ <![CDATA[ return inlineViolation('Nested for loop') ]]>
188
+ </SourceLine>
189
+ <Message>
190
+ <![CDATA[
191
+ The return keyword is not needed and can be removed
192
+ ]]>
193
+ </Message>
194
+ </Violation>
195
+ </File>
196
+ <File name="PrivateFieldCouldBeFinalRuleTest.groovy">...</File>
197
+ </Package>
198
+ <Package path="dry" totalFiles="4" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
199
+ <Package path="enhanced" totalFiles="1" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
200
+ <Package path="exceptions" totalFiles="20" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
201
+ <Package path="formatting" totalFiles="31" filesWithViolations="9" priority1="0" priority2="19" priority3="1">
202
+ <File name="BracesForForLoopRuleTest.groovy">
203
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="101">
204
+ <SourceLine>
205
+ <![CDATA[ final SOURCE = ''' ]]>
206
+ </SourceLine>
207
+ <Message>
208
+ <![CDATA[
209
+ The String ' for(String name=${SomeClass.SOME_CONSTANT}; name==null;) // And what about {} { doStuff() } ' contains a GString-type expression: '${SomeClass.SOME_CONSTANT}; name==null;) // And what about {}'
210
+ ]]>
211
+ </Message>
212
+ </Violation>
213
+ </File>
214
+ <File name="BracesForIfElseRuleTest.groovy">
215
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="59">
216
+ <SourceLine>
217
+ <![CDATA[ final SOURCE = ''' ]]>
218
+ </SourceLine>
219
+ <Message>
220
+ <![CDATA[
221
+ The String ' if (someContainer."${SomeClass.SOME_CONSTANT}" != null) // And what about {} { doStuff() } ' contains a GString-type expression: '${SomeClass.SOME_CONSTANT}" != null) // And what about {}'
222
+ ]]>
223
+ </Message>
224
+ </Violation>
225
+ </File>
226
+ <File name="BracesForMethodRuleTest.groovy">
227
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="285">
228
+ <SourceLine>
229
+ <![CDATA[ final SOURCE = ''' ]]>
230
+ </SourceLine>
231
+ <Message>
232
+ <![CDATA[
233
+ The String ' class MyClass { int size(String name = "${SomeClass.SOME_CONSTANT}") { return 99 } } ' contains a GString-type expression: '${SomeClass.SOME_CONSTANT}'
234
+ ]]>
235
+ </Message>
236
+ </Violation>
237
+ </File>
238
+ <File name="IndentationRuleTest.groovy">
239
+ <Violation ruleName="MethodCount" priority="2" lineNumber="26">
240
+ <SourceLine>
241
+ <![CDATA[
242
+ class IndentationRuleTest extends AbstractRuleTestCase&lt;IndentationRule&gt; {
243
+ ]]>
244
+ </SourceLine>
245
+ <Message>
246
+ <![CDATA[
247
+ Class org.codenarc.rule.formatting.IndentationRuleTest has 41 methods
248
+ ]]>
249
+ </Message>
250
+ </Violation>
251
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="525">
252
+ <SourceLine>
253
+ <![CDATA[ final SOURCE = ''' ]]>
254
+ </SourceLine>
255
+ <Message>
256
+ <![CDATA[
257
+ The String ' |class MyClass { | private void execute() { | try { | executeWithArgs(args) | } | catch(Throwable t) { | println "ERROR: ${t.message}" | t.printStackTrace() | } | finally { | closeResources() | } | } | private void executeOtherOne() { | try { | executeWithArgs(args) | } catch(Throwable t) { | t.printStackTrace() | } finally { | closeResources() | } | } |} ' contains a GString-type expression: '${t.message}'
258
+ ]]>
259
+ </Message>
260
+ </Violation>
261
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="796">
262
+ <SourceLine>
263
+ <![CDATA[ final SOURCE = ''' ]]>
264
+ </SourceLine>
265
+ <Message>
266
+ <![CDATA[
267
+ The String ' |project.files(project.configurations.scaconfig.files.findAll { File it -&gt; it.name.endsWith '.aar' }.collect { File it -&gt; | MessageDigest sha1 = MessageDigest.getInstance('SHA1') | String inputFile = 'COMMAND=PREPARE_LIBRARY\n' + | "FILE_PATH=${it.absolutePath}\n" | String hash = new BigInteger(1, sha1.digest(inputFile.bytes)).toString(16) | cacheDir + hash + File.separator + 'output/jars/classes.jar' |}).asFileTree ' contains a GString-type expression: '${it.absolutePath}'
268
+ ]]>
269
+ </Message>
270
+ </Violation>
271
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="810">
272
+ <SourceLine>
273
+ <![CDATA[ final SOURCE = ''' ]]>
274
+ </SourceLine>
275
+ <Message>
276
+ <![CDATA[
277
+ The String ' |buildFileList() | .collect { File it -&gt; | MessageDigest sha1 = MessageDigest.getInstance('SHA1') | String inputFile = 'COMMAND=PREPARE_LIBRARY\n' + | "FILE_PATH=${it.absolutePath}\n" | cacheDir + File.separator + inputFile + sha1 | } | .each { name -&gt; | println name | } |println "done" | |list2.collect { item -&gt; | item.name |}.each { name -&gt; println name } | |otherList.collect { item -&gt; item.name }.each { name -&gt; println name } | |if (expr instanceof ConstructorCallExpression || expr instanceof CastExpression) { | [Map, Iterable, List, Collection, ArrayList, Set, HashSet].findAll { | AstUtil.classNodeImplementsType(expr.type, it) | }.each { | callbackFunction() | } |} ' contains a GString-type expression: '${it.absolutePath}'
278
+ ]]>
279
+ </Message>
280
+ </Violation>
281
+ </File>
282
+ <File name="SpaceAfterClosingBraceRuleTest.groovy">
283
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="38">
284
+ <SourceLine>
285
+ <![CDATA[ final SOURCE = ''' ]]>
286
+ </SourceLine>
287
+ <Message>
288
+ <![CDATA[
289
+ The String ' class MyClass { def myMethod() { def closure = { } if (true) { } while(ready) { } try { } catch(Exception e) { } finally { } for(int i=0; i&lt;10; i++) { } for(String name in names) { } for(String name: names) { } if (count &gt; this."maxPriority${priority}Violations") { } while (count &gt; this."maxPriority${priority}Violations") { } } MyClass() { this(classNames) } static void reset() { violationCounts = [1:0, 2:0, 3:0] } void doStuff() { println 9 } } interface MyInterface { } enum MyEnum { OK, BAD } ' contains a GString-type expression: '${priority}Violations") { }'
290
+ ]]>
291
+ </Message>
292
+ </Violation>
293
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="291">
294
+ <SourceLine>
295
+ <![CDATA[ assertNoViolations(''' ]]>
296
+ </SourceLine>
297
+ <Message>
298
+ <![CDATA[
299
+ The String ' def foo = 1 "I am a ${ -&gt; foo }" ' contains a GString-type expression: '${ -&gt; foo }'
300
+ ]]>
301
+ </Message>
302
+ </Violation>
303
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="299">
304
+ <SourceLine>
305
+ <![CDATA[ assertNoViolations(''' ]]>
306
+ </SourceLine>
307
+ <Message>
308
+ <![CDATA[
309
+ The String ' def foo = 1 "I am a ${ -&gt; foo }0" ' contains a GString-type expression: '${ -&gt; foo }'
310
+ ]]>
311
+ </Message>
312
+ </Violation>
313
+ </File>
314
+ <File name="SpaceAfterOpeningBraceRuleTest.groovy">
315
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="38">
316
+ <SourceLine>
317
+ <![CDATA[ final SOURCE = ''' ]]>
318
+ </SourceLine>
319
+ <Message>
320
+ <![CDATA[
321
+ The String ' class MyClass { def myMethod() { def closure = { } if (true) { } while(ready) { } try { } catch(Exception e) { } finally { } for(int i=0; i&lt;10; i++) { } for(String name in names) { } for(String name: names) { } if (count &gt; this."maxPriority${priority}Violations") { } while (count &gt; this."maxPriority${priority}Violations") { } } MyClass() { this(classNames) } MyClass(String s) { } MyClass(@Annotation('${prop}') String s) { } } interface MyInterface { } enum MyEnum { OK, BAD } trait MyTrait { } ' contains a GString-type expression: '${priority}Violations") { }'
322
+ ]]>
323
+ </Message>
324
+ </Violation>
325
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="81">
326
+ <SourceLine>
327
+ <![CDATA[ final SOURCE = ''' ]]>
328
+ </SourceLine>
329
+ <Message>
330
+ <![CDATA[
331
+ The String ' class MyClass { def myMethod() { def closure = {} if (true) {} while(ready) {} try { } catch(Exception e) { } finally {} for(int i=0; i&lt;10; i++) {} for(String name in names) {} for(String name: names) {} if (count &gt; this."maxPriority${priority}Violations") {} while (count &gt; this."maxPriority${priority}Violations") {} } void doStuff2() {} MyClass() {} MyClass(@Annotation('${prop}') String s) {} } interface MyInterface2 {} ' contains a GString-type expression: '${priority}Violations") {}'
332
+ ]]>
333
+ </Message>
334
+ </Violation>
335
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="175">
336
+ <SourceLine>
337
+ <![CDATA[ final SOURCE = ''' ]]>
338
+ </SourceLine>
339
+ <Message>
340
+ <![CDATA[
341
+ The String ' class MyClass { MyClass() {int count } MyClass() {s = '{"json": true}' } MyClass(@Annotation('${prop}') String s) {println 123 } } ' contains a GString-type expression: '${prop}') String s) {println 123 }'
342
+ ]]>
343
+ </Message>
344
+ </Violation>
345
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="186">
346
+ <SourceLine>
347
+ <![CDATA[
348
+ [lineNumber:5, sourceLineText:'MyClass(@Annotation(\'${prop}\') String s) {println 123 }', messageText:'The opening brace for the block in class MyClass'])
349
+ ]]>
350
+ </SourceLine>
351
+ <Message>
352
+ <![CDATA[
353
+ The String 'MyClass(@Annotation('${prop}') String s) {println 123 }' contains a GString-type expression: '${prop}') String s) {println 123 }'
354
+ ]]>
355
+ </Message>
356
+ </Violation>
357
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="304">
358
+ <SourceLine>
359
+ <![CDATA[ final SOURCE = ''' ]]>
360
+ </SourceLine>
361
+ <Message>
362
+ <![CDATA[
363
+ The String ' class MyClass { String s MyClass() { s = '{"json": true}' } MyClass(@Annotation('${prop}') String s) { println 123 } } ' contains a GString-type expression: '${prop}') String s) { println 123 }'
364
+ ]]>
365
+ </Message>
366
+ </Violation>
367
+ </File>
368
+ <File name="SpaceAroundMapEntryColonRuleTest.groovy">
369
+ <Violation ruleName="UnnecessaryReturnKeyword" priority="3" lineNumber="115">
370
+ <SourceLine>
371
+ <![CDATA[
372
+ return inlineViolation("The colon for the literal Map entry for key [$keyName] within class $className" +
373
+ ]]>
374
+ </SourceLine>
375
+ <Message>
376
+ <![CDATA[
377
+ The return keyword is not needed and can be removed
378
+ ]]>
379
+ </Message>
380
+ </Violation>
381
+ </File>
382
+ <File name="SpaceBeforeClosingBraceRuleTest.groovy">
383
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="39">
384
+ <SourceLine>
385
+ <![CDATA[ final SOURCE = ''' ]]>
386
+ </SourceLine>
387
+ <Message>
388
+ <![CDATA[
389
+ The String ' class MyClass { def myMethod() { def closure = { } if (true) { } while(ready) { } try { } catch(Exception e) { } finally { } for(int i=0; i&lt;10; i++) { } for(String name in names) { } for(String name: names) { } if (count &gt; this."maxPriority${priority}Violations") { } while (count &gt; this."maxPriority${priority}Violations") { } } MyClass() { this(classNames) } static void reset() { violationCounts = [1:0, 2:0, 3:0] } void doStuff() { println 9 } } interface MyInterface { } enum MyEnum { OK, BAD } ' contains a GString-type expression: '${priority}Violations") { }'
390
+ ]]>
391
+ </Message>
392
+ </Violation>
393
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="80">
394
+ <SourceLine>
395
+ <![CDATA[ final SOURCE = ''' ]]>
396
+ </SourceLine>
397
+ <Message>
398
+ <![CDATA[
399
+ The String ' class MyClass { def myMethod() { def closure = {} if (true) {} while(ready) {} try { } catch(Exception e) { } finally {} for(int i=0; i&lt;10; i++) {} for(String name in names) {} for(String name: names) {} if (count &gt; this."maxPriority${priority}Violations") {} while (count &gt; this."maxPriority${priority}Violations") {} } void doStuff2() {} } interface MyInterface2 {} ' contains a GString-type expression: '${priority}Violations") {}'
400
+ ]]>
401
+ </Message>
402
+ </Violation>
403
+ </File>
404
+ <File name="SpaceBeforeOpeningBraceRuleTest.groovy">
405
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="38">
406
+ <SourceLine>
407
+ <![CDATA[ final SOURCE = ''' ]]>
408
+ </SourceLine>
409
+ <Message>
410
+ <![CDATA[
411
+ The String ' class MyClass { def myMethod() { def closure = { } if (true) { } while(ready) { } try { } catch(Exception e) { } finally { } for(int i=0; i&lt;10; i++) { } for(String name in names) { } for(String name: names) { } if (count &gt; this."maxPriority${priority}Violations") { } while (count &gt; this."maxPriority${priority}Violations") { } } MyClass() { this(classNames) } } interface MyInterface { } enum MyEnum { OK, BAD } trait MyTrait { } ' contains a GString-type expression: '${priority}Violations") { }'
412
+ ]]>
413
+ </Message>
414
+ </Violation>
415
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="262">
416
+ <SourceLine>
417
+ <![CDATA[ assertNoViolations(''' ]]>
418
+ </SourceLine>
419
+ <Message>
420
+ <![CDATA[
421
+ The String ' def foo = 1 "I am a ${ -&gt; foo }" ' contains a GString-type expression: '${ -&gt; foo }'
422
+ ]]>
423
+ </Message>
424
+ </Violation>
425
+ </File>
426
+ </Package>
427
+ <Package path="generic" totalFiles="11" filesWithViolations="1" priority1="0" priority2="2" priority3="0">
428
+ <File name="IllegalPackageReferenceRuleTest.groovy">
429
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="64">
430
+ <SourceLine>
431
+ <![CDATA[ final SOURCE = ''' ]]>
432
+ </SourceLine>
433
+ <Message>
434
+ <![CDATA[
435
+ The String ' if (value.class == org.bad.BadClass) { } println "isClosure=${value instanceof org.bad.OtherClass}" def count = org.bad.Helper.getCount() ' contains a GString-type expression: '${value instanceof org.bad.OtherClass}'
436
+ ]]>
437
+ </Message>
438
+ </Violation>
439
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="72">
440
+ <SourceLine>
441
+ <![CDATA[
442
+ [lineNumber:3, sourceLineText:'println "isClosure=${value instanceof org.bad.OtherClass}"', messageText:'org.bad'],
443
+ ]]>
444
+ </SourceLine>
445
+ <Message>
446
+ <![CDATA[
447
+ The String 'println "isClosure=${value instanceof org.bad.OtherClass}"' contains a GString-type expression: '${value instanceof org.bad.OtherClass}'
448
+ ]]>
449
+ </Message>
450
+ </Violation>
451
+ </File>
452
+ </Package>
453
+ <Package path="grails" totalFiles="11" filesWithViolations="2" priority1="0" priority2="3" priority3="0">
454
+ <File name="GrailsMassAssignmentRuleTest.groovy">
455
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="36">
456
+ <SourceLine>
457
+ <![CDATA[ final SOURCE = ''' ]]>
458
+ </SourceLine>
459
+ <Message>
460
+ <![CDATA[
461
+ The String ' class Person { String name Boolean isAdmin } def bindingMap = [name: 'John', isAdmin: true] def person = new Person() def p2 = new Person("It is currently ${ new Date() }") def p3 = new Person(bindingMap) person.name = bindingMap['name'] person.isAdmin = bindingMap.isAdmin person.properties = "It is currently ${ new Date() }" ' contains a GString-type expression: '${ new Date() }'
462
+ ]]>
463
+ </Message>
464
+ </Violation>
465
+ </File>
466
+ <File name="GrailsServletContextReferenceRuleTest.groovy">
467
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="78">
468
+ <SourceLine>
469
+ <![CDATA[ final SOURCE = ''' ]]>
470
+ </SourceLine>
471
+ <Message>
472
+ <![CDATA[
473
+ The String ' class MyClass { def mySession = servletContext def edit = { println "amount=${servletContext.amount}" } } ' contains a GString-type expression: '${servletContext.amount}'
474
+ ]]>
475
+ </Message>
476
+ </Violation>
477
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="87">
478
+ <SourceLine>
479
+ <![CDATA[
480
+ assertTwoViolations(SOURCE, 3, 'def mySession = servletContext', 6, 'println "amount=${servletContext.amount}"')
481
+ ]]>
482
+ </SourceLine>
483
+ <Message>
484
+ <![CDATA[
485
+ The String 'println "amount=${servletContext.amount}"' contains a GString-type expression: '${servletContext.amount}'
486
+ ]]>
487
+ </Message>
488
+ </Violation>
489
+ </File>
490
+ </Package>
491
+ <Package path="groovyism" totalFiles="32" filesWithViolations="2" priority1="0" priority2="16" priority3="0">
492
+ <File name="GStringAsMapKeyRuleTest.groovy">
493
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="44">
494
+ <SourceLine>
495
+ <![CDATA[ final SOURCE = ''' ]]>
496
+ </SourceLine>
497
+ <Message>
498
+ <![CDATA[
499
+ The String ' Map map = ["${ someRef }" : 'invalid' ] ' contains a GString-type expression: '${ someRef }'
500
+ ]]>
501
+ </Message>
502
+ </Violation>
503
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="48">
504
+ <SourceLine>
505
+ <![CDATA[ 2, '["${ someRef }" :') ]]>
506
+ </SourceLine>
507
+ <Message>
508
+ <![CDATA[
509
+ The String '["${ someRef }" :' contains a GString-type expression: '${ someRef }'
510
+ ]]>
511
+ </Message>
512
+ </Violation>
513
+ </File>
514
+ <File name="GStringExpressionWithinStringRuleTest.groovy">
515
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="49">
516
+ <SourceLine>
517
+ <![CDATA[ final SOURCE = ''' ]]>
518
+ </SourceLine>
519
+ <Message>
520
+ <![CDATA[
521
+ The String ' class SomeClass { @SomeAnnotationOnField('${sample.property1}') String sampleProperty @SomeAnnotationOnMethod('${sample.property2}') void method() { } } ' contains a GString-type expression: '${sample.property1}'
522
+ ]]>
523
+ </Message>
524
+ </Violation>
525
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="64">
526
+ <SourceLine>
527
+ <![CDATA[ final SOURCE = ''' ]]>
528
+ </SourceLine>
529
+ <Message>
530
+ <![CDATA[
531
+ The String ' @SomeAnnotationOnClass('${sample.property1}') class SomeClass { @SomeAnnotationOnField('${sample.property2}') String sampleProperty @SomeAnnotationOnMethod('${sample.property3}') void method() { } } ' contains a GString-type expression: '${sample.property1}'
532
+ ]]>
533
+ </Message>
534
+ </Violation>
535
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="80">
536
+ <SourceLine>
537
+ <![CDATA[ final SOURCE = ''' ]]>
538
+ </SourceLine>
539
+ <Message>
540
+ <![CDATA[
541
+ The String ' @SomeAnnotationOnClass(attribute='${sample.property1}', nested=[@NestedAnnotation('${sample.property2}'), @NestedAnnotation('${sample.property3}')], someOtherAttribute='${sample.property4}') class SomeClass { } ' contains a GString-type expression: '${sample.property1}'
542
+ ]]>
543
+ </Message>
544
+ </Violation>
545
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="93">
546
+ <SourceLine>
547
+ <![CDATA[ final SOURCE = ''' ]]>
548
+ </SourceLine>
549
+ <Message>
550
+ <![CDATA[
551
+ The String ' @SomeAnnotationOnClass(attribute=['${sample.property1}', '${sample.property2}']) class SomeClass { } ' contains a GString-type expression: '${sample.property1}', '${sample.property2}'
552
+ ]]>
553
+ </Message>
554
+ </Violation>
555
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="103">
556
+ <SourceLine>
557
+ <![CDATA[ final SOURCE = ''' ]]>
558
+ </SourceLine>
559
+ <Message>
560
+ <![CDATA[
561
+ The String ' def valueToBeReplaced = '123' def str1 = "123" def str2 = "abc def ghi" def str3 = "abc ${count}" def str4 = "abc $count }" def str5 = "abc {123}" def str6 = "abc ${}" def str7 = "total: ${count * 25}" def str8 = "$valueToBeReplaced $valueNotToBeReplaced" ' contains a GString-type expression: '${count}'
562
+ ]]>
563
+ </Message>
564
+ </Violation>
565
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="119">
566
+ <SourceLine>
567
+ <![CDATA[ final SOURCE = ''' ]]>
568
+ </SourceLine>
569
+ <Message>
570
+ <![CDATA[
571
+ The String ' def "plugin does not apply idea plugin"() { given: buildScript &lt;&lt; """ task $testTaskName { doLast { println "Has idea plugin: \${project.plugins.hasPlugin(IdeaPlugin)}" } } """ expect: runTask(testTaskName).output.contains('Has idea plugin: false') where: testTaskName = 'hasIdeaPlugin' } ' contains a GString-type expression: '${project.plugins.hasPlugin(IdeaPlugin)}'
572
+ ]]>
573
+ </Message>
574
+ </Violation>
575
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="142">
576
+ <SourceLine>
577
+ <![CDATA[ final SOURCE = ''' ]]>
578
+ </SourceLine>
579
+ <Message>
580
+ <![CDATA[
581
+ The String ' def str1 = 'total: ${count}' def str2 = 'average: ${total / count}' ' contains a GString-type expression: '${count}'
582
+ ]]>
583
+ </Message>
584
+ </Violation>
585
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="147">
586
+ <SourceLine>
587
+ <![CDATA[
588
+ [lineNumber:2, sourceLineText:"def str1 = 'total: \${count}'", messageText:'\'${count}\''],
589
+ ]]>
590
+ </SourceLine>
591
+ <Message>
592
+ <![CDATA[
593
+ The String 'def str1 = 'total: ${count}'' contains a GString-type expression: '${count}'
594
+ ]]>
595
+ </Message>
596
+ </Violation>
597
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="147">
598
+ <SourceLine>
599
+ <![CDATA[
600
+ [lineNumber:2, sourceLineText:"def str1 = 'total: \${count}'", messageText:'\'${count}\''],
601
+ ]]>
602
+ </SourceLine>
603
+ <Message>
604
+ <![CDATA[
605
+ The String ''${count}'' contains a GString-type expression: '${count}'
606
+ ]]>
607
+ </Message>
608
+ </Violation>
609
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="148">
610
+ <SourceLine>
611
+ <![CDATA[
612
+ [lineNumber:3, sourceLineText:"def str2 = 'average: \${total / count}'", messageText:'\'${total / count}\''])
613
+ ]]>
614
+ </SourceLine>
615
+ <Message>
616
+ <![CDATA[
617
+ The String 'def str2 = 'average: ${total / count}'' contains a GString-type expression: '${total / count}'
618
+ ]]>
619
+ </Message>
620
+ </Violation>
621
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="148">
622
+ <SourceLine>
623
+ <![CDATA[
624
+ [lineNumber:3, sourceLineText:"def str2 = 'average: \${total / count}'", messageText:'\'${total / count}\''])
625
+ ]]>
626
+ </SourceLine>
627
+ <Message>
628
+ <![CDATA[
629
+ The String ''${total / count}'' contains a GString-type expression: '${total / count}'
630
+ ]]>
631
+ </Message>
632
+ </Violation>
633
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="153">
634
+ <SourceLine>
635
+ <![CDATA[ final SOURCE = ''' ]]>
636
+ </SourceLine>
637
+ <Message>
638
+ <![CDATA[
639
+ The String ' class SomeClass { @SomeAnnotationOnMethod('${sample.property}') void method() { def str1 = 'total: ${count}' } } ' contains a GString-type expression: '${sample.property}'
640
+ ]]>
641
+ </Message>
642
+ </Violation>
643
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="161">
644
+ <SourceLine>
645
+ <![CDATA[
646
+ assertSingleViolation(SOURCE, 5, "def str1 = 'total: \${count}'", '\'${count}\'')
647
+ ]]>
648
+ </SourceLine>
649
+ <Message>
650
+ <![CDATA[
651
+ The String 'def str1 = 'total: ${count}'' contains a GString-type expression: '${count}'
652
+ ]]>
653
+ </Message>
654
+ </Violation>
655
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="161">
656
+ <SourceLine>
657
+ <![CDATA[
658
+ assertSingleViolation(SOURCE, 5, "def str1 = 'total: \${count}'", '\'${count}\'')
659
+ ]]>
660
+ </SourceLine>
661
+ <Message>
662
+ <![CDATA[
663
+ The String ''${count}'' contains a GString-type expression: '${count}'
664
+ ]]>
665
+ </Message>
666
+ </Violation>
667
+ </File>
668
+ </Package>
669
+ <Package path="imports" totalFiles="7" filesWithViolations="1" priority1="0" priority2="1" priority3="0">
670
+ <File name="UnusedImportRuleTest.groovy">
671
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="192">
672
+ <SourceLine>
673
+ <![CDATA[ final SOURCE = ''' ]]>
674
+ </SourceLine>
675
+ <Message>
676
+ <![CDATA[
677
+ The String ' import test.TestData1 import test.TestData2 import test.TestData3 import test.TestData4 import test.TestData5 import test.TestData6 import test.TestData7 import test.TestData8 import test.TestData9 import test.TestData10 import test.TestData11 import test.TestData12 import test.TestData13 import test.TestData14 import test.TestData15 def GSTRING1 = " ${TestData1.GOOD_XML}" def GSTRING2 = " $TestData2.XML" def MAP1 = [(TestData3):123] def MAP2 = [abc:TestData4] def MAP3 = [abc:TestData5, ddd:123] def LIST = [TestData6,TestData7] def OPERATORS1 = 0+TestData8.VALUE-TestData9.VALUE def OPERATORS2 = 9*TestData10.VALUE/TestData11.VALUE def OPERATORS3 = 64&amp;TestData12.VALUE|TestData13.VALUE^TestData14.VALUE def OPERATORS4 = !TestData15.VALUE ' contains a GString-type expression: '${TestData1.GOOD_XML}'
678
+ ]]>
679
+ </Message>
680
+ </Violation>
681
+ </File>
682
+ </Package>
683
+ <Package path="jdbc" totalFiles="6" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
684
+ <Package path="junit" totalFiles="25" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
685
+ <Package path="logging" totalFiles="8" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
686
+ <Package path="naming" totalFiles="16" filesWithViolations="1" priority1="0" priority2="1" priority3="0">
687
+ <File name="FieldNameRuleTest.groovy">
688
+ <Violation ruleName="MethodCount" priority="2" lineNumber="28">
689
+ <SourceLine>
690
+ <![CDATA[
691
+ class FieldNameRuleTest extends AbstractRuleTestCase&lt;FieldNameRule&gt; {
692
+ ]]>
693
+ </SourceLine>
694
+ <Message>
695
+ <![CDATA[
696
+ Class org.codenarc.rule.naming.FieldNameRuleTest has 32 methods
697
+ ]]>
698
+ </Message>
699
+ </Violation>
700
+ </File>
701
+ </Package>
702
+ <Package path="security" totalFiles="10" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
703
+ <Package path="serialization" totalFiles="4" filesWithViolations="0" priority1="0" priority2="0" priority3="0"/>
704
+ <Package path="size" totalFiles="9" filesWithViolations="2" priority1="0" priority2="0" priority3="2">
705
+ <File name="GMetricsSourceCodeAdapterTest.groovy">
706
+ <Violation ruleName="MisorderedStaticImports" priority="3" lineNumber="22">
707
+ <SourceLine>
708
+ <![CDATA[
709
+ import static org.codenarc.test.TestUtil.shouldFailWithMessageContaining
710
+ ]]>
711
+ </SourceLine>
712
+ <Message>
713
+ <![CDATA[ Static imports should appear before normal imports ]]>
714
+ </Message>
715
+ </Violation>
716
+ </File>
717
+ <File name="ParameterCountRuleTest.groovy">
718
+ <Violation ruleName="UnnecessaryReturnKeyword" priority="3" lineNumber="252">
719
+ <SourceLine>
720
+ <![CDATA[
721
+ return inlineViolation("Number of parameters in ${name} exceeds maximum allowed (${rule.maxParameters}).")
722
+ ]]>
723
+ </SourceLine>
724
+ <Message>
725
+ <![CDATA[
726
+ The return keyword is not needed and can be removed
727
+ ]]>
728
+ </Message>
729
+ </Violation>
730
+ </File>
731
+ </Package>
732
+ <Package path="unnecessary" totalFiles="47" filesWithViolations="5" priority1="0" priority2="7" priority3="0">
733
+ <File name="ConsecutiveStringConcatenationRuleTest.groovy">
734
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="65">
735
+ <SourceLine>
736
+ <![CDATA[ final SOURCE = ''' ]]>
737
+ </SourceLine>
738
+ <Message>
739
+ <![CDATA[
740
+ The String ' def b = "$Hello" + 'World' // should be "${Hello}World" ' contains a GString-type expression: '${Hello}'
741
+ ]]>
742
+ </Message>
743
+ </Violation>
744
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="73">
745
+ <SourceLine>
746
+ <![CDATA[ final SOURCE = ''' ]]>
747
+ </SourceLine>
748
+ <Message>
749
+ <![CDATA[
750
+ The String ' def c = 'Hello' + "$World" // should be "Hello${World}" ' contains a GString-type expression: '${World}'
751
+ ]]>
752
+ </Message>
753
+ </Violation>
754
+ </File>
755
+ <File name="UnnecessaryGStringRuleTest.groovy">
756
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="36">
757
+ <SourceLine>
758
+ <![CDATA[ final SOURCE = ''' ]]>
759
+ </SourceLine>
760
+ <Message>
761
+ <![CDATA[
762
+ The String ' def docFile = "src/site/apt/codenarc-rules-${ruleSetName}.apt" ' contains a GString-type expression: '${ruleSetName}'
763
+ ]]>
764
+ </Message>
765
+ </Violation>
766
+ </File>
767
+ <File name="UnnecessaryGetterRuleTest.groovy">
768
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="148">
769
+ <SourceLine>
770
+ <![CDATA[ final SOURCE = ''' ]]>
771
+ </SourceLine>
772
+ <Message>
773
+ <![CDATA[
774
+ The String ' Mock { getSomeData() } Stub(1,2,3) { getData2() } "${'Stub'}"(MyClass) { getData3() } def closure = { getData4() } Mock({ getData5() }, 1234) // 2nd param is not a Closure ' contains a GString-type expression: '${'Stub'}'
775
+ ]]>
776
+ </Message>
777
+ </Violation>
778
+ </File>
779
+ <File name="UnnecessaryPackageReferenceRuleTest.groovy">
780
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="67">
781
+ <SourceLine>
782
+ <![CDATA[ final SOURCE = ''' ]]>
783
+ </SourceLine>
784
+ <Message>
785
+ <![CDATA[
786
+ The String ' if (value.class == java.math.BigDecimal) { } println "isClosure=${value instanceof groovy.lang.Closure}" def processors = java.lang.Runtime.availableProcessors() ' contains a GString-type expression: '${value instanceof groovy.lang.Closure}'
787
+ ]]>
788
+ </Message>
789
+ </Violation>
790
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="74">
791
+ <SourceLine>
792
+ <![CDATA[
793
+ [lineNumber:3, sourceLineText:'println "isClosure=${value instanceof groovy.lang.Closure}"', messageText:'groovy.lang'],
794
+ ]]>
795
+ </SourceLine>
796
+ <Message>
797
+ <![CDATA[
798
+ The String 'println "isClosure=${value instanceof groovy.lang.Closure}"' contains a GString-type expression: '${value instanceof groovy.lang.Closure}'
799
+ ]]>
800
+ </Message>
801
+ </Violation>
802
+ </File>
803
+ <File name="UnnecessarySetterRuleTest.groovy">
804
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="66">
805
+ <SourceLine>
806
+ <![CDATA[ final SOURCE = ''' ]]>
807
+ </SourceLine>
808
+ <Message>
809
+ <![CDATA[
810
+ The String ' if (!file.setExecutable(true)) { throw new Exception("Cannot set ${file} as executable") } def count = x.setCount(92) ' contains a GString-type expression: '${file}'
811
+ ]]>
812
+ </Message>
813
+ </Violation>
814
+ </File>
815
+ </Package>
816
+ <Package path="unused" totalFiles="7" filesWithViolations="5" priority1="0" priority2="11" priority3="0">
817
+ <File name="UnusedMethodParameterRuleTest.groovy">
818
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="135">
819
+ <SourceLine>
820
+ <![CDATA[ final SOURCE = ''' ]]>
821
+ </SourceLine>
822
+ <Message>
823
+ <![CDATA[
824
+ The String ' class MyClass { String myMethod1(String id, int value) { doSomething(value); return id } void myMethod2(int value) { def x = value } def myMethod3(Date startDate) { return "${startDate}" } def myMethod4(Date startDate) { return new Object() { def x = startDate } } def myMethod5(Date startDate) { return new Object() { String toString() { return startDate } } } } ' contains a GString-type expression: '${startDate}" }'
825
+ ]]>
826
+ </Message>
827
+ </Violation>
828
+ </File>
829
+ <File name="UnusedPrivateFieldRuleTest.groovy">
830
+ <Violation ruleName="MethodCount" priority="2" lineNumber="28">
831
+ <SourceLine>
832
+ <![CDATA[
833
+ class UnusedPrivateFieldRuleTest extends AbstractRuleTestCase&lt;UnusedPrivateFieldRule&gt; {
834
+ ]]>
835
+ </SourceLine>
836
+ <Message>
837
+ <![CDATA[
838
+ Class org.codenarc.rule.unused.UnusedPrivateFieldRuleTest has 32 methods
839
+ ]]>
840
+ </Message>
841
+ </Violation>
842
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="167">
843
+ <SourceLine>
844
+ <![CDATA[ final SOURCE = ''' ]]>
845
+ </SourceLine>
846
+ <Message>
847
+ <![CDATA[
848
+ The String ' class MyClass { private int count def other = this."${'count'}" } ' contains a GString-type expression: '${'count'}'
849
+ ]]>
850
+ </Message>
851
+ </Violation>
852
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="178">
853
+ <SourceLine>
854
+ <![CDATA[ final SOURCE = ''' ]]>
855
+ </SourceLine>
856
+ <Message>
857
+ <![CDATA[
858
+ The String ' class MyClass { private int count def varName = "count" def other = this."${varName}" // can't see this } ' contains a GString-type expression: '${varName}'
859
+ ]]>
860
+ </Message>
861
+ </Violation>
862
+ </File>
863
+ <File name="UnusedPrivateMethodParameterRuleTest.groovy">
864
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="111">
865
+ <SourceLine>
866
+ <![CDATA[ final SOURCE = ''' ]]>
867
+ </SourceLine>
868
+ <Message>
869
+ <![CDATA[
870
+ The String ' class MyClass { private String myMethod1(String id, int value) { doSomething(value); return id } private void myMethod2(int value) { def x = value } private def myMethod3(Date startDate) { return "${startDate}" } private def myMethod4(Date startDate) { return new Object() { def x = startDate } } private def myMethod5(Date startDate) { return new Object() { String toString() { return startDate } } } } ' contains a GString-type expression: '${startDate}" }'
871
+ ]]>
872
+ </Message>
873
+ </Violation>
874
+ </File>
875
+ <File name="UnusedPrivateMethodRuleTest.groovy">
876
+ <Violation ruleName="MethodCount" priority="2" lineNumber="26">
877
+ <SourceLine>
878
+ <![CDATA[
879
+ class UnusedPrivateMethodRuleTest extends AbstractRuleTestCase&lt;UnusedPrivateMethodRule&gt; {
880
+ ]]>
881
+ </SourceLine>
882
+ <Message>
883
+ <![CDATA[
884
+ Class org.codenarc.rule.unused.UnusedPrivateMethodRuleTest has 36 methods
885
+ ]]>
886
+ </Message>
887
+ </Violation>
888
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="354">
889
+ <SourceLine>
890
+ <![CDATA[ final SOURCE = ''' ]]>
891
+ </SourceLine>
892
+ <Message>
893
+ <![CDATA[
894
+ The String ' class MyClass { private int countStuff() { return 99 } int somePublicMethod() { } def abc = 'abc' private String getName() { 'abc' } private getPrice() { 0.0 } def doStuff() { def count = countStuff() def newName = this.getName() } def myClosure = { println "price is ${getPrice()}" } } ' contains a GString-type expression: '${getPrice()}" }'
895
+ ]]>
896
+ </Message>
897
+ </Violation>
898
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="423">
899
+ <SourceLine>
900
+ <![CDATA[ final SOURCE = ''' ]]>
901
+ </SourceLine>
902
+ <Message>
903
+ <![CDATA[
904
+ The String ' class MyClass { static int getTotal() { println "total=${MyClass.countStuff()}" } private static int countStuff() { } } ' contains a GString-type expression: '${MyClass.countStuff()}'
905
+ ]]>
906
+ </Message>
907
+ </Violation>
908
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="436">
909
+ <SourceLine>
910
+ <![CDATA[ final SOURCE = ''' ]]>
911
+ </SourceLine>
912
+ <Message>
913
+ <![CDATA[
914
+ The String ' class MyClass { private int countStuff() { } def other = this."${countStuff}"() } ' contains a GString-type expression: '${countStuff}'
915
+ ]]>
916
+ </Message>
917
+ </Violation>
918
+ <Violation ruleName="GStringExpressionWithinString" priority="2" lineNumber="458">
919
+ <SourceLine>
920
+ <![CDATA[ final SOURCE = ''' ]]>
921
+ </SourceLine>
922
+ <Message>
923
+ <![CDATA[
924
+ The String ' class MyClass { private int countStuff() { } def varName = "countStuff" def other = this."${varName}"() // can't see this } ' contains a GString-type expression: '${varName}'
925
+ ]]>
926
+ </Message>
927
+ </Violation>
928
+ </File>
929
+ <File name="UnusedVariableRuleTest.groovy">
930
+ <Violation ruleName="MethodCount" priority="2" lineNumber="26">
931
+ <SourceLine>
932
+ <![CDATA[
933
+ class UnusedVariableRuleTest extends AbstractRuleTestCase&lt;UnusedVariableRule&gt; {
934
+ ]]>
935
+ </SourceLine>
936
+ <Message>
937
+ <![CDATA[
938
+ Class org.codenarc.rule.unused.UnusedVariableRuleTest has 35 methods
939
+ ]]>
940
+ </Message>
941
+ </Violation>
942
+ </File>
943
+ </Package>
944
+ <Rules>
945
+ <Rule name="AbcMetric">
946
+ <Description>
947
+ <![CDATA[
948
+ Checks the ABC size metric for methods/classes. A method (or "closure field") with an ABC score greater than the maxMethodAbcScore property (60) causes a violation. Likewise, a class that has an (average method) ABC score greater than the maxClassAverageMethodAbcScore property (60) causes a violation.
949
+ ]]>
950
+ </Description>
951
+ </Rule>
952
+ <Rule name="AddEmptyString">
953
+ <Description>
954
+ <![CDATA[
955
+ Finds empty string literals which are being added. This is an inefficient way to convert any type to a String.
956
+ ]]>
957
+ </Description>
958
+ </Rule>
959
+ <Rule name="AssertWithinFinallyBlock">
960
+ <Description>
961
+ <![CDATA[
962
+ Checks for assert statements within a finally block. An assert can throw an exception, hiding the original exception, if there is one.
963
+ ]]>
964
+ </Description>
965
+ </Rule>
966
+ <Rule name="AssignCollectionSort">
967
+ <Description>
968
+ <![CDATA[
969
+ The Collections.sort() method mutates the list and returns the list as a value. If you are assigning the result of sort() to a variable, then you probably don't realize that you're also modifying the original list as well. This is frequently the cause of subtle bugs.
970
+ ]]>
971
+ </Description>
972
+ </Rule>
973
+ <Rule name="AssignCollectionUnique">
974
+ <Description>
975
+ <![CDATA[
976
+ The Collections.unique() method mutates the list and returns the list as a value. If you are assigning the result of unique() to a variable, then you probably don't realize that you're also modifying the original list as well. This is frequently the cause of subtle bugs.
977
+ ]]>
978
+ </Description>
979
+ </Rule>
980
+ <Rule name="AssignmentInConditional">
981
+ <Description>
982
+ <![CDATA[
983
+ An assignment operator (=) was used in a conditional test. This is usually a typo, and the comparison operator (==) was intended.
984
+ ]]>
985
+ </Description>
986
+ </Rule>
987
+ <Rule name="BigDecimalInstantiation">
988
+ <Description>
989
+ <![CDATA[
990
+ Checks for calls to the BigDecimal constructors that take a double parameter, which may result in an unexpected BigDecimal value.
991
+ ]]>
992
+ </Description>
993
+ </Rule>
994
+ <Rule name="BitwiseOperatorInConditional">
995
+ <Description>
996
+ <![CDATA[
997
+ Checks for bitwise operations in conditionals, if you need to do a bitwise operation then it is best practice to extract a temp variable.
998
+ ]]>
999
+ </Description>
1000
+ </Rule>
1001
+ <Rule name="BooleanGetBoolean">
1002
+ <Description>
1003
+ <![CDATA[
1004
+ This rule catches usages of java.lang.Boolean.getBoolean(String) which reads a boolean from the System properties. It is often mistakenly used to attempt to read user input or parse a String into a boolean. It is a poor piece of API to use; replace it with System.properties['prop'].
1005
+ ]]>
1006
+ </Description>
1007
+ </Rule>
1008
+ <Rule name="BrokenNullCheck">
1009
+ <Description>
1010
+ <![CDATA[
1011
+ Looks for faulty checks for null that can cause a NullPointerException.
1012
+ ]]>
1013
+ </Description>
1014
+ </Rule>
1015
+ <Rule name="BrokenOddnessCheck">
1016
+ <Description>
1017
+ <![CDATA[
1018
+ The code uses x % 2 == 1 to check to see if a value is odd, but this won't work for negative numbers (e.g., (-5) % 2 == -1). If this code is intending to check for oddness, consider using x &amp; 1 == 1, or x % 2 != 0.
1019
+ ]]>
1020
+ </Description>
1021
+ </Rule>
1022
+ <Rule name="ClassForName">
1023
+ <Description>
1024
+ <![CDATA[
1025
+ Using Class.forName(...) is a common way to add dynamic behavior to a system. However, using this method can cause resource leaks because the classes can be pinned in memory for long periods of time.
1026
+ ]]>
1027
+ </Description>
1028
+ </Rule>
1029
+ <Rule name="ClassSize">
1030
+ <Description>
1031
+ <![CDATA[
1032
+ Checks if the size of a class exceeds the number of lines specified by the maxLines property (1000).
1033
+ ]]>
1034
+ </Description>
1035
+ </Rule>
1036
+ <Rule name="ClosureAsLastMethodParameter">
1037
+ <Description>
1038
+ <![CDATA[
1039
+ If a method is called and the last parameter is an inline closure then it can be declared outside of the method call brackets.
1040
+ ]]>
1041
+ </Description>
1042
+ </Rule>
1043
+ <Rule name="CollectAllIsDeprecated">
1044
+ <Description>
1045
+ <![CDATA[
1046
+ collectAll{} is deprecated since Groovy 1.8.1. Use collectNested instead{}.
1047
+ ]]>
1048
+ </Description>
1049
+ </Rule>
1050
+ <Rule name="ComparisonOfTwoConstants">
1051
+ <Description>
1052
+ <![CDATA[
1053
+ Checks for expressions where a comparison operator or equals() or compareTo() is used to compare two constants to each other or two literals that contain only constant values, e.g.: 23 == 67, Boolean.FALSE != false, 0.17 &lt;= 0.99, "abc" &gt; "ddd", [a:1] &lt;=&gt; [a:2], [1,2].equals([3,4]) or [a:false, b:true].compareTo(['a':34.5, b:Boolean.TRUE], where x is a variable.
1054
+ ]]>
1055
+ </Description>
1056
+ </Rule>
1057
+ <Rule name="ComparisonWithSelf">
1058
+ <Description>
1059
+ <![CDATA[
1060
+ Checks for expressions where a comparison operator or equals() or compareTo() is used to compare a variable to itself, e.g.: x == x, x != x, x &lt;=&gt; x, x &lt; x, x &gt;= x, x.equals(x) or x.compareTo(x), where x is a variable.
1061
+ ]]>
1062
+ </Description>
1063
+ </Rule>
1064
+ <Rule name="ConfusingMultipleReturns">
1065
+ <Description>
1066
+ <![CDATA[
1067
+ Multiple return values can be used to set several variables at once. To use multiple return values, the left hand side of the assignment must be enclosed in parenthesis. If not, then you are not using multiple return values, you're only assigning the last element.
1068
+ ]]>
1069
+ </Description>
1070
+ </Rule>
1071
+ <Rule name="ConsecutiveLiteralAppends">
1072
+ <Description>
1073
+ <![CDATA[
1074
+ Violations occur when method calls to append(Object) are chained together with literals as parameters. The chained calls can be joined into one invocation.
1075
+ ]]>
1076
+ </Description>
1077
+ </Rule>
1078
+ <Rule name="ConsecutiveStringConcatenation">
1079
+ <Description>
1080
+ <![CDATA[
1081
+ Catches concatenation of two string literals on the same line. These can safely by joined.
1082
+ ]]>
1083
+ </Description>
1084
+ </Rule>
1085
+ <Rule name="ConstantAssertExpression">
1086
+ <Description>
1087
+ <![CDATA[
1088
+ Checks for assert statements where the assert boolean condition expression is a constant or literal value.
1089
+ ]]>
1090
+ </Description>
1091
+ </Rule>
1092
+ <Rule name="ConstantIfExpression">
1093
+ <Description>
1094
+ <![CDATA[
1095
+ Checks for if statements with a constant value for the if expression, such as true, false, null, or a literal constant value.
1096
+ ]]>
1097
+ </Description>
1098
+ </Rule>
1099
+ <Rule name="ConstantTernaryExpression">
1100
+ <Description>
1101
+ <![CDATA[
1102
+ Checks for ternary expressions with a constant value for the boolean expression, such as true, false, null, or a literal constant value.
1103
+ ]]>
1104
+ </Description>
1105
+ </Rule>
1106
+ <Rule name="CrapMetric">
1107
+ <Description>
1108
+ <![CDATA[
1109
+ Checks the CRAP (Change Risk Anti-Patterns) score for methods/classes. The CRAP metric score is based on the cyclomatic complexity and test coverage for individual methods. A method with a CRAP value greater than the maxMethodCrapScore property (30) causes a violation. Likewise, a class that has an (average method) CRAP value greater than the maxClassAverageMethodCrapScore property (30) causes a violation.
1110
+ ]]>
1111
+ </Description>
1112
+ </Rule>
1113
+ <Rule name="CyclomaticComplexity">
1114
+ <Description>
1115
+ <![CDATA[
1116
+ Checks the cyclomatic complexity for methods/classes.A method (or "closure field") with a cyclomatic complexity value greater than the maxMethodComplexity property (20) causes a violation. Likewise, a class that has an (average method) cyclomatic complexityvalue greater than the maxClassAverageMethodComplexity property (20) causes a violation.
1117
+ ]]>
1118
+ </Description>
1119
+ </Rule>
1120
+ <Rule name="DeadCode">
1121
+ <Description>
1122
+ <![CDATA[
1123
+ Dead code appears after a return statement or an exception is thrown. If code appears after one of these statements then it will never be executed and can be safely deleted.
1124
+ ]]>
1125
+ </Description>
1126
+ </Rule>
1127
+ <Rule name="DoubleNegative">
1128
+ <Description>
1129
+ <![CDATA[
1130
+ There is no point in using a double negative, it is always positive. For instance !!x can always be simplified to x. And !(!x) can as well.
1131
+ ]]>
1132
+ </Description>
1133
+ </Rule>
1134
+ <Rule name="DuplicateCaseStatement">
1135
+ <Description>
1136
+ <![CDATA[
1137
+ Check for duplicate case statements in a switch block, such as two equal integers or strings.
1138
+ ]]>
1139
+ </Description>
1140
+ </Rule>
1141
+ <Rule name="DuplicateImport">
1142
+ <Description>
1143
+ <![CDATA[ Duplicate import statements are unnecessary. ]]>
1144
+ </Description>
1145
+ </Rule>
1146
+ <Rule name="DuplicateMapKey">
1147
+ <Description>
1148
+ <![CDATA[
1149
+ A map literal is created with duplicated key. The map entry will be overwritten.
1150
+ ]]>
1151
+ </Description>
1152
+ </Rule>
1153
+ <Rule name="DuplicateSetValue">
1154
+ <Description>
1155
+ <![CDATA[
1156
+ A Set literal is created with duplicate constant value. A set cannot contain two elements with the same value.
1157
+ ]]>
1158
+ </Description>
1159
+ </Rule>
1160
+ <Rule name="EmptyCatchBlock">
1161
+ <Description>
1162
+ <![CDATA[
1163
+ In most cases, exceptions should not be caught and ignored (swallowed).
1164
+ ]]>
1165
+ </Description>
1166
+ </Rule>
1167
+ <Rule name="EmptyClass">
1168
+ <Description>
1169
+ <![CDATA[
1170
+ Reports classes without methods, fields or properties. Why would you need a class like this?
1171
+ ]]>
1172
+ </Description>
1173
+ </Rule>
1174
+ <Rule name="EmptyElseBlock">
1175
+ <Description>
1176
+ <![CDATA[
1177
+ Empty else blocks are confusing and serve no purpose.
1178
+ ]]>
1179
+ </Description>
1180
+ </Rule>
1181
+ <Rule name="EmptyFinallyBlock">
1182
+ <Description>
1183
+ <![CDATA[
1184
+ Empty finally blocks are confusing and serve no purpose.
1185
+ ]]>
1186
+ </Description>
1187
+ </Rule>
1188
+ <Rule name="EmptyForStatement">
1189
+ <Description>
1190
+ <![CDATA[
1191
+ Empty for statements are confusing and serve no purpose.
1192
+ ]]>
1193
+ </Description>
1194
+ </Rule>
1195
+ <Rule name="EmptyIfStatement">
1196
+ <Description>
1197
+ <![CDATA[
1198
+ Empty if statements are confusing and serve no purpose.
1199
+ ]]>
1200
+ </Description>
1201
+ </Rule>
1202
+ <Rule name="EmptyInstanceInitializer">
1203
+ <Description>
1204
+ <![CDATA[
1205
+ An empty class instance initializer was found. It is safe to remove it.
1206
+ ]]>
1207
+ </Description>
1208
+ </Rule>
1209
+ <Rule name="EmptyMethod">
1210
+ <Description>
1211
+ <![CDATA[
1212
+ A method was found without an implementation. If the method is overriding or implementing a parent method, then mark it with the @Override annotation.
1213
+ ]]>
1214
+ </Description>
1215
+ </Rule>
1216
+ <Rule name="EmptyStaticInitializer">
1217
+ <Description>
1218
+ <![CDATA[
1219
+ An empty static initializer was found. It is safe to remove it.
1220
+ ]]>
1221
+ </Description>
1222
+ </Rule>
1223
+ <Rule name="EmptySwitchStatement">
1224
+ <Description>
1225
+ <![CDATA[
1226
+ Empty switch statements are confusing and serve no purpose.
1227
+ ]]>
1228
+ </Description>
1229
+ </Rule>
1230
+ <Rule name="EmptySynchronizedStatement">
1231
+ <Description>
1232
+ <![CDATA[
1233
+ Empty synchronized statements are confusing and serve no purpose.
1234
+ ]]>
1235
+ </Description>
1236
+ </Rule>
1237
+ <Rule name="EmptyTryBlock">
1238
+ <Description>
1239
+ <![CDATA[
1240
+ Empty try blocks are confusing and serve no purpose.
1241
+ ]]>
1242
+ </Description>
1243
+ </Rule>
1244
+ <Rule name="EmptyWhileStatement">
1245
+ <Description>
1246
+ <![CDATA[
1247
+ Empty while statements are confusing and serve no purpose.
1248
+ ]]>
1249
+ </Description>
1250
+ </Rule>
1251
+ <Rule name="EqualsAndHashCode">
1252
+ <Description>
1253
+ <![CDATA[
1254
+ If either the equals(Object) or the hashCode() methods are overridden within a class, then both must be overridden.
1255
+ ]]>
1256
+ </Description>
1257
+ </Rule>
1258
+ <Rule name="EqualsOverloaded">
1259
+ <Description>
1260
+ <![CDATA[
1261
+ The class has an equals method, but the parameter of the method is not of type Object. It is not overriding equals but instead overloading it.
1262
+ ]]>
1263
+ </Description>
1264
+ </Rule>
1265
+ <Rule name="ExplicitArrayListInstantiation">
1266
+ <Description>
1267
+ <![CDATA[
1268
+ This rule checks for the explicit instantiation of a ArrayList using the no-arg constructor. In Groovy, it is best to write "new ArrayList()" as "[]", which creates the same object.
1269
+ ]]>
1270
+ </Description>
1271
+ </Rule>
1272
+ <Rule name="ExplicitCallToAndMethod">
1273
+ <Description>
1274
+ <![CDATA[
1275
+ This rule detects when the and(Object) method is called directly in code instead of using the &amp; operator. A groovier way to express this: a.and(b) is this: a &amp; b
1276
+ ]]>
1277
+ </Description>
1278
+ </Rule>
1279
+ <Rule name="ExplicitCallToCompareToMethod">
1280
+ <Description>
1281
+ <![CDATA[
1282
+ This rule detects when the compareTo(Object) method is called directly in code instead of using the &lt;=&gt;, &gt;, &gt;=, &lt;, and &lt;= operators. A groovier way to express this: a.compareTo(b) is this: a &lt;=&gt; b, or using the other operators.
1283
+ ]]>
1284
+ </Description>
1285
+ </Rule>
1286
+ <Rule name="ExplicitCallToDivMethod">
1287
+ <Description>
1288
+ <![CDATA[
1289
+ This rule detects when the div(Object) method is called directly in code instead of using the / operator. A groovier way to express this: a.div(b) is this: a / b
1290
+ ]]>
1291
+ </Description>
1292
+ </Rule>
1293
+ <Rule name="ExplicitCallToEqualsMethod">
1294
+ <Description>
1295
+ <![CDATA[
1296
+ This rule detects when the equals(Object) method is called directly in code instead of using the == or != operator. A groovier way to express this: a.equals(b) is this: a == b and a groovier way to express : !a.equals(b) is : a != b
1297
+ ]]>
1298
+ </Description>
1299
+ </Rule>
1300
+ <Rule name="ExplicitCallToGetAtMethod">
1301
+ <Description>
1302
+ <![CDATA[
1303
+ This rule detects when the getAt(Object) method is called directly in code instead of using the [] index operator. A groovier way to express this: a.getAt(b) is this: a[b]
1304
+ ]]>
1305
+ </Description>
1306
+ </Rule>
1307
+ <Rule name="ExplicitCallToLeftShiftMethod">
1308
+ <Description>
1309
+ <![CDATA[
1310
+ This rule detects when the leftShift(Object) method is called directly in code instead of using the &lt;&lt; operator. A groovier way to express this: a.leftShift(b) is this: a &lt;&lt; b
1311
+ ]]>
1312
+ </Description>
1313
+ </Rule>
1314
+ <Rule name="ExplicitCallToMinusMethod">
1315
+ <Description>
1316
+ <![CDATA[
1317
+ This rule detects when the minus(Object) method is called directly in code instead of using the - operator. A groovier way to express this: a.minus(b) is this: a - b
1318
+ ]]>
1319
+ </Description>
1320
+ </Rule>
1321
+ <Rule name="ExplicitCallToModMethod">
1322
+ <Description>
1323
+ <![CDATA[
1324
+ This rule detects when the mod(Object) method is called directly in code instead of using the % operator. A groovier way to express this: a.mod(b) is this: a % b
1325
+ ]]>
1326
+ </Description>
1327
+ </Rule>
1328
+ <Rule name="ExplicitCallToMultiplyMethod">
1329
+ <Description>
1330
+ <![CDATA[
1331
+ This rule detects when the minus(Object) method is called directly in code instead of using the * operator. A groovier way to express this: a.multiply(b) is this: a * b
1332
+ ]]>
1333
+ </Description>
1334
+ </Rule>
1335
+ <Rule name="ExplicitCallToOrMethod">
1336
+ <Description>
1337
+ <![CDATA[
1338
+ This rule detects when the or(Object) method is called directly in code instead of using the | operator. A groovier way to express this: a.or(b) is this: a | b
1339
+ ]]>
1340
+ </Description>
1341
+ </Rule>
1342
+ <Rule name="ExplicitCallToPlusMethod">
1343
+ <Description>
1344
+ <![CDATA[
1345
+ This rule detects when the plus(Object) method is called directly in code instead of using the + operator. A groovier way to express this: a.plus(b) is this: a + b
1346
+ ]]>
1347
+ </Description>
1348
+ </Rule>
1349
+ <Rule name="ExplicitCallToPowerMethod">
1350
+ <Description>
1351
+ <![CDATA[
1352
+ This rule detects when the power(Object) method is called directly in code instead of using the ** operator. A groovier way to express this: a.power(b) is this: a ** b
1353
+ ]]>
1354
+ </Description>
1355
+ </Rule>
1356
+ <Rule name="ExplicitCallToRightShiftMethod">
1357
+ <Description>
1358
+ <![CDATA[
1359
+ This rule detects when the rightShift(Object) method is called directly in code instead of using the &gt;&gt; operator. A groovier way to express this: a.rightShift(b) is this: a &gt;&gt; b
1360
+ ]]>
1361
+ </Description>
1362
+ </Rule>
1363
+ <Rule name="ExplicitCallToXorMethod">
1364
+ <Description>
1365
+ <![CDATA[
1366
+ This rule detects when the xor(Object) method is called directly in code instead of using the ^ operator. A groovier way to express this: a.xor(b) is this: a ^ b
1367
+ ]]>
1368
+ </Description>
1369
+ </Rule>
1370
+ <Rule name="ExplicitGarbageCollection">
1371
+ <Description>
1372
+ <![CDATA[
1373
+ Calls to System.gc(), Runtime.getRuntime().gc(), and System.runFinalization() are not advised. Code should have the same behavior whether the garbage collection is disabled using the option -Xdisableexplicitgc or not. Moreover, "modern" jvms do a very good job handling garbage collections. If memory usage issues unrelated to memory leaks develop within an application, it should be dealt with JVM options rather than within the code itself.
1374
+ ]]>
1375
+ </Description>
1376
+ </Rule>
1377
+ <Rule name="ExplicitHashMapInstantiation">
1378
+ <Description>
1379
+ <![CDATA[
1380
+ This rule checks for the explicit instantiation of a HashMap using the no-arg constructor. In Groovy, it is best to write "new HashMap()" as "[:]", which creates the same object.
1381
+ ]]>
1382
+ </Description>
1383
+ </Rule>
1384
+ <Rule name="ExplicitHashSetInstantiation">
1385
+ <Description>
1386
+ <![CDATA[
1387
+ This rule checks for the explicit instantiation of a HashSet using the no-arg constructor. In Groovy, it is best to write "new HashSet()" as "[] as Set", which creates the same object.
1388
+ ]]>
1389
+ </Description>
1390
+ </Rule>
1391
+ <Rule name="ExplicitLinkedHashMapInstantiation">
1392
+ <Description>
1393
+ <![CDATA[
1394
+ This rule checks for the explicit instantiation of a LinkedHashMap using the no-arg constructor. In Groovy, it is best to write "new LinkedHashMap()" as "[:]", which creates the same object.
1395
+ ]]>
1396
+ </Description>
1397
+ </Rule>
1398
+ <Rule name="ExplicitLinkedListInstantiation">
1399
+ <Description>
1400
+ <![CDATA[
1401
+ This rule checks for the explicit instantiation of a LinkedList using the no-arg constructor. In Groovy, it is best to write "new LinkedList()" as "[] as Queue", which creates the same object.
1402
+ ]]>
1403
+ </Description>
1404
+ </Rule>
1405
+ <Rule name="ExplicitStackInstantiation">
1406
+ <Description>
1407
+ <![CDATA[
1408
+ This rule checks for the explicit instantiation of a Stack using the no-arg constructor. In Groovy, it is best to write "new Stack()" as "[] as Stack", which creates the same object.
1409
+ ]]>
1410
+ </Description>
1411
+ </Rule>
1412
+ <Rule name="ExplicitTreeSetInstantiation">
1413
+ <Description>
1414
+ <![CDATA[
1415
+ This rule checks for the explicit instantiation of a TreeSet using the no-arg constructor. In Groovy, it is best to write "new TreeSet()" as "[] as SortedSet", which creates the same object.
1416
+ ]]>
1417
+ </Description>
1418
+ </Rule>
1419
+ <Rule name="ForLoopShouldBeWhileLoop">
1420
+ <Description>
1421
+ <![CDATA[
1422
+ A for loop without an init and update statement can be simplified to a while loop.
1423
+ ]]>
1424
+ </Description>
1425
+ </Rule>
1426
+ <Rule name="GStringAsMapKey">
1427
+ <Description>
1428
+ <![CDATA[
1429
+ A GString should not be used as a map key since its hashcode is not guaranteed to be stable. Consider calling key.toString().
1430
+ ]]>
1431
+ </Description>
1432
+ </Rule>
1433
+ <Rule name="GStringExpressionWithinString">
1434
+ <Description>
1435
+ <![CDATA[
1436
+ Check for regular (single quote) strings containing a GString-type expression (${...}).
1437
+ ]]>
1438
+ </Description>
1439
+ </Rule>
1440
+ <Rule name="GetterMethodCouldBeProperty">
1441
+ <Description>
1442
+ <![CDATA[
1443
+ If a class defines a public method that follows the Java getter notation, and returns a constant, then it is cleaner to provide a Groovy property for the value rather than a Groovy method.
1444
+ ]]>
1445
+ </Description>
1446
+ </Rule>
1447
+ <Rule name="GroovyLangImmutable">
1448
+ <Description>
1449
+ <![CDATA[
1450
+ The groovy.lang.Immutable annotation has been deprecated and replaced by groovy.transform.Immutable. Do not use the Immutable in groovy.lang.
1451
+ ]]>
1452
+ </Description>
1453
+ </Rule>
1454
+ <Rule name="HardCodedWindowsFileSeparator">
1455
+ <Description>
1456
+ <![CDATA[
1457
+ This rule finds usages of a Windows file separator within the constructor call of a File object. It is better to use the Unix file separator or use the File.separator constant.
1458
+ ]]>
1459
+ </Description>
1460
+ </Rule>
1461
+ <Rule name="HardCodedWindowsRootDirectory">
1462
+ <Description>
1463
+ <![CDATA[
1464
+ This rule find cases where a File object is constructed with a windows-based path. This is not portable, and using the File.listRoots() method is a better alternative.
1465
+ ]]>
1466
+ </Description>
1467
+ </Rule>
1468
+ <Rule name="ImportFromSamePackage">
1469
+ <Description>
1470
+ <![CDATA[
1471
+ An import of a class that is within the same package is unnecessary.
1472
+ ]]>
1473
+ </Description>
1474
+ </Rule>
1475
+ <Rule name="ImportFromSunPackages">
1476
+ <Description>
1477
+ <![CDATA[
1478
+ Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change.
1479
+ ]]>
1480
+ </Description>
1481
+ </Rule>
1482
+ <Rule name="IntegerGetInteger">
1483
+ <Description>
1484
+ <![CDATA[
1485
+ This rule catches usages of java.lang.Integer.getInteger(String, ...) which reads an Integer from the System properties. It is often mistakenly used to attempt to read user input or parse a String into an Integer. It is a poor piece of API to use; replace it with System.properties['prop'].
1486
+ ]]>
1487
+ </Description>
1488
+ </Rule>
1489
+ <Rule name="MethodCount">
1490
+ <Description>
1491
+ <![CDATA[
1492
+ A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects. The &lt;em&gt;maxMethods&lt;/em&gt; property (30) specifies the threshold.
1493
+ ]]>
1494
+ </Description>
1495
+ </Rule>
1496
+ <Rule name="MethodSize">
1497
+ <Description>
1498
+ <![CDATA[
1499
+ Checks if the size of a method exceeds the number of lines specified by the maxLines property (100).
1500
+ ]]>
1501
+ </Description>
1502
+ </Rule>
1503
+ <Rule name="MisorderedStaticImports">
1504
+ <Description>
1505
+ <![CDATA[
1506
+ Static imports should never be declared after nonstatic imports.
1507
+ ]]>
1508
+ </Description>
1509
+ </Rule>
1510
+ <Rule name="MultipleUnaryOperators">
1511
+ <Description>
1512
+ <![CDATA[
1513
+ Checks for multiple consecutive unary operators. These are confusing, and are likely typos and bugs.
1514
+ ]]>
1515
+ </Description>
1516
+ </Rule>
1517
+ <Rule name="NestedBlockDepth">
1518
+ <Description>
1519
+ <![CDATA[
1520
+ Checks for blocks or closures nested more than maxNestedBlockDepth (5) levels deep.
1521
+ ]]>
1522
+ </Description>
1523
+ </Rule>
1524
+ <Rule name="NoWildcardImports">
1525
+ <Description>
1526
+ <![CDATA[
1527
+ Wildcard imports, static or otherwise, should not be used.
1528
+ ]]>
1529
+ </Description>
1530
+ </Rule>
1531
+ <Rule name="ParameterCount">
1532
+ <Description>
1533
+ <![CDATA[
1534
+ Checks if the number of parameters in method/constructor exceeds the number of parameters specified by the maxParameters property.
1535
+ ]]>
1536
+ </Description>
1537
+ </Rule>
1538
+ <Rule name="RandomDoubleCoercedToZero">
1539
+ <Description>
1540
+ <![CDATA[
1541
+ The Math.random() method returns a double result greater than or equal to 0.0 and less than 1.0. If you coerce this result into an Integer or int, then it is coerced to zero. Casting the result to int, or assigning it to an int field is probably a bug.
1542
+ ]]>
1543
+ </Description>
1544
+ </Rule>
1545
+ <Rule name="RemoveAllOnSelf">
1546
+ <Description>
1547
+ <![CDATA[
1548
+ Don't use removeAll to clear a collection. If you want to remove all elements from a collection c, use c.clear, not c.removeAll(c). Calling c.removeAll(c) to clear a collection is less clear, susceptible to errors from typos, less efficient and for some collections, might throw a ConcurrentModificationException.
1549
+ ]]>
1550
+ </Description>
1551
+ </Rule>
1552
+ <Rule name="ReturnFromFinallyBlock">
1553
+ <Description>
1554
+ <![CDATA[
1555
+ Returning from a finally block is confusing and can hide the original exception.
1556
+ ]]>
1557
+ </Description>
1558
+ </Rule>
1559
+ <Rule name="ThrowExceptionFromFinallyBlock">
1560
+ <Description>
1561
+ <![CDATA[
1562
+ Throwing an exception from a finally block is confusing and can hide the original exception.
1563
+ ]]>
1564
+ </Description>
1565
+ </Rule>
1566
+ <Rule name="UnnecessaryBigDecimalInstantiation">
1567
+ <Description>
1568
+ <![CDATA[
1569
+ It is unnecessary to instantiate BigDecimal objects. Instead just use the decimal literal or the 'G' identifier to force the type, such as 123.45 or 123.45G.
1570
+ ]]>
1571
+ </Description>
1572
+ </Rule>
1573
+ <Rule name="UnnecessaryBigIntegerInstantiation">
1574
+ <Description>
1575
+ <![CDATA[
1576
+ It is unnecessary to instantiate BigInteger objects. Instead just use the literal with the 'G' identifier to force the type, such as 8G or 42G.
1577
+ ]]>
1578
+ </Description>
1579
+ </Rule>
1580
+ <Rule name="UnnecessaryBooleanExpression">
1581
+ <Description>
1582
+ <![CDATA[
1583
+ Checks for unnecessary boolean expressions, including ANDing (&amp;&amp;) or ORing (||) with true, false, null, or a Map/List/String/Number literal. Also checks for negation (!) of true, false, null, or a Map/List/String/Number literal.
1584
+ ]]>
1585
+ </Description>
1586
+ </Rule>
1587
+ <Rule name="UnnecessaryBooleanInstantiation">
1588
+ <Description>
1589
+ <![CDATA[
1590
+ Use Boolean.valueOf() for variable values or Boolean.TRUE and Boolean.FALSE for constant values instead of calling the Boolean() constructor directly or calling Boolean.valueOf(true) or Boolean.valueOf(false).
1591
+ ]]>
1592
+ </Description>
1593
+ </Rule>
1594
+ <Rule name="UnnecessaryCallForLastElement">
1595
+ <Description>
1596
+ <![CDATA[
1597
+ This rule checks for excessively verbose methods of accessing the last element of an array or list. For instance, it is possible to access the last element of an array by performing array[array.length - 1], in Groovy it is simpler to either call array.last() or array[-1]. The same is true for lists. This violation is triggered whenever a get, getAt, or array-style access is used with an object size check.
1598
+ ]]>
1599
+ </Description>
1600
+ </Rule>
1601
+ <Rule name="UnnecessaryCallToSubstring">
1602
+ <Description>
1603
+ <![CDATA[
1604
+ Calling String.substring(0) always returns the original string. This code is meaningless.
1605
+ ]]>
1606
+ </Description>
1607
+ </Rule>
1608
+ <Rule name="UnnecessaryCast">
1609
+ <Description>
1610
+ <![CDATA[ Checks for unnecessary cast operations ]]>
1611
+ </Description>
1612
+ </Rule>
1613
+ <Rule name="UnnecessaryCatchBlock">
1614
+ <Description>
1615
+ <![CDATA[
1616
+ Violations are triggered when a catch block does nothing but throw the original exception. In this scenario there is usually no need for a catch block, just let the exception be thrown from the original code. This condition frequently occurs when catching an exception for debugging purposes but then forgetting to take the catch statement out.
1617
+ ]]>
1618
+ </Description>
1619
+ </Rule>
1620
+ <Rule name="UnnecessaryCollectCall">
1621
+ <Description>
1622
+ <![CDATA[
1623
+ Some method calls to Object.collect(Closure) can be replaced with the spread operator. For instance, list.collect { it.multiply(2) } can be replaced by list*.multiply(2). Warning: if a collection is null, collect will return an empty list, while *. will return null.
1624
+ ]]>
1625
+ </Description>
1626
+ </Rule>
1627
+ <Rule name="UnnecessaryCollectionCall">
1628
+ <Description>
1629
+ <![CDATA[
1630
+ Useless call to collections. This call doesn't make sense. For any collection c, calling c.containsAll(c) should always be true, and c.retainAll(c) should have no effect.
1631
+ ]]>
1632
+ </Description>
1633
+ </Rule>
1634
+ <Rule name="UnnecessaryConstructor">
1635
+ <Description>
1636
+ <![CDATA[
1637
+ This rule detects when a constructor is not necessary; i.e., when there's only one constructor, it's public, has an empty body, and takes no arguments.
1638
+ ]]>
1639
+ </Description>
1640
+ </Rule>
1641
+ <Rule name="UnnecessaryDefInFieldDeclaration">
1642
+ <Description>
1643
+ <![CDATA[
1644
+ If a field has a visibility modifier or a type declaration, then the def keyword is unneeded. For instance, 'static def constraints = {}' is redundant and can be simplified to 'static constraints = {}.
1645
+ ]]>
1646
+ </Description>
1647
+ </Rule>
1648
+ <Rule name="UnnecessaryDefInMethodDeclaration">
1649
+ <Description>
1650
+ <![CDATA[
1651
+ If a method has a visibility modifier or a type declaration, then the def keyword is unneeded. For instance 'def private method() {}' is redundant and can be simplified to 'private method() {}'.
1652
+ ]]>
1653
+ </Description>
1654
+ </Rule>
1655
+ <Rule name="UnnecessaryDefInVariableDeclaration">
1656
+ <Description>
1657
+ <![CDATA[
1658
+ If a variable has a visibility modifier or a type declaration, then the def keyword is unneeded. For instance 'def private n = 2' is redundant and can be simplified to 'private n = 2'.
1659
+ ]]>
1660
+ </Description>
1661
+ </Rule>
1662
+ <Rule name="UnnecessaryDotClass">
1663
+ <Description>
1664
+ <![CDATA[
1665
+ To make a reference to a class, it is unnecessary to specify the '.class' identifier. For instance String.class can be shortened to String.
1666
+ ]]>
1667
+ </Description>
1668
+ </Rule>
1669
+ <Rule name="UnnecessaryDoubleInstantiation">
1670
+ <Description>
1671
+ <![CDATA[
1672
+ It is unnecessary to instantiate Double objects. Instead just use the double literal or the 'D' identifier to force the type, such as 123.45d or 0.42d.
1673
+ ]]>
1674
+ </Description>
1675
+ </Rule>
1676
+ <Rule name="UnnecessaryElseStatement">
1677
+ <Description>
1678
+ <![CDATA[
1679
+ When an if statement block ends with a return statement the else is unnecessary. The logic in the else branch can be run without being in a new scope.
1680
+ ]]>
1681
+ </Description>
1682
+ </Rule>
1683
+ <Rule name="UnnecessaryFinalOnPrivateMethod">
1684
+ <Description>
1685
+ <![CDATA[
1686
+ A private method is marked final. Private methods cannot be overridden, so marking it final is unnecessary.
1687
+ ]]>
1688
+ </Description>
1689
+ </Rule>
1690
+ <Rule name="UnnecessaryFloatInstantiation">
1691
+ <Description>
1692
+ <![CDATA[
1693
+ It is unnecessary to instantiate Float objects. Instead just use the float literal with the 'F' identifier to force the type, such as 123.45F or 0.42f.
1694
+ ]]>
1695
+ </Description>
1696
+ </Rule>
1697
+ <Rule name="UnnecessaryGString">
1698
+ <Description>
1699
+ <![CDATA[
1700
+ String objects should be created with single quotes, and GString objects created with double quotes. Creating normal String objects with double quotes is confusing to readers.
1701
+ ]]>
1702
+ </Description>
1703
+ </Rule>
1704
+ <Rule name="UnnecessaryGroovyImport">
1705
+ <Description>
1706
+ <![CDATA[
1707
+ A Groovy file does not need to include an import for classes from java.lang, java.util, java.io, java.net, groovy.lang and groovy.util, as well as the classes java.math.BigDecimal and java.math.BigInteger.
1708
+ ]]>
1709
+ </Description>
1710
+ </Rule>
1711
+ <Rule name="UnnecessaryIfStatement">
1712
+ <Description>
1713
+ <![CDATA[
1714
+ Checks for if statements where the if and else blocks (or subsequent fall-through to a return), are merely returning true and false constants. These cases can be replaced by a simple return statement.
1715
+ ]]>
1716
+ </Description>
1717
+ </Rule>
1718
+ <Rule name="UnnecessaryInstanceOfCheck">
1719
+ <Description>
1720
+ <![CDATA[
1721
+ This rule finds instanceof checks that cannot possibly evaluate to true. For instance, checking that (!variable instanceof String) will never be true because the result of a not expression is always a boolean.
1722
+ ]]>
1723
+ </Description>
1724
+ </Rule>
1725
+ <Rule name="UnnecessaryInstantiationToGetClass">
1726
+ <Description>
1727
+ <![CDATA[
1728
+ Avoid instantiating an object just to call getClass() on it; use the .class public member instead.
1729
+ ]]>
1730
+ </Description>
1731
+ </Rule>
1732
+ <Rule name="UnnecessaryIntegerInstantiation">
1733
+ <Description>
1734
+ <![CDATA[
1735
+ It is unnecessary to instantiate Integer objects. Instead just use the literal with the 'I' identifier to force the type, such as 8I or 42i.
1736
+ ]]>
1737
+ </Description>
1738
+ </Rule>
1739
+ <Rule name="UnnecessaryLongInstantiation">
1740
+ <Description>
1741
+ <![CDATA[
1742
+ It is unnecessary to instantiate Long objects. Instead just use the literal with the 'L' identifier to force the type, such as 8L or 42L.
1743
+ ]]>
1744
+ </Description>
1745
+ </Rule>
1746
+ <Rule name="UnnecessaryModOne">
1747
+ <Description>
1748
+ <![CDATA[
1749
+ Any expression mod 1 (exp % 1) is guaranteed to always return zero. This code is probably an error, and should be either (exp &amp; 1) or (exp % 2).
1750
+ ]]>
1751
+ </Description>
1752
+ </Rule>
1753
+ <Rule name="UnnecessaryNullCheck">
1754
+ <Description>
1755
+ <![CDATA[
1756
+ Groovy contains the safe dereference operator, which can be used in boolean conditional statements to safely replace explicit "x == null" tests.
1757
+ ]]>
1758
+ </Description>
1759
+ </Rule>
1760
+ <Rule name="UnnecessaryNullCheckBeforeInstanceOf">
1761
+ <Description>
1762
+ <![CDATA[
1763
+ There is no need to check for null before an instanceof; the instanceof keyword returns false when given a null argument.
1764
+ ]]>
1765
+ </Description>
1766
+ </Rule>
1767
+ <Rule name="UnnecessaryObjectReferences">
1768
+ <Description>
1769
+ <![CDATA[
1770
+ Violations are triggered when an excessive set of consecutive statements all reference the same variable. This can be made more readable by using a with or identity block.
1771
+ ]]>
1772
+ </Description>
1773
+ </Rule>
1774
+ <Rule name="UnnecessaryOverridingMethod">
1775
+ <Description>
1776
+ <![CDATA[
1777
+ The overriding method merely calls the same method defined in a superclass
1778
+ ]]>
1779
+ </Description>
1780
+ </Rule>
1781
+ <Rule name="UnnecessaryPackageReference">
1782
+ <Description>
1783
+ <![CDATA[
1784
+ Checks for explicit package reference for classes that Groovy imports by default, such as java.lang.String, java.util.Map and groovy.lang.Closure.
1785
+ ]]>
1786
+ </Description>
1787
+ </Rule>
1788
+ <Rule name="UnnecessaryParenthesesForMethodCallWithClosure">
1789
+ <Description>
1790
+ <![CDATA[
1791
+ If a method is called and the only parameter to that method is an inline closure then the parentheses of the method call can be omitted.
1792
+ ]]>
1793
+ </Description>
1794
+ </Rule>
1795
+ <Rule name="UnnecessaryPublicModifier">
1796
+ <Description>
1797
+ <![CDATA[
1798
+ The 'public' modifier is not required on methods or classes.
1799
+ ]]>
1800
+ </Description>
1801
+ </Rule>
1802
+ <Rule name="UnnecessaryReturnKeyword">
1803
+ <Description>
1804
+ <![CDATA[
1805
+ In Groovy, the return keyword is often optional. If a statement is the last line in a method or closure then you do not need to have the return keyword.
1806
+ ]]>
1807
+ </Description>
1808
+ </Rule>
1809
+ <Rule name="UnnecessarySafeNavigationOperator">
1810
+ <Description>
1811
+ <![CDATA[
1812
+ Check for the safe navigation operator (?.) applied to constants and literals, which can never be null.
1813
+ ]]>
1814
+ </Description>
1815
+ </Rule>
1816
+ <Rule name="UnnecessarySelfAssignment">
1817
+ <Description>
1818
+ <![CDATA[
1819
+ Method contains a pointless self-assignment to a variable or property.
1820
+ ]]>
1821
+ </Description>
1822
+ </Rule>
1823
+ <Rule name="UnnecessarySemicolon">
1824
+ <Description>
1825
+ <![CDATA[
1826
+ Semicolons as line terminators are not required in Groovy: remove them. Do not use a semicolon as a replacement for empty braces on for and while loops; this is a confusing practice.
1827
+ ]]>
1828
+ </Description>
1829
+ </Rule>
1830
+ <Rule name="UnnecessarySetter">
1831
+ <Description>
1832
+ <![CDATA[
1833
+ Checks for explicit calls to setter methods which can, for the most part, be replaced by assignment to property. A setter is defined as a method call that matches set[A-Z] but not set[A-Z][A-Z] such as setURL(). Setters take one method argument.
1834
+ ]]>
1835
+ </Description>
1836
+ </Rule>
1837
+ <Rule name="UnnecessaryStringInstantiation">
1838
+ <Description>
1839
+ <![CDATA[
1840
+ Use a String literal (e.g., "...") instead of calling the corresponding String constructor (new String("..")) directly.
1841
+ ]]>
1842
+ </Description>
1843
+ </Rule>
1844
+ <Rule name="UnnecessarySubstring">
1845
+ <Description>
1846
+ <![CDATA[
1847
+ This rule finds usages of String.substring(int) and String.substring(int, int) that can be replaced by use of the subscript operator. For instance, var.substring(5) can be replaced with var[5..-1].
1848
+ ]]>
1849
+ </Description>
1850
+ </Rule>
1851
+ <Rule name="UnnecessaryTernaryExpression">
1852
+ <Description>
1853
+ <![CDATA[
1854
+ Checks for ternary expressions where the conditional expression always evaluates to a boolean and the true and false expressions are merely returning true and false constants. Also checks for ternary expressions where both expressions are the same constant or variable.
1855
+ ]]>
1856
+ </Description>
1857
+ </Rule>
1858
+ <Rule name="UnnecessaryToString">
1859
+ <Description>
1860
+ <![CDATA[ Checks for unnecessary calls to toString(). ]]>
1861
+ </Description>
1862
+ </Rule>
1863
+ <Rule name="UnnecessaryTransientModifier">
1864
+ <Description>
1865
+ <![CDATA[
1866
+ The field is marked as transient, but the class isn't Serializable, so marking it as transient has no effect.
1867
+ ]]>
1868
+ </Description>
1869
+ </Rule>
1870
+ <Rule name="UnusedImport">
1871
+ <Description>
1872
+ <![CDATA[
1873
+ Imports for a class that is never referenced within the source file is unnecessary.
1874
+ ]]>
1875
+ </Description>
1876
+ </Rule>
1877
+ <Rule name="UseCollectMany">
1878
+ <Description>
1879
+ <![CDATA[
1880
+ In many case collectMany() yields the same result as collect{}.flatten(). It is easier to understand and more clearly conveys the intent.
1881
+ ]]>
1882
+ </Description>
1883
+ </Rule>
1884
+ <Rule name="UseCollectNested">
1885
+ <Description>
1886
+ <![CDATA[
1887
+ Instead of nested collect{}-calls use collectNested{}
1888
+ ]]>
1889
+ </Description>
1890
+ </Rule>
1891
+ </Rules>
1892
+ </CodeNarc>