rmuir commented on code in PR #14804:
URL: https://github.com/apache/lucene/pull/14804#discussion_r2155360626
##########
gradle/validation/ast-grep/sgconfig.yml:
##########
@@ -0,0 +1,2 @@
+ruleDirs:
+ - ./rules
Review Comment:
I've found the built-in self-test to be essential for having and keeping
correct rules. It takes milliseconds and they are easy to write.
```suggestion
- ./rules
testConfigs:
- testDir: ./tests
```
I run these with `ast-grep test --skip-snapshot-tests` before the `ast-grep
scan`.
For a rule like this one, I would add tests (untested!) like this:
`tests/errorprone.yml` (which would test rules in `rules/errorprone.yml`. I
organize them this way with `---` yaml doc separator between the rules in both
files. For multiline tests, I use yaml literal style (`|`):
https://yaml.org/spec/1.2-old/spec.html#id2795688
```yaml
---
# test wildcard import detector
id: wildcard-import-not-allowed
valid:
- import foo.bar.Baz;
- import static foo.bar.Baz;
invalid:
- import foo.bar.*;
- import static foo.bar.*;
---
# test for another error prone rule
id: some-other-errorprone-rule
invalid:
- |
if (x.equals(null) {
}
- |
foo = x.equals(null) ? 1 : 2;
# ...
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]