GritQL plugins: expose leading-trivia / JSDoc-comment matching predicate #10479
brewpirate
started this conversation in
Ideas
Replies: 1 comment
✅ Organic activityNo automation signals detected in the analyzed events. This is an automated analysis by AgentScan |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Use case
Writing a GritQL plugin that flags exported declarations missing a preceding
/** … */block — equivalent to ESLint'seslint-plugin-tsdocsyntax check plus a presence check that doesn't yet exist there either.The presence check is the load-bearing piece: "does this exported function/class/interface/type/etc. have a
/** */block attached to it?" This is straightforwardly expressible with the TypeScript compiler API (ts.getJSDocCommentsAndTags(node)) and the internalbiome_jsdoc_commentcrate has the same primitive (JsdocComment::get_jsdocs(node)), but neither is reachable from a GritQL plugin.What I tried empirically (biome v2.4)
$fn <: not after '/** $_ */'after/beforematch sibling AST nodes, not leading-trivia comments.$fn <: not preceded_by '/** $_ */'preceded_byisn't a registered predicate; biome fails open rather than erroring.'/** $doc */ export function ...'(positive doc-capture)not $fn <: contains '/** $_ */'containschecks the function body, not its surroundings.So biome v2.4's GritQL surface cannot inspect leading comments — either via a positive
/** */capture pattern or via a negative-predicate. Trivia is unreachable from the plugin layer.What works internally — but not in plugins
crates/biome_jsdoc_comment/src/jsdoc_comment.rshas:Used by biome's own Rust-built rules and the formatter — but not exposed to GritQL plugins.
Proposal
One of:
Option A — new GritQL predicate
with_leading_jsdocBoolean predicate. Returns true if the node has at least one
/** */leading trivia piece viaget_jsdocs(node).next().is_some().Option B — expose
leading_commentsas a matchable listMore general; lets plugins also match
//-style comments above declarations (useful for documenting that single-line comments should be promoted to TSDoc — a sibling concern).Option C — positive doc-capture pattern actually works
Today this silently no-ops. If biome's GritQL pattern matcher concatenated leading trivia into the matchable text span, this would work and feels more in the spirit of GritQL's "pattern is the source" model.
Why I'm filing this
Working around the gap means projects implement a sibling TS-compiler-API scanner per repo, duplicating logic biome already has internally. Concrete example: https://github.com/brewpirate/helios/blob/main/scripts/detect-tsdoc.ts — ~400 LOC TypeScript using
ts.getJSDocCommentsAndTagsto do what a 5-line GritQL plugin should be able to express.Happy to contribute any of these options if there's appetite for direction.
Related
useTsdoclint rule (not yet shipped per Biome 2.4)All reactions