Skip to content

feat: honor /* exported */ in no-unused-vars, prefer-const and no-useless-assignment - #1770

Draft
swwind wants to merge 1 commit into
feat/port-rule-no_implicit_globals-20260816from
feat/exported-directive-consumers-20260817
Draft

feat: honor /* exported */ in no-unused-vars, prefer-const and no-useless-assignment#1770
swwind wants to merge 1 commit into
feat/port-rule-no_implicit_globals-20260816from
feat/exported-directive-consumers-20260817

Conversation

@swwind

@swwind swwind commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Consumes the inline /* exported */ API added in #1760 in the four remaining rules ESLint applies the directive to: no-unused-vars (core and @typescript-eslint), prefer-const, and no-useless-assignment.

RuleContext.IsExportedGlobalBinding(decl, name) performs the lookup ESLint does before marking a variable: the name is listed by a comment, the file's top level is the global scope, and decl binds the name in that scope. A var reaches the global scope from inside any block, while let/const/class, a function declaration, and a catch parameter belong to their nearest block scope.

Each rule then reads the flag the way its upstream counterpart does:

  • no-unused-vars, core and TypeScript, counts the directive as a use. reportUsedIgnorePattern still sees the binding as used, which is what turns a directive on an ignored name into a usedIgnoredVar report. The TypeScript scope manager puts type-only declarations in the same global scope as value ones, so the directive also reaches interface, type, enum, namespace, and import x = require().
  • prefer-const declines to judge such a global, since a separately loaded file may reassign it. Under destructuring: "all" that holds the whole destructuring group back.
  • no-useless-assignment treats it like an export: the value can still be read from outside the file, so no assignment to it is reported.

Six /* exported */ skips are removed from the core no-unused-vars upstream suite and one from no-useless-assignment's.

Checklist

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

@elecmonkey

Copy link
Copy Markdown
Member

The shared scope-gating helper and all four rule integrations match ESLint's exported-directive semantics across global, block, function, module, CommonJS, destructuring, and TypeScript-only declaration shapes. No actionable correctness, regression, performance, or maintainability issue was found.

@swwind
swwind marked this pull request as draft August 19, 2026 07:42
@swwind
swwind force-pushed the feat/exported-directive-consumers-20260817 branch from e0fe15b to 20d8f59 Compare August 20, 2026 09:25
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.

2 participants