Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no-never-initialized-let rule #55

Merged
merged 3 commits into from
Apr 1, 2025
Merged

Conversation

jtbandes
Copy link
Member

@jtbandes jtbandes commented Apr 1, 2025

Changelog

Added @foxglove/no-never-initialized-let (enabled by default).

Docs

Added to readme

Description

Adds a rule to fill a gap when init-declarations is not enabled. Related discussions: eslint/eslint#19581 & microsoft/TypeScript#61496

Copying from readme:

@foxglove/no-never-initialized-let

Disallow variable declarations that use let but have no intitial value and are never assigned. These variables will always be undefined and are likely a programmer error.

The builtin prefer-const rule doesn't flag these because they lack an initializer. Otherwise, they could be flagged by init-declarations, but this rule is mostly stylistic and has some implications for TypeScript type inference & refinement. (See eslint/eslint#19581 & microsoft/TypeScript#61496 for more discussion.)

Examples of incorrect code for this rule:

let prevX;
let prevY;
if (x !== prevX) {
  prevX = x;
}
if (y !== prevY) {
  prevX = x; // typo, should have been Y
}

Examples of correct code for this rule:

let prevX;
let prevY;
if (x !== prevX) {
  prevX = x;
}
if (y !== prevY) {
  prevY = y;
}

Copy link

@drdelambre drdelambre left a comment

Choose a reason for hiding this comment

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

not against it on it's face. hard to gauge impact when it's in a different repo

@jtbandes
Copy link
Member Author

jtbandes commented Apr 1, 2025

FWIW I ran it against our main repo and it did not flag any additional cases. (The one case that launched this journey has already been fixed)

So I guess not very high impact, but I think this basically always indicates a programmer error 🤷

@jtbandes jtbandes merged commit 02ada15 into main Apr 1, 2025
1 check passed
@jtbandes jtbandes deleted the jacob/no-never-initialized-let branch April 1, 2025 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants