Skip to content

Commit f56a526

Browse files
committed
Ban certain javadoc tags
Closes gh-190
1 parent 76c8197 commit f56a526

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public class SpringJavadocCheck extends AbstractSpringCheck {
4444
CASE_CHECKED_TAG_PATTERNS = Collections.unmodifiableList(patterns);
4545
}
4646

47+
private static final List<Pattern> BANNED_TAGS;
48+
static {
49+
List<Pattern> patterns = new ArrayList<>();
50+
patterns.add(Pattern.compile("(@soundtrack)\\s+.*"));
51+
BANNED_TAGS = Collections.unmodifiableList(patterns);
52+
}
53+
4754
private static final Pattern SINCE_TAG_PATTERN = Pattern.compile("@since\\s+(.*)");
4855

4956
private static final Set<Integer> TOP_LEVEL_TYPES;
@@ -78,8 +85,26 @@ public void visitToken(DetailAST ast) {
7885
int lineNumber = ast.getLineNo();
7986
TextBlock javadoc = getFileContents().getJavadocBefore(lineNumber);
8087
if (javadoc != null) {
81-
checkTagCase(ast, javadoc);
82-
checkSinceTag(ast, javadoc);
88+
checkJavadoc(ast, javadoc);
89+
}
90+
}
91+
92+
private void checkJavadoc(DetailAST ast, TextBlock javadoc) {
93+
checkBannedTags(ast, javadoc);
94+
checkTagCase(ast, javadoc);
95+
checkSinceTag(ast, javadoc);
96+
}
97+
98+
private void checkBannedTags(DetailAST ast, TextBlock javadoc) {
99+
String[] text = javadoc.getText();
100+
for (int i = 0; i < text.length; i++) {
101+
for (Pattern pattern : BANNED_TAGS) {
102+
Matcher matcher = pattern.matcher(text[i]);
103+
if (matcher.find()) {
104+
String tagName = matcher.group(1).trim();
105+
log(javadoc.getStartLineNo() + i, tagName.length(), "javadoc.bannedTag", tagName);
106+
}
107+
}
83108
}
84109
}
85110

spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/check/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ catch.wideEye=''o_O'' catch variable (use "ex" instead).
33
header.unexpected=Unexpected header.
44
header.mismatch=Line does not match expected header line of ''{0}''.
55
javadoc.badCase=Javadoc element descriptions should not start with an uppercase letter.
6+
javadoc.bannedTag=Javadoc tag ''{0}'' should not be used.
67
javadoc.missingSince=Missing Javadoc @since tag.
78
javadoc.publicSince=Javadoc @since tag should not be used on private classes.
89
junit5.bannedImport=Import ''{0}'' should not be used in a JUnit 5 test.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
+Javadoc tag '@soundtrack' should not be used. [SpringJavadoc]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2017-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Valid Javadoc.
19+
*
20+
* @param <T> this is a valid param
21+
* @author Phillip Webb
22+
* @soundtrack Gina G - Ooh Aah Just A Little Bit
23+
*/
24+
public class JavadocSoundtrack<T> {
25+
26+
}

0 commit comments

Comments
 (0)