Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

dweiss
Copy link
Contributor

@dweiss dweiss commented Jun 18, 2025

This is a spinoff from #14804. We should allow running ast-grep (https://ast-grep.github.io/) rules as validation checks. This is a powerful tool (and fast).

For now, running ast-grep is optional. You need to install ast-grep manually and then set this build option to the location (or name) of of the ast-grep tool:

lucene.tool.ast-grep=ast-grep

I recommend doing this in build-options.local.properties. If this build option is not set, the entire task (ruleset) is ignored and a warning is printed.

I've set up CI jobs on github to install and run ast-grep as part of pull requests and on-commit checks for now.

Copy link
Contributor

This PR does not have an entry in lucene/CHANGES.txt. Consider adding one. If the PR doesn't need a changelog entry, then add the skip-changelog label to it and you will stop receiving this reminder on future updates to the PR.

@dweiss dweiss requested a review from rmuir June 18, 2025 19:46
@dweiss
Copy link
Contributor Author

dweiss commented Jun 18, 2025

I'll allow myself to merge this in without a review. I don't think anybody will object (but if anybody does, shout out).

@dweiss dweiss merged commit e61ff55 into apache:main Jun 18, 2025
6 of 7 checks passed
@dweiss dweiss deleted the ast-grep-support branch June 18, 2025 20:08
@rmuir
Copy link
Member

rmuir commented Jun 18, 2025

Thank you @dweiss, I was just slow, was testing it out. I set the property locally, and added rule and test:

---
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/refs/heads/main/schemas/rule.json
id: java-syntax
language: java
rule:
  kind: ERROR
message: Syntax Error
severity: error
---
# test the parser is working
id: java-syntax
valid:
  - x = 1;

I introduced bogus syntax to a file and the build then failed quickly on the problem (it is just an example and we probably should not do this):


> Task :testAstGrepRules
Running 1 tests

----------- Case Details -----------
PASS java-syntax  .

test result: ok. 1 passed; 0 failed;

> Task :applyAstGrepRules
error[java-syntax]: Syntax Error
    ┌─ lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java:145:50
    │
145 │   public List<LeafReaderContext> getLeafContexts([) {
    │                                                  ^

Error: 1 error(s) found in code.
Help: Scan succeeded and found error level diagnostics in the codebase.


> Task :applyAstGrepRules FAILED

@dweiss
Copy link
Contributor Author

dweiss commented Jun 18, 2025

Sorry for not waiting, I wanted to proceed. Please open a new issue with those rules. This one looks very neat indeed - we can even force it to run prior to javac. It's a C based parser for java... remember jikes? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.