Skip to content

Add ast-grep Groovy lint foundations#7330

Open
edmundmiller wants to merge 2 commits into
masterfrom
astgrep-lint-foundations
Open

Add ast-grep Groovy lint foundations#7330
edmundmiller wants to merge 2 commits into
masterfrom
astgrep-lint-foundations

Conversation

@edmundmiller

Copy link
Copy Markdown
Member

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-import

It 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 AccessDeniedException clashed because both packages were star-imported. Note this Groovy-only linter would not have caught that .java case; 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:19import javax.swing.*
  • plugins/nf-tower/src/main/io/seqera/tower/plugin/auth/AuthCommandImpl.groovy:24import 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.sh fetches 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 compiles groovy.dylib locally. 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.yml registers groovy as an ast-grep custom language.
  • .config/astgrep/rules/ holds one YAML lint rule per file.

Usage

cd .config/astgrep && ./build.sh          # once
ast-grep scan -c .config/astgrep/sgconfig.yml

Requires ast-grep (>= 0.44) and a C compiler.

Notes

  • Advisory onlyseverity: warning; not wired into CI, nothing blocks.
  • Intended follow-up rules (separate PRs): no-print-stack-trace, no-system-out-println (both tie to the @Slf4j logger convention), no-thread-sleep, and optionally static-wildcard imports.

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>
@netlify

netlify Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploy Preview for nextflow-docs canceled.

Name Link
🔨 Latest commit 6b133fa
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs/deploys/6a5540fbfa386b0008f9ee4a

- 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>
@edmundmiller edmundmiller marked this pull request as ready for review July 13, 2026 23:13
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.

1 participant