Skip to content

feat: add ctx.Globals API for native rules to read declared globals#1238

Merged
fansenze merged 3 commits into
mainfrom
fix/no-undef-scope-analysis
Jul 9, 2026
Merged

feat: add ctx.Globals API for native rules to read declared globals#1238
fansenze merged 3 commits into
mainfrom
fix/no-undef-scope-analysis

Conversation

@swwind

@swwind swwind commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add ctx.Globals: a per-file map of declared globals, merged from config languageOptions.globals and /* global */ comments. Parsed once per file in the linter (alongside DisableManager), so native rules read declared globals directly instead of parsing config or comments themselves.
  • Fix no-undef to use ctx.Globals, validating the new API. This fixes two bugs: languageOptions.globals was never consulted, and /* global */ comments were parsed with a rule-local regex that ignored :off.
  • Add typed globals support (GlobalAccess / GlobalsConfig) to defineConfig()'s LanguageOptions.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

no-undef already resolves names via the TypeChecker (RequiresTypeInfo)
and separately supports /*global*/ comments, but never consulted
config-declared languageOptions.globals, so a legitimately configured
global was reported as undefined.

Thread the resolved globals (config.ExtractGlobals) through
ConfiguredRule/RuleContext the same way Settings already flows, and
check ctx.Globals alongside the existing /*global*/ comment check.

ExtractGlobals matches ESLint's own normalizeConfigGlobal: only the
string "off" un-declares a global — boolean false and null both mean
"readonly" and still declare it.
Copilot AI review requested due to automatic review settings July 9, 2026 06:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

swwind added 2 commits July 9, 2026 14:04
Add GlobalAccess/GlobalsConfig types and a globals field to
LanguageOptions so defineConfig() stops rejecting it with a type
error. Only the three common values (boolean, 'readonly', 'writable',
'off') are typed here rather than ESLint's full legacy alias set
(readable/writeable/string-boolean).
no-undef never consulted config-declared languageOptions.globals, and its
/* global */ comment handling was a rule-local regex over raw source text
that silently ignored `:off`. Both are now parsed once per file in the
linter (alongside DisableManager) and merged into ctx.Globals, so any
native rule can consult declared globals without re-deriving config or
comment semantics itself.
@swwind swwind changed the title fix: honor languageOptions.globals in no-undef feat: add ctx.Globals API for native rules to read declared globals Jul 9, 2026
@fansenze fansenze merged commit 4b53212 into main Jul 9, 2026
14 checks passed
@fansenze fansenze deleted the fix/no-undef-scope-analysis branch July 9, 2026 10:23
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.

3 participants