Skip to content

Commit df47b08

Browse files
committed
Skip noinspection and region/endregion IDE comments
1 parent 0442125 commit df47b08

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/main/java/org/openrewrite/staticanalysis/SingleLineCommentSpacing.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public Space visitSpace(Space space, Space.Location loc, ExecutionContext ctx) {
5555
}
5656
TextComment tc = (TextComment) comment;
5757
String text = tc.getText();
58-
if (text.isEmpty() || text.startsWith(" ") || text.startsWith("language=")) {
58+
if (text.isEmpty() || text.startsWith(" ") ||
59+
text.startsWith("language=") ||
60+
text.startsWith("noinspection") ||
61+
text.startsWith("region") ||
62+
text.startsWith("endregion")) {
5963
return comment;
6064
}
6165
return tc.withText(" " + text);

src/test/java/org/openrewrite/staticanalysis/SingleLineCommentSpacingTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void method() {
102102
}
103103

104104
@Test
105-
void skipsSpecialComment() {
105+
void skipsLanguageComment() {
106106
rewriteRun(
107107
//language=java
108108
java(
@@ -117,4 +117,39 @@ void method() {
117117
)
118118
);
119119
}
120+
121+
@Test
122+
void skipsNoinspectionComment() {
123+
rewriteRun(
124+
//language=java
125+
java(
126+
"""
127+
class Test {
128+
@SuppressWarnings("unchecked")
129+
void method() {
130+
//noinspection unchecked
131+
int a = 1;
132+
}
133+
}
134+
"""
135+
)
136+
);
137+
}
138+
139+
@Test
140+
void skipsRegionComments() {
141+
rewriteRun(
142+
//language=java
143+
java(
144+
"""
145+
class Test {
146+
//region MyRegion
147+
void method() {
148+
}
149+
//endregion
150+
}
151+
"""
152+
)
153+
);
154+
}
120155
}

0 commit comments

Comments
 (0)