File: codenarc-rules-formatting.html

package info (click to toggle)
codenarc 0.23-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 11,312 kB
  • sloc: java: 2,530; xml: 1,088; makefile: 21
file content (656 lines) | stat: -rw-r--r-- 35,618 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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
<!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 - Formatting 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">
            <strong>Formatting Rules</strong>
          </li>
                  <li class="none">
                          <a href="codenarc-rules-generic.html" title="Generic Rules">Generic Rules</a>
            </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>Formatting Rules (&quot;<i>rulesets/formatting.xml</i>&quot;)<a name="Formatting_Rules_rulesetsformatting.xml"></a></h2><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<div class="section">
<h3><a name="BlankLineBeforePackage">BlankLineBeforePackage</a> Rule<a name="BlankLineBeforePackage_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.21</i></p>
<p>Makes sure there are no blank lines before the package declaration of a source code file.</p></div>
<div class="section">
<h3><a name="BracesForClass">BracesForClass</a> Rule<a name="BracesForClass_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.15</i></p>
<p>Checks the location of the opening brace ({) for classes. By default, requires them on the same line, but the <tt>sameLine</tt> property can be set to false to override this.</p>
<p>NOTE: This rule ignores annotation types, e.g. <tt>@interface MyAnnotation <a name="a"></a></tt>.</p></div>
<div class="section">
<h3><a name="BracesForForLoop">BracesForForLoop</a> Rule<a name="BracesForForLoop_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.15</i></p>
<p>Checks the location of the opening brace ({) for for loops. By default, requires them on the same line, but the <tt>sameLine</tt> property can be set to false to override this.</p></div>
<div class="section">
<h3><a name="BracesForIfElse">BracesForIfElse</a> Rule<a name="BracesForIfElse_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.15</i></p>
<p>Checks the location of the opening brace ({) for if statements. By default, requires them on the same line, but the <tt>sameLine</tt> property can be set to false to override this.</p></div>
<div class="section">
<h3><a name="BracesForMethod">BracesForMethod</a> Rule<a name="BracesForMethod_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.15</i></p>
<p>Checks the location of the opening brace ({) for constructors and methods. By default, requires them on the same line, but the <tt>sameLine</tt> property can be set to false to override this.</p></div>
<div class="section">
<h3><a name="BracesForTryCatchFinally">BracesForTryCatchFinally</a> Rule<a name="BracesForTryCatchFinally_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.15</i></p>
<p>Checks the location of the opening brace ({) for try statements. By default, requires them on the line, but the <tt>sameLine</tt> property can be set to false to override this.</p></div>
<div class="section">
<h3><a name="ClassJavadoc">ClassJavadoc</a> Rule<a name="ClassJavadoc_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.15</i></p>
<p>Makes sure each class and interface definition is preceded by javadoc. Enum definitions are not checked, due to strange behavior in the Groovy AST. By default, only the main class in a file is checked for Javadoc. The main class is defined as the class that has the same name as the source file, for instance MyClass is the main class in MyClass.groovy but the class MyOtherClass defined in the same source file is not the main class. To check all the classes in the file set the rule property <tt>applyToNonMainClasses</tt> to true.</p></div>
<div class="section">
<h3><a name="ClosureStatementOnOpeningLineOfMultipleLineClosure">ClosureStatementOnOpeningLineOfMultipleLineClosure</a> Rule<a name="ClosureStatementOnOpeningLineOfMultipleLineClosure_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.20</i></p>
<p>Checks for closure logic on first line (after <tt>-&gt;</tt>) for a multi-line closure. That breaks the symmetry of indentation (if the subsequent statements are indented normally), and that first statement can be easily missed when reading the code.</p>
<p>Example of violations:</p>
<div>
<pre>    def closure = { name -&gt; println name
        addToCounts()
        println &#x201c;done&#x201d; }
</pre></div></div>
<div class="section">
<h3><a name="ConsecutiveBlankLines">ConsecutiveBlankLines</a> Rule<a name="ConsecutiveBlankLines_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.21</i></p>
<p>Makes sure there are no consecutive lines that are either blank or whitespace only. This reduces the need to scroll further than necessary when reading code, and increases the likelihood that a logical block of code will fit on one screen for easier comprehension.</p>
<p>Example of violation:</p>
<div>
<pre>    def name


    def value



    def id
</pre></div></div>
<div class="section">
<h3><a name="FileEndsWithoutNewline">FileEndsWithoutNewline</a> Rule<a name="FileEndsWithoutNewline_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.21</i></p>
<p>Makes sure each source file ends with a newline character.</p></div>
<div class="section">
<h3><a name="LineLength">LineLength</a> Rule<a name="LineLength_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.15</i></p>
<p>Checks the maximum length for each line of source code. It checks for number of characters, so lines that include tabs may appear longer than the allowed number when viewing the file. The maximum line length can be configured by setting the length property, which defaults to 120.</p>
<p>NOTE: This rule does not support the @SuppressAnnotations annotation or the classname-based rule properties (applyToClassNames, doNotApplyToClassNames) to enable/disable the rule. If you want to specify or restrict where this rule is applied, you must use the file-based rule properties: applyToFileNames, doNotApplyToFileNames, applyToFilesMatching and doNotApplyToFilesMatching.</p></div>
<div class="section">
<h3><a name="MissingBlankLineAfterImports">MissingBlankLineAfterImports</a> Rule<a name="MissingBlankLineAfterImports_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.21</i></p>
<p>Makes sure there is a blank line after the imports of a source code file.</p>
<p>Example of violation:</p>
<div>
<pre>    import org.apache.commons.lang.StringUtils
    class MyClass { }                       // violation
</pre></div></div>
<div class="section">
<h3><a name="MissingBlankLineAfterPackage">MissingBlankLineAfterPackage</a> Rule<a name="MissingBlankLineAfterPackage_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.21</i></p>
<p>Makes sure there is a blank line after the package statement of a source code file.</p>
<p>Example of violation:</p>
<div>
<pre>  package org.codenarc
  import java.util.Date                     // violation

  class MyClass {
      void go() { /* ... */ }
  }
</pre></div></div>
<div class="section">
<h3><a name="SpaceAfterCatch">SpaceAfterCatch</a> Rule<a name="SpaceAfterCatch_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is exactly one space (blank) after the <tt>catch</tt> keyword and before the opening parenthesis.</p>
<p>Examples of violations:</p>
<div>
<pre>    try { } catch(Exception e) { }          // violation
    try { } catch  (Exception e) { }        // violation
</pre></div></div>
<div class="section">
<h3><a name="SpaceAfterComma">SpaceAfterComma</a> Rule<a name="SpaceAfterComma_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Checks that there is at least one space or whitespace following each comma. That includes checks for method and closure declaration parameter lists, method call parameter lists, Map literals and List literals.</p>
<p>Known limitations:</p>
<ul>
<li>May not catch actual violations if the source line contains unicode character literals, e.g. <tt>'\u00A0'</tt></li></ul>
<p>Examples of violations:</p>
<div>
<pre>    def value = calculate(1,399, 'abc')         // violation on parameter 399

    def method1(int a,String b) { }             // violation on parameter b

    def closure1 = { int a,String b -&gt; }        // violation on parameter b

    def list1 = [a,b, c]                        // violation on list element b

    def map1 = [a:1,b:2, c:3]                   // violation on map element b:2
</pre></div></div>
<div class="section">
<h3><a name="SpaceAfterClosingBrace">SpaceAfterClosingBrace</a> Rule<a name="SpaceAfterClosingBrace_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is at least one space (blank) or whitespace after each closing brace (&quot;{&quot;) for method/class/interface declarations, closure expressions and block statements.</p>
<p>A closure expression followed by a dot operator (.), a comma, a closing parenthesis, the spread-dot operator (*.), a semicolon or the null-safe operator (?.) does not cause a violation.</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">checkClosureMapEntryValue</td>
<td align="left">If <tt>false</tt>, then do not check for whitespace after closing braces for closure expressions that are literal Map values, e.g. <tt>[abc:<a name="doStuff">doStuff()</a>]</tt>.</td>
<td align="left"><tt>true</tt></td></tr></table>
<p>Known limitations:</p>
<ul>
<li>May not catch actual violations if the source line contains unicode character literals, e.g. <tt>'\u00A0'</tt></li></ul>
<p>Examples of violations and exceptions:</p>
<div>
<pre>    if (ready) { return 9 }else { }             // violation
    try { doStuff() }finally { }                // violation

    def matching = list.find { it.isReady() }.filter()  // no violation for dot operator
    assert list.every { it.isReady() }, &quot;Error&quot;         // no violation for comma
    def m = [a:123, b:{ println 7 },c:99]               // no violation for comma
    processItems(list.select { it.isReady() })          // no violation for closing parenthesis
    def names = records.findAll { it.age &gt; 1 }*.name    // no violation for spread operator
    list?.collect { it?.type }?.join(',')               // no violation for null-safe operator
</pre></div></div>
<div class="section">
<h3><a name="SpaceAfterFor">SpaceAfterFor</a> Rule<a name="SpaceAfterFor_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is exactly one space (blank) after the <tt>for</tt> keyword and before the opening parenthesis.</p>
<p>Examples of violations:</p>
<div>
<pre>    for(name in names) { }                  // violation
    for  (int i=0; i &lt; 10; i++) { }         // violation
</pre></div></div>
<div class="section">
<h3><a name="SpaceAfterIf">SpaceAfterIf</a> Rule<a name="SpaceAfterIf_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is exactly one space (blank) after the <tt>if</tt> keyword and before the opening parenthesis.</p>
<p>Examples of violations:</p>
<div>
<pre>    if(true) { }                            // violation
    if  (true) { }                          // violation
</pre></div></div>
<div class="section">
<h3><a name="SpaceAfterOpeningBrace">SpaceAfterOpeningBrace</a> Rule<a name="SpaceAfterOpeningBrace_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is at least one space (blank) or whitespace after each opening brace (&quot;{&quot;) for method/class/interface declarations, closure expressions and block statements.</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">checkClosureMapEntryValue</td>
<td align="left">If <tt>false</tt>, then do not check for whitespace after opening braces for closure expressions that are literal Map values, e.g. <tt>[abc:<a name="doStuff">doStuff()</a>]</tt>.</td>
<td align="left"><tt>true</tt></td></tr>
<tr class="a">
<td align="left">ignoreEmptyBlock</td>
<td align="left">If <tt>true</tt>, then allow for <tt>[<a name="a"></a>]</tt> in code</td>
<td align="left"><tt>false</tt></td></tr></table>
<p>Examples of violations:</p>
<div>
<pre>    class MyClass{int count }                   // violation

    interface MyInterface {static final OK = 1 }// violation

    enum MyEnum {OK, BAD }                      // violation

    def myMethod() {int count }                 // violation

    if (ready) {println 9 }                     // violation

    if (ready) {
    } else {println 99}                         // violation

    for (int i=0; i&lt;10; i++) {println i }       // violation

    for (String name in names) {println name }  // violation

    for (String name: names) {println name }    // violation

    while (ready) {println time }               // violation

    try {doStuff()                              // violation
    } catch(Exception e) {x=77 }                // violation
    } finally {println 'error' }                // violation

    list.each {name -&gt; }                        // violation

    shouldFail(Exception) {doStuff() }          // violation
</pre></div></div>
<div class="section">
<h3><a name="SpaceAfterSemicolon">SpaceAfterSemicolon</a> Rule<a name="SpaceAfterSemicolon_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is at least one space (blank) or whitespace following a semicolon that separates:</p>
<ul>
<li>multiple statements on a single line</li>
<li>the clauses within a classic for loop, e.g. for (i=0;i&lt;10;i++)</li></ul>
<p>Examples of violations:</p>
<div>
<pre>    def myMethod() {
        println 1;println 2                         // violation
        def closure = { x -&gt; doStuff();x = 23; }    // violation

        for (int i=0;i &lt; 10;i++) {                  // violations (2)
            for (int j=0; j &lt; 10;j++) { }           // violation
        }
    }
</pre></div></div>
<div class="section">
<h3><a name="SpaceAfterSwitch">SpaceAfterSwitch</a> Rule<a name="SpaceAfterSwitch_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is exactly one space (blank) after the <tt>switch</tt> keyword and before the opening parenthesis.</p>
<p>Examples of violations:</p>
<div>
<pre>    switch(x) {                                 // violation
        case 1: println 'one'
    }
    switch  (x) {                               // violation
        case 1: println 'one'
    }
</pre></div></div>
<div class="section">
<h3><a name="SpaceAfterWhile">SpaceAfterWhile</a> Rule<a name="SpaceAfterWhile_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is exactly one space (blank) after the <tt>while</tt> keyword and before the opening parenthesis.</p>
<p>Examples of violations:</p>
<div>
<pre>    while(true) { }             // violation
    while  (true) { }           // violation
</pre></div></div>
<div class="section">
<h3><a name="SpaceAroundClosureArrow">SpaceAroundClosureArrow</a> Rule<a name="SpaceAroundClosureArrow_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.19</i></p>
<p>Checks that there is at least one space (blank) or whitespace around each closure arrow (-&gt;) symbol.</p>
<p>Known limitations:</p>
<ul>
<li>Does not catch violations if the closure arrow (-&gt;) is on a separate line from the start of the closure.</li></ul>
<p>Example of violations:</p>
<div>
<pre>    def closure1 = {-&gt;}                             // violation
    def closure2 = { -&gt;}                            // violation
    def closure3 = {-&gt; }                            // violation
    def closure4 = { count-&gt; println 123 }          // violation
    def closure5 = { count, name -&gt;println 123 }    // violation
</pre></div></div>
<div class="section">
<h3><a name="SpaceAroundMapEntryColon">SpaceAroundMapEntryColon</a> Rule<a name="SpaceAroundMapEntryColon_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.20</i></p>
<p>Check for proper formatting of whitespace around colons for literal Map entries. By default, no whitespace is allowed either before or after the Map entry colon, but you can change that through the configuration properties below.</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">characterBeforeColonRegex</td>
<td align="left">The regular expression that must match the character before the colon (:) for a literal <i>Map</i> entry. For example, <tt>/\S/</tt> matches any non-whitespace character and <tt>/\s/</tt> matches any whitespace character (thus requiring a space or whitespace).</td>
<td align="left"><tt>/\S/</tt> (i.e., no space allowed before the colon)</td></tr>
<tr class="a">
<td align="left">characterAfterColonRegex</td>
<td align="left">The regular expression that must match the character after the colon (:) for a literal <i>Map</i> entry. For example, <tt>/\S/</tt> matches any non-whitespace character and <tt>/\s/</tt> matches any whitespace character (thus requiring a space or whitespace).</td>
<td align="left"><tt>/\S/</tt> (i.e., no space allowed before the colon)</td></tr></table>
<p>Example of violations:</p>
<div>
<pre>    Map m1 = [myKey : 12345]            // violation (both before and after the colon)
    println [a :[1:11, 2:22],           // violation on a (before colon)
                b:[(Integer): 33]]      // violation on Integer (after colon)
</pre></div></div>
<div class="section">
<h3><a name="SpaceAroundOperator">SpaceAroundOperator</a> Rule<a name="SpaceAroundOperator_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is at least one space (blank) or whitespace around each binary operator, including: +, -, *, /, &gt;&gt;, &lt;&lt;, &amp;&amp;, ||, &amp;, |, ?:, =, &quot;as&quot;.</p>
<p>Do not check dot ('.') operator. Do not check unary operators (!, +, -, ++, --, ?.). Do not check array ('[') operator.</p>
<p>Known limitations:</p>
<ul>
<li>Does not catch violations of missing space around equals operator (=) within a declaration expression, e.g. <tt>def x=23</tt></li>
<li>Does not catch violations of certain ternary expressions and standalone elvis operator (?:) expressions</li></ul>
<p>Examples of violations:</p>
<div>
<pre>    def myMethod() {
        3+ 5-x*23/ 100              // violation
        list \&lt;\&lt;123                // violation
        other\&gt;\&gt; writer            // violation
        x=99                        // violation
        x&amp;&amp; y                       // violation
        x ||y                       // violation
        x &amp;y                        // violation
        x| y                        // violation
        [1,2]as String              // violation
    }
</pre></div></div>
<div class="section">
<h3><a name="SpaceBeforeClosingBrace">SpaceBeforeClosingBrace</a> Rule<a name="SpaceBeforeClosingBrace_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is at least one space (blank) or whitespace before each closing brace (&quot;}&quot;) for method/class/interface declarations, closure expressions and block statements.</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">checkClosureMapEntryValue</td>
<td align="left">If <tt>false</tt>, then do not check for whitespace before closing braces for closure expressions that are literal Map values, e.g. <tt>[abc:<a name="doStuff">doStuff()</a>]</tt>.</td>
<td align="left"><tt>true</tt></td></tr>
<tr class="a">
<td align="left">ignoreEmptyBlock</td>
<td align="left">If <tt>true</tt>, then allow for <tt>[<a name="a"></a>]</tt> in code</td>
<td align="left"><tt>false</tt></td></tr></table>
<p>Known limitations:</p>
<ul>
<li>May not catch actual violations if the source line contains unicode character literals, e.g. <tt>'\u00A0'</tt></li></ul>
<p>Examples of violations:</p>
<div>
<pre>    class MyClass { int count}                  // violation

    interface MyInterface { void doStuff()}     // violation

    enum MyEnum { OK, BAD}                      // violation

    def myMethod() { return 9}                  // violation

    if (ready) { doStuff()}                     // violation

    if (ready) {
    } else { return 9}                          // violation

    for (int i=0; i&lt;10; i++) { println i}       // violation

    for (String name in names) { println name}  // violation

    for (String name: names) { println name}    // violation

    while (ready) { doStuff()}                  // violation

    try { doStuff()}                            // violation
    catch(Exception e) { logError(e)}           // violation
    finally { cleanUp()}                        // violation

    list.each { name -&gt; println name}           // violation

    shouldFail(Exception) { doStuff()}          // violation
</pre></div></div>
<div class="section">
<h3><a name="SpaceBeforeOpeningBrace">SpaceBeforeOpeningBrace</a> Rule<a name="SpaceBeforeOpeningBrace_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.18</i></p>
<p>Check that there is at least one space (blank) or whitespace before each opening brace (&quot;{&quot;) for method/class/interface declarations, closure expressions and block statements.</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">checkClosureMapEntryValue</td>
<td align="left">If <tt>false</tt>, then do not check for whitespace before opening braces for closure expressions that are literal Map values, e.g. <tt>[abc:<a name="doStuff">doStuff()</a>]</tt>.</td>
<td align="left"><tt>true</tt></td></tr></table>
<p>Known limitations:</p>
<ul>
<li>May not catch actual violations if the source line contains unicode character literals, e.g. <tt>'\u00A0'</tt></li></ul>
<p>Examples of violations:</p>
<div>
<pre>    class MyClass{ }                            // violation
    class MyOtherClass extends AbstractClass{ } // violation

    interface MyInterface{ }                    // violation

    enum MyEnum{ OK, BAD }                      // violation

    def myMethod(){ }                           // violation

    if (ready){ }                               // violation

    if (ready) {
    } else{}                                    // violation

    for (int i=0; i&lt;10; i++){ }                 // violation

    for (String name in names){ }               // violation

    for (String name: names){ }                 // violation

    while (ready){ }                            // violation

    try{
    } finally { }                               // violation

    try {
    } catch(Exception e){ }                     // violation

    try {
    } finally{ }                                // violation

    list.each{ name -&gt; }                        // violation

    shouldFail(Exception){ doStuff() }          // violation
</pre></div></div>
<div class="section">
<h3><a name="TrailingWhitespace">TrailingWhitespace</a> Rule<a name="TrailingWhitespace_Rule"></a></h3><!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<p><i>Since CodeNarc 0.21</i></p>
<p>Checks that no lines of source code end with whitespace characters.</p></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>