feat(no-undef): support eslint-style /* global */ comments - #1498
feat(no-undef): support eslint-style /* global */ comments#1498bartlomieju wants to merge 1 commit into
/* global */ comments#1498Conversation
|
Verdict: LGTM — correct and thoroughly tested. Recommend merge (rule-behavior change, so flagging rather than auto-merging; just needs green CI / a rebase). Correctness — traced the parser against every test
Test coverage is excellent: positive cases (all forms + hints + multiline), and negatives for undeclared names, line comments, and the Minor (non-blocking)
Perf: good — one pass over comments; O(1) set lookup per identifier. (The existing linear Housekeeping: No changes requested. Good to merge once CI is green. |
The
no-undefrule only recognized identifiers from its built-in globalslist, so legitimate ambient globals (declared elsewhere, injected by a host,
or specific to a non-Deno environment) were always reported as undefined with
no way to allow them. ESLint solves this with
/* global foo */directivecomments, but deno_lint had no equivalent, leaving the comment-based escape
hatch unavailable.
This teaches
no-undefto read eslint-compatible/* global foo */and/* globals foo, bar */block comments and treat the listed names as defined.Writability hints (
foo:writable,bar:readonly, and the legacybaz:true)are parsed and ignored, since
no-undefonly cares whether a name is defined.Matching is deliberately strict: only block comments count, and the keyword
must be exactly
globalorglobalsfollowed by whitespace, so identifierslike
globalThisand line comments are never mistaken for a directive.Closes #1287