Skip to content

Commit 7ff1ebf

Browse files
shaikhuromani
authored andcommitted
Issue #13345: Enable example test for SuppressWithNearbyCommentFilter
1 parent 9201875 commit 7ff1ebf

File tree

15 files changed

+186
-127
lines changed

15 files changed

+186
-127
lines changed

src/site/xdoc/filters/suppresswithnearbycommentfilter.xml

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,15 @@
107107
<module name="Checker">
108108
<module name="TreeWalker">
109109
<module name="SuppressWithNearbyCommentFilter"/>
110+
<module name="NoWhitespaceAfter"/>
110111
</module>
111112
</module>
112113
</source>
113114
<p id="Example1-code">Example:</p>
114115
<source>
115-
private int [] array; // SUPPRESS CHECKSTYLE
116+
public class Example1 {
117+
private int [] array; // SUPPRESS CHECKSTYLE NoWhitespaceAfter
118+
}
116119
</source>
117120
<p id="Example2-config">
118121
To configure a filter to suppress all audit events on any line
@@ -126,12 +129,15 @@ private int [] array; // SUPPRESS CHECKSTYLE
126129
&lt;property name=&quot;checkFormat&quot; value=&quot;.*&quot;/&gt;
127130
&lt;property name=&quot;influenceFormat&quot; value=&quot;0&quot;/&gt;
128131
&lt;/module&gt;
132+
&lt;module name=&quot;ConstantName&quot;/&gt;
129133
&lt;/module&gt;
130134
&lt;/module&gt;
131135
</source>
132136
<p id="Example2-code">Example:</p>
133137
<source>
134-
public static final int lowerCaseConstant; // CHECKSTYLE IGNORE THIS LINE
138+
public class Example2 {
139+
public static final int lowerCaseConstant = 1; // CHECKSTYLE IGNORE THIS LINE
140+
}
135141
</source>
136142
<p id="Example3-config">
137143
To configure a filter so that
@@ -148,17 +154,22 @@ public static final int lowerCaseConstant; // CHECKSTYLE IGNORE THIS LINE
148154
&lt;property name=&quot;messageFormat&quot; value=&quot;$1&quot;/&gt;
149155
&lt;property name=&quot;influenceFormat&quot; value=&quot;-1&quot;/&gt;
150156
&lt;/module&gt;
157+
&lt;module name=&quot;IllegalCatch&quot;/&gt;
151158
&lt;/module&gt;
152159
&lt;/module&gt;
153160
</source>
154161
<p id="Example3-code">Example:</p>
155162
<source>
156-
. . .
157-
catch (RuntimeException re) {
158-
// OK to catch RuntimeException here
163+
public class Example3 {
164+
public void doStuff() {
165+
try {
166+
// blah blah blah
167+
}
168+
catch(RuntimeException re) {
169+
// OK to catch RuntimeException here
170+
}
171+
}
159172
}
160-
catch (Throwable th) { ... }
161-
. . .
162173
</source>
163174
<p id="Example4-config">
164175
To configure a filter so that
@@ -175,16 +186,20 @@ catch (Throwable th) { ... }
175186
&lt;property name=&quot;checkFormat&quot; value=&quot;$1&quot;/&gt;
176187
&lt;property name=&quot;influenceFormat&quot; value=&quot;$2&quot;/&gt;
177188
&lt;/module&gt;
189+
&lt;module name=&quot;ConstantName&quot;/&gt;
178190
&lt;/module&gt;
179191
&lt;/module&gt;
180192
</source>
181193
<p id="Example4-code">Example:</p>
182194
<source>
183-
static final int lowerCaseConstant; // CHECKSTYLE IGNORE ConstantNameCheck FOR NEXT 3 LINES
184-
static final int lowerCaseConstant1;
185-
static final int lowerCaseConstant2;
186-
static final int lowerCaseConstant3;
187-
static final int lowerCaseConstant4; // will warn here
195+
public class Example4 {
196+
// CHECKSTYLE IGNORE ConstantNameCheck FOR NEXT 4 LINES
197+
static final int lowerCaseConstant1 = 1;
198+
static final int lowerCaseConstant2 = 2;
199+
static final int lowerCaseConstant3 = 3;
200+
static final int lowerCaseConstant4 = 4;
201+
static final int lowerCaseConstant5 = 5; // violation 'must match pattern'
202+
}
188203
</source>
189204
<p id="Example5-config">
190205
To configure a filter to avoid any audits on code like:
@@ -194,18 +209,19 @@ static final int lowerCaseConstant4; // will warn here
194209
&lt;module name=&quot;TreeWalker&quot;&gt;
195210
&lt;module name=&quot;SuppressWithNearbyCommentFilter&quot;&gt;
196211
&lt;property name=&quot;commentFormat&quot;
197-
value=&quot;ALLOW (\\w+) ON PREVIOUS LINE&quot;/&gt;
198-
&lt;property name=&quot;checkFormat&quot; value=&quot;$1&quot;/&gt;
212+
value=&quot;ALLOW (\w+) ON PREVIOUS LINE&quot;/&gt;
199213
&lt;property name=&quot;influenceFormat&quot; value=&quot;-1&quot;/&gt;
200214
&lt;/module&gt;
215+
&lt;module name=&quot;MemberName&quot;/&gt;
201216
&lt;/module&gt;
202217
&lt;/module&gt;
203218
</source>
204219
<p id="Example5-code">Example:</p>
205220
<source>
206-
private int D2;
207-
// ALLOW MemberName ON PREVIOUS LINE
208-
. . .
221+
public class Example5 {
222+
private int D2;
223+
// ALLOW MemberName ON PREVIOUS LINE
224+
}
209225
</source>
210226

211227
<p id="Example6-config">
@@ -217,16 +233,21 @@ private int D2;
217233
&lt;module name=&quot;TreeWalker&quot;&gt;
218234
&lt;module name=&quot;SuppressWithNearbyCommentFilter&quot;&gt;
219235
&lt;property name=&quot;commentFormat&quot;
220-
value=&quot;@cs\.suppress \[(\w+(\|\w+)*)\] \w[-\.'`,:;\w ]{14,}&quot;/&gt;
236+
value=&quot;@cs\.suppress \[(\w+(\|\w+)*)\] \w[-\.'`,:;\w ]{13,}&quot;/&gt;
221237
&lt;property name=&quot;checkFormat&quot; value=&quot;$1&quot;/&gt;
222238
&lt;property name=&quot;influenceFormat&quot; value=&quot;1&quot;/&gt;
223239
&lt;/module&gt;
240+
&lt;module name=&quot;ConstantName&quot;/&gt;
241+
&lt;module name=&quot;NoWhitespaceAfter&quot;/&gt;
224242
&lt;/module&gt;
225243
&lt;/module&gt;
226244
</source>
227245
<p id="Example6-code">Example:</p>
228246
<source>
229-
public static final int [] array; // @cs.suppress [ConstantName|NoWhitespaceAfter] A comment here
247+
public class Example6 {
248+
// @cs.suppress [ConstantName|NoWhitespaceAfter] A comment here
249+
public static final int [] array = {};
250+
}
230251
</source>
231252
<p>
232253
It is possible to specify an ID of checks, so that it can be leveraged by the
@@ -255,23 +276,25 @@ public static final int [] array; // @cs.suppress [ConstantName|NoWhitespaceAfte
255276
&lt;property name=&quot;format&quot; value=&quot;^.*@Ignore\s*$&quot;/&gt;
256277
&lt;property name=&quot;message&quot; value=&quot;@Ignore should have a reason.&quot;/&gt;
257278
&lt;/module&gt;
258-
259279
&lt;module name=&quot;RegexpSinglelineJava&quot;&gt;
260280
&lt;property name=&quot;id&quot; value=&quot;systemout&quot;/&gt;
261-
&lt;property name=&quot;format&quot; value=&quot;^.*System\.(out|err).*$&quot;/&gt;
281+
&lt;property name=&quot;format&quot; value=&quot;^.*System\.\(out|err\).*$&quot;/&gt;
262282
&lt;property name=&quot;message&quot; value=&quot;Don't use System.out/err, use SLF4J instead.&quot;/&gt;
263283
&lt;/module&gt;
264284
&lt;/module&gt;
265285
&lt;/module&gt;
266286
</source>
267287
<p id="Example7-code">Example:</p>
268288
<source>
269-
@Ignore // @cs-: ignore (test has not been implemented yet)
270-
@Test
271-
public void testMethod() { }
289+
public class Example7 {
290+
@Ignore // @cs-: ignore (test has not been implemented yet)
291+
@Test
292+
public void testMethod() {}
272293

273-
public static void foo() {
274-
System.out.println(&quot;Debug info.&quot;); // @cs-: systemout (should not fail RegexpSinglelineJava)
294+
public static void foo() {
295+
296+
System.out.println(&quot;Debug info.&quot;); // @cs-: systemout (should not fail)
297+
}
275298
}
276299
</source>
277300
<p id="Example8-config">
@@ -286,16 +309,20 @@ public static void foo() {
286309
&lt;property name=&quot;checkFormat&quot; value=&quot;$1&quot;/&gt;
287310
&lt;property name=&quot;influenceFormat&quot; value=&quot;$2&quot;/&gt;
288311
&lt;/module&gt;
312+
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
313+
&lt;property name=&quot;max&quot; value=&quot;1&quot; /&gt;
314+
&lt;/module&gt;
315+
&lt;module name=&quot;MagicNumber&quot;/&gt;
289316
&lt;/module&gt;
290317
&lt;/module&gt;
291318
</source>
292319
<p id="Example8-code">Example:</p>
293320
<source>
294321
// @cs-: ClassDataAbstractionCoupling influence 2
295322
// @cs-: MagicNumber influence 4
296-
@Service // no violations from ClassDataAbstractionCoupling here
297-
@Transactional
298-
public class UserService {
323+
public class Example8 { // no violations from ClassDataAbstractionCoupling here
324+
private Example1 foo = new Example1();
325+
private Example2 bar = new Example2();
299326
private int value = 10022; // no violations from MagicNumber here
300327
}
301328
</source>

src/site/xdoc/filters/suppresswithnearbycommentfilter.xml.template

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@
5151
</p>
5252
<macro name="example">
5353
<param name="path"
54-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example1.txt"/>
54+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example1.java"/>
5555
<param name="type" value="config"/>
5656
</macro>
5757
<p id="Example1-code">Example:</p>
5858
<macro name="example">
5959
<param name="path"
60-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example1.txt"/>
60+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example1.java"/>
6161
<param name="type" value="code"/>
6262
</macro>
6363
<p id="Example2-config">
@@ -66,13 +66,13 @@
6666
</p>
6767
<macro name="example">
6868
<param name="path"
69-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example2.txt"/>
69+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example2.java"/>
7070
<param name="type" value="config"/>
7171
</macro>
7272
<p id="Example2-code">Example:</p>
7373
<macro name="example">
7474
<param name="path"
75-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example2.txt"/>
75+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example2.java"/>
7676
<param name="type" value="code"/>
7777
</macro>
7878
<p id="Example3-config">
@@ -83,13 +83,13 @@
8383
</p>
8484
<macro name="example">
8585
<param name="path"
86-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example3.txt"/>
86+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example3.java"/>
8787
<param name="type" value="config"/>
8888
</macro>
8989
<p id="Example3-code">Example:</p>
9090
<macro name="example">
9191
<param name="path"
92-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example3.txt"/>
92+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example3.java"/>
9393
<param name="type" value="code"/>
9494
</macro>
9595
<p id="Example4-config">
@@ -100,27 +100,27 @@
100100
</p>
101101
<macro name="example">
102102
<param name="path"
103-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example4.txt"/>
103+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example4.java"/>
104104
<param name="type" value="config"/>
105105
</macro>
106106
<p id="Example4-code">Example:</p>
107107
<macro name="example">
108108
<param name="path"
109-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example4.txt"/>
109+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example4.java"/>
110110
<param name="type" value="code"/>
111111
</macro>
112112
<p id="Example5-config">
113113
To configure a filter to avoid any audits on code like:
114114
</p>
115115
<macro name="example">
116116
<param name="path"
117-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example5.txt"/>
117+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example5.java"/>
118118
<param name="type" value="config"/>
119119
</macro>
120120
<p id="Example5-code">Example:</p>
121121
<macro name="example">
122122
<param name="path"
123-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example5.txt"/>
123+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example5.java"/>
124124
<param name="type" value="code"/>
125125
</macro>
126126

@@ -130,13 +130,13 @@
130130
</p>
131131
<macro name="example">
132132
<param name="path"
133-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example6.txt"/>
133+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example6.java"/>
134134
<param name="type" value="config"/>
135135
</macro>
136136
<p id="Example6-code">Example:</p>
137137
<macro name="example">
138138
<param name="path"
139-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example6.txt"/>
139+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example6.java"/>
140140
<param name="type" value="code"/>
141141
</macro>
142142
<p>
@@ -154,13 +154,13 @@
154154
</p>
155155
<macro name="example">
156156
<param name="path"
157-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example7.txt"/>
157+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example7.java"/>
158158
<param name="type" value="config"/>
159159
</macro>
160160
<p id="Example7-code">Example:</p>
161161
<macro name="example">
162162
<param name="path"
163-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example7.txt"/>
163+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example7.java"/>
164164
<param name="type" value="code"/>
165165
</macro>
166166
<p id="Example8-config">
@@ -169,13 +169,13 @@
169169
</p>
170170
<macro name="example">
171171
<param name="path"
172-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example8.txt"/>
172+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example8.java"/>
173173
<param name="type" value="config"/>
174174
</macro>
175175
<p id="Example8-code">Example:</p>
176176
<macro name="example">
177177
<param name="path"
178-
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example8.txt"/>
178+
value="resources/com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter/Example8.java"/>
179179
<param name="type" value="code"/>
180180
</macro>
181181
</subsection>

src/test/java/com/puppycrawl/tools/checkstyle/bdd/InlineConfigParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ private static String getFullyQualifiedClassName(String filePath, String moduleN
540540
"com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck");
541541
moduleMappings.put("MagicNumber",
542542
"com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck");
543+
moduleMappings.put("ClassDataAbstractionCoupling",
544+
"com.puppycrawl.tools.checkstyle.checks.metrics.ClassDataAbstractionCouplingCheck");
543545

544546
String fullyQualifiedClassName;
545547
if (moduleMappings.containsKey(moduleName)) {

0 commit comments

Comments
 (0)