Skip to content

replace no-never-initialized-let with upstreamed no-unassigned-vars #59

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

Merged
merged 2 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configs/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ module.exports = [

// require double equal for null and undefined, triple equal everywhere else
"@foxglove/strict-equality": "error",
"@foxglove/no-never-initialized-let": "error",
"@foxglove/no-return-promise-resolve": "error",
"@foxglove/prefer-hash-private": "error",

Expand All @@ -87,6 +86,7 @@ module.exports = [
"no-implied-eval": "error",
"no-new-func": "error",

"no-unassigned-vars": "error",
// unused vars must have `_` prefix
"no-unused-vars": [
"error",
Expand Down
3 changes: 3 additions & 0 deletions configs/typescript.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ void (async () => {

void undefined; // eslint-disable-line @typescript-eslint/no-meaningless-void-operator

let x: string | undefined; // eslint-disable-line no-unassigned-vars
console.log(x);

/* eslint-enable @typescript-eslint/no-unused-expressions */
42; // eslint-disable-line @typescript-eslint/no-unused-expressions
<></>; // eslint-disable-line @typescript-eslint/no-unused-expressions
Expand Down
623 changes: 315 additions & 308 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"eslint-plugin-filenames": "^1",
"eslint-plugin-import": "^2",
"eslint-plugin-jest": "^28",
"eslint-plugin-prettier": "^5",
"eslint-plugin-react": "^7",
"eslint-plugin-react-hooks": "^5",
"eslint-plugin-prettier": "^5",
"tsutils": "^3",
"typescript-eslint": "^8"
},
"peerDependencies": {
"eslint": "^9"
"eslint": "^9.27.0"
},
"devDependencies": {
"@foxglove/eslint-plugin": "file:.",
Expand All @@ -45,8 +45,8 @@
"@swc/jest": "0.2.36",
"@types/eslint__js": "8.42.3",
"@types/jest": "29.5.14",
"@typescript-eslint/rule-tester": "8.10.0",
"eslint": "9.13.0",
"@typescript-eslint/rule-tester": "8.32.1",
"eslint": "9.27.0",
"globals": "15.11.0",
"jest": "29.7.0",
"prettier": "3.3.3",
Expand Down
1 change: 0 additions & 1 deletion plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
module.exports = {
rules: {
"no-boolean-parameters": require("./rules/no-boolean-parameters"),
"no-never-initialized-let": require("./rules/no-never-initialized-let"),
"no-restricted-imports": require("./rules/no-restricted-imports"),
"no-return-promise-resolve": require("./rules/no-return-promise-resolve"),
"prefer-hash-private": require("./rules/prefer-hash-private"),
Expand Down
32 changes: 0 additions & 32 deletions rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,6 @@ This rule accepts a single object option with the following default configuratio

- `allowLoneParameter: true` will not report an error if a boolean parameter is the **only** parameter to a function.

### [`@foxglove/no-never-initialized-let`](./no-never-initialized-let.js)

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](https://eslint.org/docs/latest/rules/prefer-const) rule doesn't flag these because they lack an initializer. Otherwise, they could be flagged by [init-declarations](https://eslint.org/docs/latest/rules/init-declarations), but this rule is mostly stylistic and has some implications for TypeScript type inference & refinement. (See [eslint/eslint#19581](https://github.com/eslint/eslint/issues/19581) & [microsoft/TypeScript#61496](https://github.com/microsoft/TypeScript/issues/61496) for more discussion.)

Examples of **incorrect** code for this rule:

```ts
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:

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

### [`@foxglove/no-return-promise-resolve`](./no-return-promise-resolve.js) 🔧

Disallow returning `Promise.resolve(...)` or `Promise.reject(...)` inside an async function. This is redundant since an async function will always return a Promise — use `return` or `throw` directly instead.
Expand Down
31 changes: 0 additions & 31 deletions rules/no-never-initialized-let.js

This file was deleted.

81 changes: 0 additions & 81 deletions rules/no-never-initialized-let.test.ts

This file was deleted.