File: codenarc-rules-generic.html

package info (click to toggle)
codenarc 0.23-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,316 kB
  • sloc: java: 2,530; xml: 1,088; makefile: 13
file content (489 lines) | stat: -rw-r--r-- 32,707 bytes parent folder | download | duplicates (3)
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- Generated by Apache Maven Doxia Site Renderer 1.4 at 18 Feb 2015 -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>CodeNarc - CodeNarc - Generic Rules</title>
    <style type="text/css" media="all">
      @import url("./css/maven-base.css");
      @import url("./css/maven-theme.css");
      @import url("./css/site.css");
    </style>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
    <meta name="Date-Revision-yyyymmdd" content="20150218" />
    <meta http-equiv="Content-Language" content="en" />
                  
        </head>
  <body class="composite">
    <div id="banner">
                                              <a href="./" id="bannerLeft">
                                                <img src="images/codenarc-logo.png" alt="CodeNarc" />
                </a>
                              <a href="http://github.com/CodeNarc" id="bannerRight">
                                                <img src="images/forkme_right_red_aa0000.png" alt="Fork me on GitHub" />
                </a>
            <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="breadcrumbs">
            
                    
                <div class="xleft">
        <span id="publishDate">Last Published: 18 Feb 2015</span>
                  &nbsp;| <span id="projectVersion">Version: 0.23</span>
                      </div>
            <div class="xright">        
                    
      </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="leftColumn">
      <div id="navcolumn">
             
                    
                                <h5>General</h5>
                  <ul>
                  <li class="none">
                          <a href="index.html" title="Home">Home</a>
            </li>
                  <li class="none">
                          <a href="https://sourceforge.net/project/showfiles.php?group_id=250145" class="externalLink" title="Downloads">Downloads</a>
            </li>
                  <li class="none">
                          <a href="apidocs/index.html" title="Javadocs">Javadocs</a>
            </li>
                  <li class="none">
                          <a href="http://sourceforge.net/mail/?group_id=250145" class="externalLink" title="Mailing Lists">Mailing Lists</a>
            </li>
                  <li class="none">
                          <a href="http://sourceforge.net/tracker/?group_id=250145" class="externalLink" title="Bug Tracker">Bug Tracker</a>
            </li>
                  <li class="none">
                          <a href="http://sourceforge.net/projects/codenarc" class="externalLink" title="SourceForge Project">SourceForge Project</a>
            </li>
                  <li class="none">
                          <a href="http://github.com/CodeNarc" class="externalLink" title="GitHub Project">GitHub Project</a>
            </li>
          </ul>
                       <h5>Running</h5>
                  <ul>
                  <li class="none">
                          <a href="codenarc-ant-task.html" title="Ant Task Usage">Ant Task Usage</a>
            </li>
                  <li class="none">
                          <a href="codenarc-command-line.html" title="Command-Line">Command-Line</a>
            </li>
                  <li class="none">
                          <a href="codenarc-run-as-a-test.html" title="Run as a Test">Run as a Test</a>
            </li>
                  <li class="none">
                          <a href="codenarc-other-tools-frameworks.html" title="Other Tools/Frameworks">Other Tools/Frameworks</a>
            </li>
          </ul>
                       <h5>Using</h5>
                  <ul>
                  <li class="none">
                          <a href="codenarc-creating-ruleset.html" title="Creating a RuleSet">Creating a RuleSet</a>
            </li>
                  <li class="none">
                          <a href="codenarc-creating-rule.html" title="Creating a Rule">Creating a Rule</a>
            </li>
                  <li class="none">
                          <a href="codenarc-configuring-rules.html" title="Configuring Rules">Configuring Rules</a>
            </li>
                  <li class="none">
                          <a href="StarterRuleSet-AllRulesByCategory.groovy.txt" title="Starter RuleSet (All)">Starter RuleSet (All)</a>
            </li>
          </ul>
                       <h5>Report Types</h5>
                  <ul>
                  <li class="none">
                          <a href="codenarc-HtmlReportWriter.html" title="HTML Report">HTML Report</a>
            </li>
                  <li class="none">
                          <a href="codenarc-XmlReportWriter.html" title="XML Report">XML Report</a>
            </li>
                  <li class="none">
                          <a href="codenarc-TextReportWriter.html" title="Text and IDE Reports">Text and IDE Reports</a>
            </li>
          </ul>
                       <h5>Sample Reports</h5>
                  <ul>
                  <li class="none">
                          <a href="SampleCodeNarcHtmlReport.html" title="Sample HTML Report">Sample HTML Report</a>
            </li>
                  <li class="none">
                          <a href="SampleCodeNarcXmlReport.xml" title="Sample XML Report">Sample XML Report</a>
            </li>
          </ul>
                       <h5>Rules</h5>
                  <ul>
                  <li class="none">
                          <a href="codenarc-rule-index.html" title="Rule Index">Rule Index</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-basic.html" title="Basic Rules">Basic Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-braces.html" title="Braces Rules">Braces Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-concurrency.html" title="Concurrency Rules">Concurrency Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-convention.html" title="Convention Rules">Convention Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-design.html" title="Design Rules">Design Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-dry.html" title="DRY Rules">DRY Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-enhanced.html" title="Enhanced Rules">Enhanced Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-exceptions.html" title="Exceptions Rules">Exceptions Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-formatting.html" title="Formatting Rules">Formatting Rules</a>
            </li>
                  <li class="none">
            <strong>Generic Rules</strong>
          </li>
                  <li class="none">
                          <a href="codenarc-rules-grails.html" title="Grails Rules">Grails Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-groovyism.html" title="Groovyism Rules">Groovyism Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-imports.html" title="Imports Rules">Imports Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-jdbc.html" title="JDBC Rules">JDBC Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-junit.html" title="JUnit Rules">JUnit Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-logging.html" title="Logging Rules">Logging Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-naming.html" title="Naming Rules">Naming Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-size.html" title="Size/Complexity Rules">Size/Complexity Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-security.html" title="Security Rules">Security Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-serialization.html" title="Serialization Rules">Serialization Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-unnecessary.html" title="Unnecessary Rules">Unnecessary Rules</a>
            </li>
                  <li class="none">
                          <a href="codenarc-rules-unused.html" title="Unused Rules">Unused Rules</a>
            </li>
          </ul>
                       <h5>Developing</h5>
                  <ul>
                  <li class="none">
                          <a href="codenarc-developer-guide.html" title="Developer Guide">Developer Guide</a>
            </li>
          </ul>
                       <h5>Project Documentation</h5>
                  <ul>
                                                                    <li class="collapsed">
                          <a href="project-info.html" title="Project Information">Project Information</a>
                  </li>
                                                                                                                          <li class="collapsed">
                          <a href="project-reports.html" title="Project Reports">Project Reports</a>
                  </li>
          </ul>
                                                                                                                               <a href="http://sourceforge.net" title="Hosted on SourceForge.net" class="poweredBy">
        <img class="poweredBy"  alt="Hosted on SourceForge.net" src="http://sflogo.sourceforge.net/sflogo.php?group_id=208647&type=2"     />
      </a>
                                                                                                                      <a href="http://maven.apache.org" title="Build with Maven 2" class="poweredBy">
        <img class="poweredBy"  alt="Build with Maven 2" src="images/logos/maven-feather.png"     />
      </a>
                       
                    
            </div>
    </div>
    <div id="bodyColumn">
      <div id="contentBox">
        <div class="section">
<h2>Generic Rules (&quot;<i>rulesets/generic.xml</i>&quot;)<a name="Generic_Rules_rulesetsgeneric.xml"></a></h2><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p>These rules provide a generic check that only makes sense when customized. These rules are not <i>enabled</i> until the necessary configuration is provided.</p>
<p>See <a class="externalLink" href="http://tenpercentnotcrap.wordpress.com/2013/08/04/codenarc-hidden-gems-using-codenarcs-generic-rules/">CodeNarc &#x2013; Hidden Gems: Using CodeNarc&#x2019;s generic rules</a> for examples of using the <b>CodeNarc</b> <i>&quot;generic&quot;</i> rules to enforce your own custom best practices.</p>
<div class="section">
<h3><a name="IllegalClassMember">IllegalClassMember</a> Rule<a name="IllegalClassMember_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.19</i></p>
<p>Checks for classes containing fields/properties/methods matching configured illegal member modifiers or not matching any of the configured allowed member modifiers.</p>
<table border="1" class="bodyTable">
<tr class="a">
<td align="left"><b>Property</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Default Value</b></td></tr>
<tr class="b">
<td align="left">allowedFieldModifiers</td>
<td align="left">Specifies one or more groups of whitespace-delimited modifier names (e.g. &quot;public static&quot; or &quot;protected&quot;). Multiple groups are separated by commas (e.g. &quot;private final, protected&quot;). If a field does not match all of the modifiers in any group, then trigger a violation. If <tt>null</tt> or empty, skip this check.</td>
<td align="left"><tt>null</tt></td></tr>
<tr class="a">
<td align="left">allowedMethodModifiers</td>
<td align="left">Specifies one or more groups of whitespace-delimited modifier names (e.g. &quot;public static&quot; or &quot;protected&quot;). Multiple groups are separated by commas (e.g. &quot;private final, protected&quot;). If a method does not match all of the modifiers in any group, then trigger a violation. If <tt>null</tt> or empty, skip this check.</td>
<td align="left"><tt>null</tt></td></tr>
<tr class="b">
<td align="left">allowedPropertyModifiers</td>
<td align="left">Specifies one or more groups of whitespace-delimited modifier names (e.g. &quot;public static&quot; or &quot;protected&quot;). Multiple groups are separated by commas (e.g. &quot;private final, protected&quot;). If a property does not match all of the modifiers in any group, then trigger a violation. If <tt>null</tt> or empty, skip this check.</td>
<td align="left"><tt>null</tt></td></tr>
<tr class="a">
<td align="left">ignoreMethodNames</td>
<td align="left">Specifies one or more (comma-separated) method names that should be ignored (i.e., that should not cause a rule violation). The names may optionally contain wildcards (*,?).</td>
<td align="left"><tt>null</tt></td></tr>
<tr class="b">
<td align="left">ignoreMethodsWith- AnnotationNames</td>
<td align="left">Specifies one or more (comma-separated) annotation names that should be ignored (i.e., methods with those annotations should not cause a rule violation). The names may optionally contain wildcards (*,?). (Do not include the &quot;@&quot; in the annotation name.</td>
<td align="left"><tt>null</tt></td></tr>
<tr class="a">
<td align="left">illegalFieldModifiers</td>
<td align="left">Specifies one or more groups of whitespace-delimited modifier names (e.g. &quot;public static&quot; or &quot;protected&quot;). Multiple groups are separated by commas (e.g. &quot;private final, protected&quot;). If a field matches all of the modifiers in any group, then trigger a violation. If <tt>null</tt> or empty, skip this check.</td>
<td align="left"><tt>null</tt></td></tr>
<tr class="b">
<td align="left">illegalMethodModifiers</td>
<td align="left">Specifies one or more groups of whitespace-delimited modifier names (e.g. &quot;public static&quot; or &quot;protected&quot;). Multiple groups are separated by commas (e.g. &quot;private final, protected&quot;). If a method matches all of the modifiers in any group, then trigger a violation. If <tt>null</tt> or empty, skip this check.</td>
<td align="left"><tt>null</tt></td></tr>
<tr class="a">
<td align="left">illegalPropertyModifiers</td>
<td align="left">Specifies one or more groups of whitespace-delimited modifier names (e.g. &quot;public static&quot; or &quot;protected&quot;). Multiple groups are separated by commas (e.g. &quot;private final, protected&quot;). If a property matches all of the modifiers in any group, then trigger a violation. If <tt>null</tt> or empty, skip this check.</td>
<td align="left"><tt>null</tt></td></tr></table>
<p>Modifiers for fields and methods include:</p>
<ul>
<li>public</li>
<li>protected</li>
<li>private</li>
<li>static</li>
<li>final</li>
<li>volatile (fields only)</li>
<li>transient (fields only)</li></ul>
<p>Modifiers for properties are only:</p>
<ul>
<li>static</li>
<li>final</li></ul>
<p>Note that you must use the standard rule properties, such as <tt>applyToClassNames</tt>, <tt>doNotApplyToFileNames</tt> and <tt>applyToFilesMatching</tt> to apply this rule to a subset of all classes/files. These rule properties are described in <a href="./codenarc-configuring-rules.html#Standard_Properties_for_Configuring_Rules"> Standard Properties for Configuring Rules</a>.</p>
<p>Example of violations for methods:</p>
<div>
<pre>    // IllegalClassMember.allowedMethodModifiers = 'public final, private, protected static'

    class MyClass {
        public method1() { }            // violation
        protected method2() { }         // violation
        protected static method3() { }
    }
</pre></div>
<p>Example of violations for properties:</p>
<div>
<pre>    // IllegalClassMember.illegalPropertyModifiers = 'final'

    class MyClass {
        def property1
        final property2         // violation
        static property3
    }
</pre></div>
<p>A RuleSet can contain any number of instances of this rule, but each should be configured with a unique rule <i>name</i> and <i>classNames</i>, and (optionally) customized <i>violationMessage</i> and <i>priority</i>.</p>
<div class="section">
<h4>Notes<a name="Notes"></a></h4><!-- ~~~~~~~~~~ -->
<ol style="list-style-type: decimal">
<li>At least one the <tt>illegalFieldModifiers</tt>, <tt>allowedFieldModifiers</tt>, <tt>illegalPropertyModifiers</tt>, <tt>allowedPropertyModifiers</tt>, <tt>illegalMethodModifiers</tt> or <tt>allowedMethodModifiers</tt> properties must be set (i.e., not null or empty) or else this rule does nothing. In other words, you must configure this rule with at least one kind of illegal or allowed class member.</li>
<li>At least one of the (standard) <tt>applyToClassNames</tt>, <tt>applyToFileNames</tt> or <tt>applyToFilesMatching</tt> properties must be set (i.e., not null or empty) or else this rule does nothing. In other words, you must configure this rule to apply to a specific set of classes or files.</li></ol></div></div>
<div class="section">
<h3><a name="IllegalClassReference">IllegalClassReference</a> Rule<a name="IllegalClassReference_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.15</i></p>
<p>Checks for reference to any of the classes configured in <tt>classNames</tt>.</p>
<table border="1" class="bodyTable">
<tr class="a">
<td align="left"><b>Property</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Default Value</b></td></tr>
<tr class="b">
<td align="left">classNames</td>
<td align="left">Specifies the comma-separated list of (fully-qualified) class names. The class name(s) may optionally include wildcard characters ('*' or '?'). Note that the '*' wildcard matches any sequence of zero or more characters in the class/package name, e.g. 'a.*.MyClass' matches <tt>a.b.MyClass</tt> as well as <tt>a.b.c.d.MyClass</tt>. If <tt>classNames</tt> is null or empty, do nothing.</td>
<td align="left"><tt>null</tt></td></tr></table>
<p>Note that you can use the standard rule properties, such as <tt>applyToClassNames</tt>, <tt>doNotApplyToFileNames</tt> and <tt>applyToFilesMatching</tt> to only apply this rule to a subset of all classes/files. These rule properties are described in <a href="./codenarc-configuring-rules.html#Standard_Properties_for_Configuring_Rules"> Standard Properties for Configuring Rules</a>.</p>
<p>This rule can be useful for governance and enforcement of <i>architectural layering</i>. For instance, making sure that view or model classes, for instance, do not contain references to DAO classes (e.g., *Dao).</p>
<p>Here is an example configuration of this rule used to ensure that DAO classes are not referenced from within model classes:</p>
<div class="source">
<pre>    ruleset {
        description &quot;Example CodeNarc Ruleset&quot;

        // ...

        IllegalClassReference {
            name = 'DoNotReferenceDaoFromModelClasses'
            priority = 2
            classNames = '*Dao'
            applyToClassNames = 'com.example.model.*'
            description = 'Do not reference DAOs from model classes.'
        }
    }
</pre></div>
<p>A RuleSet can contain any number of instances of this rule, but each should be configured with a unique rule <i>name</i> and <i>classNames</i>, and (optionally) customized <i>violationMessage</i> and <i>priority</i>.</p></div>
<div class="section">
<h3><a name="IllegalPackageReference">IllegalPackageReference</a> Rule<a name="IllegalPackageReference_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.14</i></p>
<p>Checks for reference to any of the packages configured in <tt>packageNames</tt>.</p>
<table border="1" class="bodyTable">
<tr class="a">
<td align="left"><b>Property</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Default Value</b></td></tr>
<tr class="b">
<td align="left">packageNames</td>
<td align="left">Specifies the comma-separated list of package names. The package name(s) may optionally include wildcard characters ('*' or '?'). Note that the '*' wildcard matches any sequence of zero or more characters in the package name, e.g. 'a.*' matches 'a.b' as well as 'a.b.c.d'. If <tt>packageNames</tt> is null or empty, do nothing.</td>
<td align="left"><tt>null</tt></td></tr></table>
<p>Note that you can use the standard rule properties, such as <tt>applyToClassNames</tt>, <tt>doNotApplyToFileNames</tt> and <tt>applyToFilesMatching</tt> to only apply this rule to a subset of all classes/files. These rule properties are described in <a href="./codenarc-configuring-rules.html#Standard_Properties_for_Configuring_Rules"> Standard Properties for Configuring Rules</a>.</p>
<p>This rule can be useful for governance and enforcement of <i>architectural layering</i>. For instance, making sure that view or model classes, for instance, do not contain references to JDBC-specific packages (e.g. java.sql and javax.sql).</p>
<p>Here is an example configuration of this rule used to ensure that JDBC packages/classes are only referenced within DAO classes:</p>
<div class="source">
<pre>    ruleset {
        description &quot;Example CodeNarc Ruleset&quot;

        // ...

        IllegalPackageReference {
            name = 'UseJdbcOnlyInDaoClasses'
            priority = 2
            packageNames = 'groovy.sql, java.sql, javax.sql'
            doNotApplyToClassNames = 'com.example.framework.dao.*, *Dao, *DaoImpl'
            description = 'Reference to JDBC packages should be restricted to DAO classes.'
        }
    }
</pre></div>
<p>A RuleSet can contain any number of instances of this rule, but each should be configured with a unique rule <i>name</i> and <i>packageNames</i>, and (optionally) customized <i>violationMessage</i> and <i>priority</i>.</p></div>
<div class="section">
<h3><a name="IllegalRegex">IllegalRegex</a> Rule<a name="IllegalRegex_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p>Checks for a specified illegal regular expression within the source code.</p>
<table border="1" class="bodyTable">
<tr class="a">
<td align="left"><b>Property</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Default Value</b></td></tr>
<tr class="b">
<td align="left">regex</td>
<td align="left">The regular expression to check for. If null or empty then do nothing.</td>
<td align="left"><tt>null</tt></td></tr></table>
<p>A RuleSet can contain any number of instances of this rule, but each should be configured with a unique rule <i>name</i> and <i>regex</i>, and (optionally) customized <i>violationMessage</i> and <i>priority</i>.</p>
<p><b>NOTE:</b> This rule applies to the text contents of an entire <i>file</i> rather than a specific <i>class</i>, so it does not support the <i>applyToClassNames</i> and <i>doNotApplyToClassNames</i> configuration properties.</p></div>
<div class="section">
<h3><a name="IllegalString">IllegalString</a> Rule<a name="IllegalString_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.20</i></p>
<p>Checks for a specified illegal string within the source code.</p>
<table border="1" class="bodyTable">
<tr class="a">
<td align="left"><b>Property</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Default Value</b></td></tr>
<tr class="b">
<td align="left">string</td>
<td align="left">The String to check for. If null or empty then do nothing.</td>
<td align="left"><tt>null</tt></td></tr></table>
<p>A RuleSet can contain any number of instances of this rule, but each should be configured with a unique rule <i>name</i> and <i>string</i>, and (optionally) customized <i>violationMessage</i> and <i>priority</i>.</p>
<p><b>NOTE:</b> This rule applies to the text contents of an entire <i>file</i> rather than a specific <i>class</i>, so it does not support the <i>applyToClassNames</i> and <i>doNotApplyToClassNames</i> configuration properties.</p></div>
<div class="section">
<h3><a name="IllegalSubclass">IllegalSubclass</a> Rule<a name="IllegalSubclass_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.21</i></p>
<p>Checks for classes that extend one of the specified set of illegal superclasses.</p>
<table border="1" class="bodyTable">
<tr class="a">
<td align="left"><b>Property</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Default Value</b></td></tr>
<tr class="b">
<td align="left">superclassNames</td>
<td align="left">Specifies the comma-separated list of (fully-qualified) class names. The class name(s) may optionally include wildcard characters ('*' or '?'). Note that the '*' wildcard matches any sequence of zero or more characters in the class/package name, e.g. 'a.*.MyClass' matches <tt>a.b.MyClass</tt> as well as <tt>a.b.c.d.MyClass</tt>. If <tt>classNames</tt> is null or empty, do nothing.</td>
<td align="left"><tt>null</tt></td></tr></table>
<p>A RuleSet can contain any number of instances of this rule, but each should be configured with a unique rule <i>name</i> and <i>string</i>, and (optionally) customized <i>violationMessage</i> and <i>priority</i>.</p></div>
<div class="section">
<h3><a name="RequiredRegex">RequiredRegex</a> Rule<a name="RequiredRegex_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p>Checks for a specified regular expression that must exist within the source code.</p>
<table border="1" class="bodyTable">
<tr class="a">
<td align="left"><b>Property</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Default Value</b></td></tr>
<tr class="b">
<td align="left">regex</td>
<td align="left">The regular expression to check for. If null or empty then do nothing.</td>
<td align="left"><tt>null</tt></td></tr></table>
<p>A RuleSet can contain any number of instances of this rule, but each should be configured with a unique rule <i>name</i> and <i>regex</i>, and (optionally) customized <i>violationMessage</i> and <i>priority</i>.</p>
<p><b>NOTE:</b> This rule applies to the text contents of an entire <i>file</i> rather than a specific <i>class</i>, so it does not support the <i>applyToClassNames</i> and <i>doNotApplyToClassNames</i> configuration properties.</p></div>
<div class="section">
<h3><a name="RequiredString">RequiredString</a> Rule<a name="RequiredString_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p>Checks for a specified text string that must exist within the source code.</p>
<table border="1" class="bodyTable">
<tr class="a">
<td align="left"><b>Property</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Default Value</b></td></tr>
<tr class="b">
<td align="left">string</td>
<td align="left">The String to check for. If null or empty then do nothing.</td>
<td align="left"><tt>null</tt></td></tr></table>
<p>A RuleSet can contain any number of instances of this rule, but each should be configured with a unique rule <i>name</i> and <i>string</i>, and (optionally) customized <i>violationMessage</i> and <i>priority</i>.</p>
<p><b>NOTE:</b> This rule applies to the text contents of an entire <i>file</i> rather than a specific <i>class</i>, so it does not support the <i>applyToClassNames</i> and <i>doNotApplyToClassNames</i> configuration properties.</p></div>
<div class="section">
<h3><a name="StatelessClass">StatelessClass</a> Rule<a name="StatelessClass_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~ -->
<p>Checks for non-<tt>final</tt> fields on a class. The intent of this rule is to check a configured set of classes that should remain &quot;stateless&quot; and reentrant. One example might be Grails service classes which are singletons, by default, and so they should be reentrant.</p>
<p>This rule ignores <tt>final</tt> fields (either instance or static). Fields that are <tt>static</tt> and non-<tt>final</tt>, however, do cause a violation.</p>
<p>This rule also ignores all classes annotated with the <tt>@Immutable</tt> transformation. See <a class="externalLink" href="http://groovy.codehaus.org/Immutable+transformation">http://groovy.codehaus.org/Immutable+transformation</a>.</p>
<p>This rule also ignores all fields annotated with the <tt>@Inject</tt> annotation.</p>
<p>You can configure this rule to ignore certain fields either by name or by type. This can be useful to ignore fields that hold references to (static) dependencies (such as DAOs or Service objects) or static configuration.</p>
<table border="1" class="bodyTable">
<tr class="a">
<td align="left"><b>Property</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Default Value</b></td></tr>
<tr class="b">
<td align="left">ignoreFieldNames</td>
<td align="left">Specifies one or more (comma-separated) field names that should be ignored (i.e., that should not cause a rule violation). The names may optionally contain wildcards (*,?).</td>
<td align="left"><tt>null</tt></td></tr>
<tr class="a">
<td align="left">addToIgnoreFieldNames</td>
<td align="left">Specifies one or more (comma-separated) field names to be added to the <tt>ignoreFieldNames</tt> property value. This is a special write-only property, and each call to <tt>setAddIgnoreFieldNames()</tt> adds to (rather than overwrites) the list of field names to be ignored.</td>
<td align="left"><tt>null</tt></td></tr>
<tr class="b">
<td align="left">ignoreFieldTypes</td>
<td align="left">Specifies one or more (comma-separated) field types that should be ignored (i.e., that should not cause a rule violation). The names may optionally contain wildcards (*,?).</td>
<td align="left"><tt>null</tt></td></tr></table>
<p>Note that you can use the standard rule properties, such as <tt>applyToClassNames</tt>, <tt>doNotApplyToFileNames</tt> and <tt>applyToFilesMatching</tt> to only apply this rule to a subset of all classes/files. These rule properties are described in <a href="./codenarc-configuring-rules.html#Standard_Properties_for_Configuring_Rules"> Standard Properties for Configuring Rules</a>.</p>
<div class="section">
<h4>Notes<a name="Notes"></a></h4><!-- ~~~~~~~~~~ -->
<ol style="list-style-type: decimal">
<li>The <tt>ignoreFieldTypes</tt> property matches the field type name as indicated in the field declaration, only including a full package specification IF it is included in the source code. For example, the field declaration <tt>BigDecimal value</tt> matches an <tt>ignoreFieldTypes</tt> value of <tt>BigDecimal</tt>, but not <tt>java.lang.BigDecimal</tt>.</li>
<li>There is one exception for the <tt>ignoreFieldTypes</tt> property: if the field is declared with a modifier/type of <tt>def</tt>, then the type resolves to <tt>java.lang.Object</tt>.</li>
<li>At least one of the (standard) <tt>applyToClassNames</tt>, <tt>applyToFileNames</tt> or <tt>applyToFilesMatching</tt> properties must be set (i.e., not null or empty) or else this rule does nothing. In other words, you must configure this rule to apply to a specific set of classes or files.</li>
<li>This rule will not catch violations of true <i>statelessness</i>/<i>reentrancy</i> if you define a <tt>final</tt> field whose value is itself mutable, e.g. a <tt>final HashMap</tt>.</li></ol></div></div></div>
      </div>
    </div>
    <div class="clear">
      <hr/>
    </div>
    <div id="footer">
      <div class="xright">
              Copyright &#169;                   2015.
          All Rights Reserved.      
                    
                  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
  </body>
</html>