feat: add ctx.Globals API for native rules to read declared globals#1238
Merged
Conversation
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.
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.
fansenze
approved these changes
Jul 9, 2026
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.
Summary
ctx.Globals: a per-file map of declared globals, merged from configlanguageOptions.globalsand/* global */comments. Parsed once per file in the linter (alongsideDisableManager), so native rules read declared globals directly instead of parsing config or comments themselves.no-undefto usectx.Globals, validating the new API. This fixes two bugs:languageOptions.globalswas never consulted, and/* global */comments were parsed with a rule-local regex that ignored:off.globalssupport (GlobalAccess/GlobalsConfig) todefineConfig()'sLanguageOptions.Related Links
Checklist