Skip to content

Commit 7fe43de

Browse files
authored
Move isolated-inheritdoc detection to an ast-grep rule (#14988)
1 parent d8cf8f7 commit 7fe43de

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

build-tools/build-infra/src/main/groovy/lucene.validation.source-patterns.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ class ValidateSourcePatternsTask extends DefaultTask {
9797

9898
@TaskAction
9999
public void check() {
100-
def invalidPatterns = [
101-
(~$/\Q/**\E((?:\s)|(?:\*))*\Q{@inheritDoc}\E((?:\s)|(?:\*))*\Q*/\E/$) : '{@inheritDoc} on its own is unnecessary',
102-
]
100+
def invalidPatterns = []
103101

104102
def violations = new TreeSet();
105103
def reportViolation = { f, name ->

gradle/validation/ast-grep/rules/java-patterns.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,12 @@ rule:
140140
pattern: incubator
141141
severity: error
142142
message: Module dependency on incubator APIs
143+
---
144+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/refs/heads/main/schemas/java_rule.json
145+
id: javadoc-only-inheriting-super
146+
language: java
147+
rule:
148+
matches: javadoc
149+
regex: "^/\\*\\*([ \r\n*])*[{]@inheritDoc[ \r\n]*[}]([ \r\n*])*\\*/$"
150+
severity: error
151+
message: "{@inheritDoc} on its own is unnecessary"

gradle/validation/ast-grep/tests/java-patterns.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,21 @@ valid:
115115
module org.apache.lucene.foo {
116116
requires org.apache.lucene.bar;
117117
}
118+
---
119+
id: javadoc-only-inheriting-super
120+
invalid:
121+
- /** {@inheritDoc} */
122+
- /** {@inheritDoc } */
123+
- "/**\n * {@inheritDoc}\n */"
124+
valid:
125+
- |
126+
/**
127+
* {@inheritDoc}
128+
*
129+
* And something.
130+
*/
131+
- |
132+
/**
133+
* Something and...
134+
* {@inheritDoc}
135+
*/

0 commit comments

Comments
 (0)