Skip to content

Commit b098213

Browse files
authored
source patterns: @author/nocommit/TOOD/tabs (#14853)
The tab rule is handled by eclint for all filetypes. @author/nocommit/TOOD moved to ast-grep rules: they are easier when they only match inside comment nodes to begin with, and can give better feedback from the CLI, editor, and GH actions.
1 parent 77f0d1f commit b098213

File tree

4 files changed

+79
-6
lines changed

4 files changed

+79
-6
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ class ValidateSourcePatternsTask extends DefaultTask {
124124
@TaskAction
125125
public void check() {
126126
def invalidPatterns = [
127-
(~$/@author\b/$) : '@author javadoc tag',
128-
(~$/(?i)\bno(n|)commit\b/$) : 'nocommit',
129-
(~$/\bTOOD:/$) : 'TOOD instead TODO',
130-
(~$/\t/$) : 'tabs instead spaces',
131127
(~$/[\u202A-\u202E\u2066-\u2069]/$) : 'misuse of RTL/LTR (https://trojansource.codes)',
132128
(~$/\Q/**\E((?:\s)|(?:\*))*\Q{@inheritDoc}\E((?:\s)|(?:\*))*\Q*/\E/$) : '{@inheritDoc} on its own is unnecessary',
133129
(~$/\$$(?:LastChanged)?Date\b/$) : 'svn keyword',

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

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ note: add explicit typing on the RHS when using `var`
2626
id: javadoc-style-license-header
2727
language: java
2828
rule:
29-
matches: java-license
30-
regex: "^/[*][*]"
29+
all:
30+
- matches: java-license
31+
- matches: javadoc
3132
pattern: $TEXT
3233
# remove extraneous stars
3334
transform:
@@ -51,3 +52,42 @@ rule:
5152
stopBy: end
5253
severity: error
5354
message: license should be before `package` declaration
55+
---
56+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/refs/heads/main/schemas/java_rule.json
57+
id: javadoc-author-tag
58+
language: java
59+
rule:
60+
matches: javadoc
61+
regex: "@author"
62+
severity: error
63+
message: javadoc `@author` tags should not be used
64+
---
65+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/refs/heads/main/schemas/java_rule.json
66+
id: nocommit-comment
67+
language: java
68+
rule:
69+
regex: "nocommit:"
70+
any:
71+
- kind: line_comment
72+
- kind: block_comment
73+
severity: error
74+
message: all `nocommit:` comments must be resolved
75+
---
76+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/refs/heads/main/schemas/java_rule.json
77+
id: tood-comment
78+
language: java
79+
rule:
80+
regex: "TOOD:"
81+
any:
82+
- kind: line_comment
83+
- kind: block_comment
84+
pattern: $TEXT
85+
transform:
86+
NEWTEXT:
87+
replace:
88+
replace: "TOOD:"
89+
by: "TODO:"
90+
source: $TEXT
91+
fix: $NEWTEXT
92+
severity: error
93+
message: please write as `TODO:` instead

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,32 @@ valid:
4141
- |
4242
/* BLAH BLAH Unless required by applicable law BLAH BLAH */
4343
package foo;
44+
---
45+
id: javadoc-author-tag
46+
invalid:
47+
- |
48+
/** @author foo */
49+
valid:
50+
- |
51+
// notjavadoc @author
52+
- |
53+
/* notjavadoc @author */
54+
---
55+
id: nocommit-comment
56+
invalid:
57+
- |
58+
// nocommit: fix this
59+
- |
60+
/* nocommit: fix this */
61+
valid:
62+
- boolean nocommit = false;
63+
---
64+
id: tood-comment
65+
invalid:
66+
- |
67+
// TOOD: fix this
68+
- |
69+
/* TOOD: fix this */
70+
valid:
71+
- |
72+
var foo = "TOOD: whatever";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/refs/heads/main/schemas/java_rule.json
3+
id: javadoc
4+
language: java
5+
rule:
6+
# detect javadoc
7+
kind: block_comment
8+
regex: "^/[*][*]"

0 commit comments

Comments
 (0)