[eslint-plugin] Document the @rushstack/typedef-var rule and clarify scope #5410
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
This PR resolves user confusion regarding the existence and scope of the @rushstack/typedef-var ESLint rule. Although the rule is referenced in the ESLint config rationale, it was missing from the plugin's README, leading users (as documented in Issue #5374) to question its deprecation status.
I have added comprehensive documentation to the
eslint/eslint-plugin/README.md
file. The new section clarifies the rule's strict philosophy ("reading over writing") and explicitly defines the exact local scope exemptions.Fixes #5374
Details
Problem Solved:
The primary problem was the lack of documentation, which prevented users from understanding the core difference between
@typescript-eslint/typedef
(deprecated) and@rushstack/typedef-var
(active).How it was solved:
I analyzed the
typedef-var.ts
andtypedef-var.test.ts
source files to reverse-engineer the exact scope of the rule. The new documentation section includes:for...of
/for...in
, destructuring) supported by the existing code.Consistency Question & Follow-up (Nontrivial Change):
During analysis, a potential design inconsistency was noted which I am currently seeking clarification on in the #contributor-helpline:
for...of
andfor...in
variables, but testing reveals that standardfor
loop variables (e.g.,for (var x = 0; x < 10; x++)
) are NOT exempted and require a type annotation.If this strictness on standard
for
loops is confirmed to be the intentional design, I propose submitting a follow-up PR to add an explicit failing test case totypedef-var.test.ts
to ensure this behavior is covered and prevents future regressions.How it was tested
Impacted documentation
The core documentation for the
@rushstack/eslint-plugin
package is impacted: