forked from checkstyle/checkstyle
/
config_filters.xml
2558 lines (2499 loc) · 100 KB
/
config_filters.xml
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="http://maven.apache.org/XDOC/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 https://maven.apache.org/xsd/xdoc-2.0.xsd">
<head>
<title>Filters</title>
</head>
<body>
<section name="Content">
<macro name="toc">
<param name="fromDepth" value="1"/>
<param name="toDepth" value="1"/>
</macro>
</section>
<section name="SeverityMatchFilter">
<p>Since Checkstyle 3.2</p>
<subsection name="Description" id="SeverityMatchFilter_Description">
<p>
Filter <code>SeverityMatchFilter</code> decides
audit events according to the <a href="config.html#Severity">severity
level</a> of the event.
</p>
</subsection>
<subsection name="Notes" id="SeverityMatchFilter_Notes">
<p>
SeverityMatchFilter can suppress Checks that have Treewalker or Checker as parent module.
</p>
</subsection>
<subsection name="Properties" id="SeverityMatchFilter_Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>severity</td>
<td>Specify the severity level of this filter.</td>
<td><a href="property_types.html#SeverityLevel">SeverityLevel</a></td>
<td><code>error</code></td>
<td>3.2</td>
</tr>
<tr>
<td>acceptOnMatch</td>
<td>
Control whether the filter accepts an audit event if and only if there is
a match between the event's severity level and property
severity. If acceptOnMatch
is <code>false</code>, then the filter
accepts an audit event if and only if there is not a match
between the event's severity level and property severity.
</td>
<td><a href="property_types.html#boolean">boolean</a></td>
<td><code>true</code></td>
<td>3.2</td>
</tr>
</table>
</div>
</subsection>
<subsection name="Examples" id="SeverityMatchFilter_Examples">
<p>
For example, the following configuration fragment directs the
Checker to not report audit events with severity
level <code>info</code>:
</p>
<source>
<module name="SeverityMatchFilter">
<property name="severity" value="info"/>
<property name="acceptOnMatch" value="false"/>
</module>
</source>
</subsection>
<subsection name="Example of Usage" id="SeverityMatchFilter_Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SeverityMatchFilter">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Package" id="SeverityMatchFilter_Package">
<p> com.puppycrawl.tools.checkstyle.filters </p>
</subsection>
<subsection name="Parent Module" id="SeverityMatchFilter_Parent_Module">
<p> <a href="config.html#Checker">Checker</a> </p>
</subsection>
</section>
<section name="SuppressionCommentFilter">
<p>Since Checkstyle 3.5</p>
<subsection name="Description" id="SuppressionCommentFilter_Description">
<p>
Filter <code>SuppressionCommentFilter</code> uses
pairs of comments to suppress audit events.
</p>
<p>
Rationale: Sometimes there are legitimate reasons for violating
a check. When this is a matter of the code in question and not
personal preference, the best place to override the policy is in
the code itself. Semi-structured comments can be associated
with the check. This is sometimes superior to a separate
suppressions file, which must be kept up-to-date as the source
file is edited.
</p>
<p>
Note that the suppression comment should be put before the violation. You can use more
than one suppression comment each on separate line.
</p>
<p>
Attention: This filter may only be specified within the TreeWalker module
(<code><module name="TreeWalker"/></code>) and only
applies to checks which are also defined within this module.
To filter non-TreeWalker checks like <code>RegexpSingleline</code>,
a <a href="config_filters.html#SuppressWithPlainTextCommentFilter">
SuppressWithPlainTextCommentFilter</a> or similar filter must be used.
</p>
</subsection>
<subsection name="Notes" id="SuppressionCommentFilter_Notes">
<p>
<code>offCommentFormat</code> and <code>onCommentFormat</code> must have equal
<a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/regex/Matcher.html#groupCount()">
paren counts</a>.
</p>
<p>
SuppressionCommentFilter can suppress Checks that have Treewalker as parent module.
</p>
</subsection>
<subsection name="Properties" id="SuppressionCommentFilter_Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>offCommentFormat</td>
<td>Specify comment pattern to trigger filter to begin suppression.</td>
<td><a href="property_types.html#Pattern">Pattern</a></td>
<td><code>"CHECKSTYLE:OFF"</code></td>
<td>3.5</td>
</tr>
<tr>
<td>onCommentFormat</td>
<td>Specify comment pattern to trigger filter to end suppression.</td>
<td><a href="property_types.html#Pattern">Pattern</a></td>
<td><code>"CHECKSTYLE:ON"</code></td>
<td>3.5</td>
</tr>
<tr>
<td>checkFormat</td>
<td>Specify check pattern to suppress.</td>
<td><a href="property_types.html#Pattern">Pattern</a></td>
<td><code>".*"</code></td>
<td>3.5</td>
</tr>
<tr>
<td>messageFormat</td>
<td>Specify message pattern to suppress.</td>
<td><a href="property_types.html#Pattern">Pattern</a></td>
<td><code>null</code></td>
<td>3.5</td>
</tr>
<tr>
<td>idFormat</td>
<td>Specify check ID pattern to suppress.</td>
<td><a href="property_types.html#Pattern">Pattern</a></td>
<td><code>null</code></td>
<td>8.24</td>
</tr>
<tr>
<td>checkCPP</td>
<td>Control whether to check C++ style comments (<code>//</code>).</td>
<td><a href="property_types.html#boolean">boolean</a></td>
<td><code>true</code></td>
<td>3.5</td>
</tr>
<tr>
<td>checkC</td>
<td>Control whether to check C style comments (<code>/* ... */</code>).</td>
<td><a href="property_types.html#boolean">boolean</a></td>
<td><code>true</code></td>
<td>3.5</td>
</tr>
</table>
</div>
</subsection>
<subsection name="Examples" id="SuppressionCommentFilter_Examples">
<p>
To configure a filter to suppress audit events between a comment
containing <code>CHECKSTYLE:OFF</code> and a comment containing
<code>CHECKSTYLE:ON</code>:
</p>
<source>
<module name="TreeWalker">
...
<module name="SuppressionCommentFilter"/>
...
</module>
</source>
<p>
To configure a filter to suppress audit events between a comment
containing line <code>BEGIN GENERATED CODE</code> and a comment
containing line <code>END GENERATED CODE</code>:
</p>
<source>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="BEGIN GENERATED CODE"/>
<property name="onCommentFormat" value="END GENERATED CODE"/>
</module>
</source>
<source>
//BEGIN GENERATED CODE
@Override
public boolean equals(Object obj) { ... } // No violation events will be reported
@Override
public int hashCode() { ... } // No violation events will be reported
//END GENERATED CODE
. . .
</source>
<p>
To configure a filter so that <code>// stop constant
check</code> and <code>// resume constant check</code> marks
legitimate constant names:
</p>
<source>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="stop constant check"/>
<property name="onCommentFormat" value="resume constant check"/>
<property name="checkFormat" value="ConstantNameCheck"/>
</module>
</source>
<source>
//stop constant check
public static final int someConstant; // won't warn here
//resume constant check
public static final int someConstant; // will warn here as constant's name doesn't match the
// pattern "^[A-Z][A-Z0-9]*$"
</source>
<p>
To configure a filter so that <code>UNUSED OFF:<i>var</i></code>
and <code>UNUSED ON: <i>var</i></code> marks a
variable or parameter known not to be used by the code by
matching the variable name in the message:
</p>
<source>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="UNUSED OFF\: (\w+)"/>
<property name="onCommentFormat" value="UNUSED ON\: (\w+)"/>
<property name="checkFormat" value="Unused"/>
<property name="messageFormat" value="^Unused \w+ '$1'.$"/>
</module>
</source>
<source>
private static void foo(int a, int b) // UNUSED OFF: b
{
System.out.println(a);
}
private static void foo1(int a, int b) // UNUSED ON: b
{
System.out.println(a);
}
</source>
<p>
To configure a filter so that name of suppressed check mentioned
in comment <code>CSOFF: <i>regexp</i></code>
and <code>CSON: <i>regexp</i></code> mark a matching check:
</p>
<source>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CSOFF\: ([\w\|]+)"/>
<property name="onCommentFormat" value="CSON\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>
</source>
<source>
public static final int lowerCaseConstant; // CSOFF: ConstantNameCheck
public static final int lowerCaseConstant1; // CSON: ConstantNameCheck
</source>
<p>
To configure a filter to suppress all audit events between a comment
containing <code>CHECKSTYLE_OFF: ALMOST_ALL</code> and a comment containing
<code>CHECKSTYLE_OFF: ALMOST_ALL</code> except for the <em>EqualsHashCode</em> check:
</p>
<source>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE_OFF: ALMOST_ALL"/>
<property name="onCommentFormat" value="CHECKSTYLE_ON: ALMOST_ALL"/>
<property name="checkFormat" value="^((?!(EqualsHashCode)).)*$"/>
</module>
</source>
<source>
public static final int array []; // CHECKSTYLE_OFF: ALMOST_ALL
private String [] strArray;
private int array1 []; // CHECKSTYLE_ON: ALMOST_ALL
</source>
<p>
To configure a filter to suppress Check's violation message <b>which matches
specified message in messageFormat</b> (so suppression will be not only by
Check's name, but by message text additionally, as the same Check could report
different by message format violations) between a comment
containing <code>stop</code> and comment containing <code>resume</code>:
</p>
<source>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="stop"/>
<property name="onCommentFormat" value="resume"/>
<property name="checkFormat" value="IllegalTypeCheck"/>
<property name="messageFormat"
value="^Declaring variables, return values or parameters of type 'GregorianCalendar'
is not allowed.$"/>
</module>
</source>
<p>
Code before filter above is applied with Check's audit events:
</p>
<source>
...
// Warning below: Declaring variables, return values or parameters of type 'GregorianCalendar'
// is not allowed.
GregorianCalendar calendar;
// Warning below here: Declaring variables, return values or parameters of type 'HashSet'
// is not allowed.
HashSet hashSet;
...
</source>
<p>
Code after filter is applied:
</p>
<source>
...
//stop
GregorianCalendar calendar; // No warning here as it is suppressed by filter.
HashSet hashSet;
// Warning above here: Declaring variables, return values or parameters of type 'HashSet'
//is not allowed.
//resume
...
</source>
<p>
It is possible to specify an ID of checks, so that it can be leveraged by the
SuppressionCommentFilter to skip validations. The following examples show how to skip
validations near code that is surrounded with <code>// CSOFF <ID> (reason)</code>
and <code>// CSON <ID></code>, where ID is the ID of checks you want to suppress.
</p>
<p>
Examples of Checkstyle checks configuration:
</p>
<source>
<module name="RegexpSinglelineJava">
<property name="id" value="ignore"/>
<property name="format" value="^.*@Ignore\s*$"/>
<property name="message" value="@Ignore should have a reason."/>
</module>
<module name="RegexpSinglelineJava">
<property name="id" value="systemout"/>
<property name="format" value="^.*System\.(out|err).*$"/>
<property name="message" value="Don't use System.out/err, use SLF4J instead."/>
</module>
</source>
<p>
Example of SuppressionCommentFilter configuration (checkFormat which is set to '$1'
points that ID of the checks is in the first group of offCommentFormat and
onCommentFormat regular expressions):
</p>
<source>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CSOFF (\w+) \(\w+\)"/>
<property name="onCommentFormat" value="CSON (\w+)"/>
<property name="idFormat" value="$1"/>
</module>
</source>
<source>
// CSOFF ignore (test has not been implemented yet)
@Ignore // should NOT fail RegexpSinglelineJava
@Test
public void testMethod() { }
// CSON ignore
// CSOFF systemout (debug)
public static void foo() {
System.out.println("Debug info."); // should NOT fail RegexpSinglelineJava
}
// CSON systemout
</source>
<p>
Example of how to configure the check to suppress more than one checks.
</p>
<source>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="@cs-\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>
</source>
<source>
// @cs-: ClassDataAbstractionCoupling
// @cs-: MagicNumber
@Service // no violations from ClassDataAbstractionCoupling here
@Transactional
public class UserService {
private int value = 10022; // no violations from MagicNumber here
}
</source>
</subsection>
<subsection name="Example of Usage" id="SuppressionCommentFilter_Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionCommentFilter">
Checkstyle Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionCommentFilter">
Google Style</a>
</li>
</ul>
</subsection>
<subsection name="Package" id="SuppressionCommentFilter_Package">
<p> com.puppycrawl.tools.checkstyle.filters </p>
</subsection>
<subsection name="Parent Module" id="SuppressionCommentFilter_Parent_Module">
<p> <a href="config.html#TreeWalker">TreeWalker</a> </p>
</subsection>
</section>
<section name="SuppressionFilter">
<p>Since Checkstyle 3.2</p>
<subsection name="Description" id="SuppressionFilter_Description">
<p>
Filter <code>SuppressionFilter</code> rejects
audit events for Check violations according to
a <a href="/dtds/suppressions_1_2.dtd">suppressions XML
document</a> in a file. If there is no configured
suppressions file or the optional is set to true and
suppressions file was not found the Filter accepts all audit events.
</p>
</subsection>
<subsection name="Properties" id="SuppressionFilter_Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>file</td>
<td>
Specify the location of the <em>suppressions XML document</em> file.
</td>
<td><a href="property_types.html#String">String</a></td>
<td><code>null</code></td>
<td>3.2</td>
</tr>
<tr>
<td>optional</td>
<td>
Control what to do when the file is not existing. If
<code>optional</code> is set to <code>false</code> the file must exist, or else
it ends with error. On the other hand if optional is
<code>true</code> and file is not found, the filter accept all
audit events.
</td>
<td><a href="property_types.html#boolean">boolean</a></td>
<td><code>false</code></td>
<td>6.15</td>
</tr>
</table>
</div>
</subsection>
<subsection name="Notes" id="SuppressionFilter_Notes">
<p>
A <a href="/dtds/suppressions_1_2.dtd">suppressions XML
document</a> contains a set of <code>suppress</code> elements, where
each <code>suppress</code> element can have the following attributes:
</p>
<ul>
<li>
<code>files</code> -
a <a href="property_types.html#Pattern">Pattern</a>
matched against the file name associated with an audit
event. It is optional.
</li>
<li>
<code>checks</code> -
a <a href="property_types.html#Pattern">Pattern</a>
matched against the name of the check associated with an audit
event. Optional as long as <code>id</code> or <code>message</code> is specified.
</li>
<li>
<code>message</code> -
a <a href="property_types.html#Pattern">Pattern</a>
matched against the message of the check associated with an audit
event. Optional as long as <code>checks</code> or <code>id</code> is specified.
</li>
<li>
<code>id</code> -
a <a href="property_types.html#String">String</a>
matched against the <a href="config.html#Id">check id</a> associated with an audit
event. Optional as long as <code>checks</code> or <code>message</code>
is specified.
</li>
<li>
<code>lines</code> - a comma-separated list of
values, where each value is
an <a href="property_types.html#int">int</a> or a
range of integers denoted by integer-integer. It is optional.
</li>
<li>
<code>columns</code> - a comma-separated list of
values, where each value is
an <a href="property_types.html#int">int</a> or a
range of integers denoted by integer-integer. It is optional.
</li>
</ul>
<p>
Each audit event is checked against each <code>suppress</code> element. It is
suppressed if all specified attributes match against the audit event.
</p>
<p>
ATTENTION: filtering by message is dependent on runtime locale. If project is running
in different languages it is better to avoid filtering by message.
</p>
<p>
You can download template of empty suppression filter
<a href="files/suppressions_none.xml">here</a>.
</p>
<p>
Location of the file defined in <code>file</code> property is checked
in the following order:
</p>
<ol>
<li>as a filesystem location</li>
<li>
if no file found, and the location starts with either
<code>http://</code> or <code>https://</code>, then it
is interpreted as a URL
</li>
<li>
if no file found, then passed to the
<code>ClassLoader.getResource()</code> method.
</li>
</ol>
<p>
SuppressionFilter can suppress Checks that have Treewalker or Checker as parent module.
</p>
</subsection>
<subsection name="Examples" id="SuppressionFilter_Examples">
<p>
For example, the following configuration fragment directs the
Checker to use a <code>SuppressionFilter</code>
with suppressions
file <code>config/suppressions.xml</code>:
</p>
<source>
<module name="SuppressionFilter">
<property name="file" value="config/suppressions.xml"/>
<property name="optional" value="false"/>
</module>
</source>
<p>
The following suppressions XML document directs
a <code>SuppressionFilter</code> to
reject <code>JavadocStyleCheck</code> violations for
lines 82 and 108 to 122 of
file <code>AbstractComplexityCheck.java</code>,
and <code>MagicNumberCheck</code> violations for line
221 of file <code>JavadocStyleCheck.java</code>,
and <code>'Missing a Javadoc comment'</code> violations
for all lines and files:
</p>
<source>
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress checks="JavadocStyleCheck"
files="AbstractComplexityCheck.java"
lines="82,108-122"/>
<suppress checks="MagicNumberCheck"
files="JavadocStyleCheck.java"
lines="221"/>
<suppress message="Missing a Javadoc comment"/>
</suppressions>
</source>
<p>
Suppress check by <a href="config.html#Id">module id</a>
when config have two instances on the same check:
</p>
<source>
<suppress id="stringEqual" files="SomeTestCode.java"/>
</source>
<p>
Suppress all checks for hidden files and folders:
</p>
<source>
<suppress files="[/\\]\..+" checks=".*"/>
</source>
<p>
Suppress all checks for Maven-generated code:
</p>
<source>
<suppress files="[/\\]target[/\\]" checks=".*"/>
</source>
<p>
Suppress all checks for archives, classes and other binary files:
</p>
<source>
<suppress files=".+\.(?:jar|zip|war|class|tar|bin)$" checks=".*"/>
</source>
<p>
Suppress all checks for image files:
</p>
<source>
<suppress files=".+\.(?:png|gif|jpg|jpeg)$" checks=".*"/>
</source>
<p>
Suppress all checks for non-java files:
</p>
<source>
<suppress files=".+\.(?:txt|xml|csv|sh|thrift|html|sql|eot|ttf|woff|css|png)$"
checks=".*"/>
</source>
<p>
Suppress all checks in generated sources:
</p>
<source>
<suppress checks=".*" files="com[\\/]mycompany[\\/]app[\\/]gen[\\/]"/>
</source>
<p>
Suppress FileLength check on integration tests in certain folder:
</p>
<source>
<suppress checks="FileLength"
files="com[\\/]mycompany[\\/]app[\\/].*IT.java"/>
</source>
<p>
Suppress naming violations on variable named 'log' in all files:
</p>
<source>
<suppress message="Name 'log' must match pattern"/>
</source>
</subsection>
<subsection name="Example of Usage" id="SuppressionFilter_Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionFilter">
Google Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionFilter">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionFilter">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Package" id="SuppressionFilter_Package">
<p> com.puppycrawl.tools.checkstyle.filters </p>
</subsection>
<subsection name="Parent Module" id="SuppressionFilter_Parent_Module">
<p> <a href="config.html#Checker">Checker</a> </p>
</subsection>
</section>
<section name="SuppressionSingleFilter">
<p>Since Checkstyle 8.23</p>
<subsection name="Description" id="SuppressionSingleFilter_Description">
<p>
Filter <code>SuppressionSingleFilter</code> suppresses audit events for
Checks violations in the specified file, class, checks, message, module id,
lines, and columns.
</p>
<p>
Rationale: To allow users use suppressions configured in the same config with
other modules. SuppressionFilter and SuppressionXpathFilter are require separate
file.
</p>
<p>
Advice: If checkstyle configuration is used for several projects, single suppressions
on common files/folders is better to put in checkstyle configuration as common rule.
All suppression that are for specific file names is better to keep in project specific
config file.
</p>
<p>
Attention: This filter only supports single suppression, and will need
multiple instances if users wants to suppress multiple violations.
</p>
</subsection>
<subsection name="Notes" id="SuppressionSingleFilter_Notes">
<p>
SuppressionSingleFilter can suppress Checks that have Treewalker or
Checker as parent module.
</p>
</subsection>
<subsection name="Properties" id="SuppressionSingleFilter_Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>files</td>
<td>Define the RegExp for matching against the file name associated
with an audit event.</td>
<td><a href="property_types.html#Pattern">Pattern</a></td>
<td><code>null</code></td>
<td>8.23</td>
</tr>
<tr>
<td>checks</td>
<td>Define the RegExp for matching against the name of the check
associated with an audit event.</td>
<td><a href="property_types.html#Pattern">Pattern</a></td>
<td><code>null</code></td>
<td>8.23</td>
</tr>
<tr>
<td>message</td>
<td>Define the RegExp for matching against the message of the check associated
with an audit event.</td>
<td><a href="property_types.html#Pattern">Pattern</a></td>
<td><code>null</code></td>
<td>8.23</td>
</tr>
<tr>
<td>id</td>
<td>Specify a string matched against the ID of the check associated with an audit
event.</td>
<td><a href="property_types.html#String">String</a></td>
<td><code>null</code></td>
<td>8.23</td>
</tr>
<tr>
<td>lines</td>
<td>Specify a comma-separated list of values, where each value is an integer or a
range of integers denoted by integer-integer.</td>
<td><a href="property_types.html#String">String</a></td>
<td><code>null</code></td>
<td>8.23</td>
</tr>
<tr>
<td>columns</td>
<td>Specify a comma-separated list of values, where each value is an integer or a
range of integers denoted by integer-integer.</td>
<td><a href="property_types.html#String">String</a></td>
<td><code>null</code></td>
<td>8.23</td>
</tr>
</table>
</div>
</subsection>
<subsection name="Examples" id="SuppressionSingleFilter_Examples">
<p>
The following suppressions directs
a <code>SuppressionSingleFilter</code> to
reject <code>JavadocStyleCheck</code> violations for
lines 82 and 108 to 122 of
file <code>AbstractComplexityCheck.java</code>,
and <code>MagicNumberCheck</code> violations for line
221 of file <code>JavadocStyleCheck.java</code>,
and <code>'Missing a Javadoc comment'</code> violations
for all lines and files:
</p>
<source>
<module name="SuppressionSingleFilter">
<property name="checks" value="JavadocStyleCheck"/>
<property name="files" value="AbstractComplexityCheck.java"/>
<property name="lines" value="82,108-122"/>
</module>
<module name="SuppressionSingleFilter">
<property name="checks" value="MagicNumberCheck"/>
<property name="files" value="JavadocStyleCheck.java"/>
<property name="lines" value="221"/>
</module>
<module name="SuppressionSingleFilter">
<property name="message" value="Missing a Javadoc comment"/>
</module>
</source>
<p>
Suppress check by <a href="https://checkstyle.org/config.html#Id">module id</a>
when config have two instances on the same check:
</p>
<source>
<module name="SuppressionSingleFilter">
<property name="id" value="stringEqual"/>
<property name="files" value="SomeTestCode.java"/>
</module>
</source>
<p>
Suppress all checks for hidden files and folders:
</p>
<source>
<module name="SuppressionSingleFilter">
<property name="files" value="[/\\]\..+"/>
<property name="checks" value=".*"/>
</module>
</source>
<p>
Suppress all checks for Maven-generated code:
</p>
<source>
<module name="SuppressionSingleFilter">
<property name="files" value="[/\\]target[/\\]"/>
<property name="checks" value=".*"/>
</module>
</source>
<p>
Suppress all checks for archives, classes and other binary files:
</p>
<source>
<module name="SuppressionSingleFilter">
<property name="files" value=".+\.(?:jar|zip|war|class|tar|bin)$"/>
<property name="checks" value=".*"/>
</module>
</source>
<p>
Suppress all checks for image files:
</p>
<source>
<module name="SuppressionSingleFilter">
<property name="files" value=".+\.(?:png|gif|jpg|jpeg)$"/>
<property name="checks" value=".*"/>
</module>
</source>
<p>
Suppress all checks for non-java files:
</p>
<source>
<module name="SuppressionSingleFilter">
<property name="files"
value=".+\.(?:txt|xml|csv|sh|thrift|html|sql|eot|ttf|woff|css|png)$"/>
<property name="checks" value=".*"/>
</module>
</source>
<p>
Suppress all checks in generated sources:
</p>
<source>
<module name="SuppressionSingleFilter">
<property name="files" value="com[\\/]mycompany[\\/]app[\\/]gen[\\/]"/>
<property name="checks" value=".*"/>
</module>
</source>
<p>
Suppress FileLength check on integration tests in certain folder:
</p>
<source>
<module name="SuppressionSingleFilter">
<property name="files" value="com[\\/]mycompany[\\/]app[\\/].*IT.java"/>
<property name="checks" value="FileLength"/>
</module>
</source>
<p>
Suppress naming violations on variable named 'log' in all files:
</p>
<source>
<module name="SuppressionSingleFilter">
<property name="message" value="Name 'log' must match pattern"/>
</module>
</source>
</subsection>
<subsection name="Example of Usage" id="SuppressionSingleFilter_Example_of_Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionSingleFilter">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Package" id="SuppressionSingleFilter_Package">
<p> com.puppycrawl.tools.checkstyle.filters </p>
</subsection>
<subsection name="Parent Module" id="SuppressionSingleFilter_Parent_Module">
<p> <a href="config.html#Checker">Checker</a> </p>
</subsection>
</section>
<section name="SuppressionXpathFilter">
<p>Since Checkstyle 8.6</p>
<subsection name="Description" id="SuppressionXpathFilter_Description">
<p>
Filter <code>SuppressionXpathFilter</code> works as
<a href="config_filters.html#SuppressionFilter">
SuppressionFilter</a>.
Additionally, filter processes <code>suppress-xpath</code> elements,
which contains xpath-expressions. Xpath-expressions
are queries for suppressed nodes inside the AST tree.
</p>
<p>
Currently, filter does not support the following checks:
</p>
<ul id="SuppressionXpathFilter_IncompatibleChecks">
<li>NoCodeInFile (reason is that AST is not generated for a file not containing code)</li>
<li>Regexp (reason is at <a href="https://github.com/checkstyle/checkstyle/issues/7759#issuecomment-605525287"> #7759</a>)</li>
<li>RegexpSinglelineJava (reason is at <a href="https://github.com/checkstyle/checkstyle/issues/7759#issuecomment-605525287"> #7759</a>)</li>
</ul>
<p>
Also, the filter does not support suppressions inside javadoc reported by Javadoc checks:
</p>
<ul id="SuppressionXpathFilter_JavadocChecks">
<li>AtclauseOrder</li>
<li>JavadocBlockTagLocation</li>
<li>JavadocMethod</li>
<li>JavadocMissingLeadingAsterisk</li>
<li>JavadocMissingWhitespaceAfterAsterisk</li>
<li>JavadocParagraph</li>
<li>JavadocStyle</li>
<li>JavadocTagContinuationIndentation</li>
<li>JavadocType</li>
<li>MissingDeprecated</li>
<li>NonEmptyAtclauseDescription</li>
<li>RequireEmptyLineBeforeBlockTagGroup</li>
<li>SingleLineJavadoc</li>
<li>SummaryJavadoc</li>
<li>WriteTag</li>
</ul>
<p>
Note, that support for these Checks will be available after resolving issue
<a href="https://github.com/checkstyle/checkstyle/issues/5770">#5770</a>.
</p>
<p>
Currently, filter supports the following
xpath axes:
</p>
<ul>
<li>ancestor</li>
<li>ancestor-or-self</li>
<li>attribute</li>
<li>child</li>
<li>descendant</li>
<li>descendant-or-self</li>
<li>following</li>
<li>following-sibling</li>
<li>parent</li>
<li>preceding</li>
<li>preceding-sibling</li>
<li>self</li>
</ul>
<p>
You can use the command line helper tool to generate xpath
suppressions based on your configuration file and input files.
See
<a href="cmdline.html">here</a>
for more details.
</p>
</subsection>
<subsection name="Notes" id="SuppressionXpathFilter_Notes">
<p>
The suppression file location is checked in following order:
</p>
<ol>
<li>as a filesystem location</li>
<li>
if no file found, and the location starts with either
<code>http://</code> or <code>https://</code>, then it
is interpreted as a URL
</li>
<li>
if no file found, then passed to the
<code>ClassLoader.getResource()</code> method.
</li>
</ol>
<p>
SuppressionXpathFilter can suppress Checks that have Treewalker as parent module.
</p>
</subsection>
<subsection name="Properties" id="SuppressionXpathFilter_Properties">
<div class="wrapper">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>