Add ast-grep Groovy lint foundations#7330
Open
edmundmiller wants to merge 2 commits into
Open
Conversation
Structural (AST-based) linting for Groovy sources via ast-grep with a compiled tree-sitter Groovy grammar registered as a custom language. - .config/astgrep/build.sh fetches dekobon/tree-sitter-groovy at pinned commit 8c70dc6 (v0.2.2) and compiles groovy.dylib locally (portable: Mach-O/macOS, ELF/Linux; nothing binary committed) - sgconfig.yml registers the groovy custom language - One starter rule (warning): no-wildcard-import, matching Nextflow's documented single-class-import style guide Run: cd .config/astgrep && ./build.sh, then ast-grep scan -c .config/astgrep/sgconfig.yml Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
✅ Deploy Preview for nextflow-docs canceled.
|
- rule-tests/no-wildcard-import-test.yml: valid + invalid cases - rule-tests/__snapshots__/: captured rule output - register testConfigs in sgconfig.yml; document 'ast-grep test' in README Run: cd .config/astgrep && ast-grep test Signed-off-by: Edmund Miller <edmund.miller@seqera.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a small ast-grep setup for structural (AST-based) linting of Groovy sources, under
.config/astgrep/. This is the foundation PR: it wires up the tooling and ships a single, advisory (warning-severity) starter rule so the mechanism can be reviewed in isolation. Further rules are intended to stack as follow-up PRs.Why lead with
no-wildcard-importIt maps directly to an already-documented house style: the Nextflow developer docs mandate single-class imports (the recommended IntelliJ setup raises the "class count to use import with
*" thresholds to 99, effectively disabling star imports). So this rule encodes an existing written convention rather than introducing a new opinion.As a secondary motivation, wildcard imports invite name collisions as the codebase evolves — a recent illustration (in Java, not Groovy) was #7100, where the AWS SDK's and the JDK's
AccessDeniedExceptionclashed because both packages were star-imported. Note this Groovy-only linter would not have caught that.javacase; it's cited only to show the class of problem wildcards create.Scoped to plain
import foo.bar.*— 2 findings today:plugins/nf-console/src/main/nextflow/ui/console/Nextflow.groovy:19—import javax.swing.*plugins/nf-tower/src/main/io/seqera/tower/plugin/auth/AuthCommandImpl.groovy:24—import java.awt.*(Static wildcard imports —
import static ...*— are idiomatic for enums/constants and Spock tests, ~106 occurrences; intentionally not flagged here. A separate rule for those could be a follow-up if desired.)How it works
.config/astgrep/build.shfetches dekobon/tree-sitter-groovy at a pinned immutable commit (8c70dc6, v0.2.2) into a gitignored.grammar-build/(not vendored), asserts the resolved SHA matches the pin, and compilesgroovy.dyliblocally. The library is native code built on each machine, so it works on macOS (Mach-O) and Linux (ELF) — nothing binary is committed..config/astgrep/sgconfig.ymlregistersgroovyas an ast-grep custom language..config/astgrep/rules/holds one YAML lint rule per file.Usage
Requires
ast-grep(>= 0.44) and a C compiler.Notes
severity: warning; not wired into CI, nothing blocks.no-print-stack-trace,no-system-out-println(both tie to the@Slf4jlogger convention),no-thread-sleep, and optionally static-wildcard imports.