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

Bug: [prefer-nullish-coalescing] <internal error when linting on binary expression (||) with destruct tuple and object with rename property> #8261

Closed
4 tasks done
sasurau4 opened this issue Jan 16, 2024 · 6 comments · Fixed by #8262
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@sasurau4
Copy link

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.3.3&fileType=.tsx&code=PTAEEkDNQTwewK6gMZwLZoKYDsAuoBLbUSOAGzLgHciBzUOAJ1AEMATNu0AAxYGcUcbH1zdQuOKEaZcCRsQBuLMgkwNopOABpQAQQqEBAeQDSAWABQIcTAAOagGJxJAXlABtAEbOymFth0Ab1BKdjoALlBvcj9iAF8AXQBuS2tIBGxkXAIhEmcACgBKSKdJQNSwUCkZOWJ3SGU%2BTCCQuDDsWkiGsibQRIq%2By0t0zOzczSLQcosq6Vl5D26moNDODq7GzH6LOKGLVGF8D08WRhW2tc7WRNA3CcK9g5Eo25JNyyf8ZFelzA%2BhZ6rLhuFigAA%2BYJeEJQSSAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WlqYSNkAC1pkA9gEMkyMswDm6KL2jjokcGAC%2BILUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDAruuGAL4g9A&tokens=false

Repro Code

// If you comment in following or adding `as const` to return value of foo, All is OK
// type Foo = [boolean, { loading: boolean }];
// function foo(): Foo {
//   return [false, { loading: false }]
// }

function foo() {
  return [false, {loading: false}]
}

const  [bar, {loading: a}] = foo()

const b = false
const c = false
const loading = a || b || c;

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/prefer-nullish-coalescing": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    "strict": true
  }
}

Expected Result

No lint and internal errors

Actual Result

Following internal error happened

TypeError: Cannot read properties of undefined (reading 'some')
Occurred while linting /input.tsx:15
Rule: "@typescript-eslint/prefer-nullish-coalescing"
    at LogicalExpression[operator = "||"] (https://typescript-eslint.io/sandbox/index.js:143:58720)

Additional Info

No response

@sasurau4 sasurau4 added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jan 16, 2024
@auvred
Copy link
Member

auvred commented Jan 16, 2024

The problem is that it doesn't know what to do when type of left of LogicalExpression is any

Minimal repro: playground

Probably a bug. The rule shouldn't throw when it encounters any type

@GerroDen
Copy link

I have the same issue.
I tested it with the previous version 6.18.1 and it still runs.

@auvred
Copy link
Member

auvred commented Jan 16, 2024

The regression is caused by #8089. #8262 should fix it

@TrainedLoop

This comment has been minimized.

J12934 added a commit to juice-shop/juice-shop that referenced this issue Jan 17, 2024
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Jan 17, 2024
@jschill
Copy link

jschill commented Jan 18, 2024

It's also throwing in javascript-files (ie non-typescript files), where it's a little harder to correct the type.

@jasikpark
Copy link

I'm getting the same error when eslint tries to run the rule on one of my JS based eslint rule definitions in src/eslint-rules

webclient on  01-19-Upgrade_typescript-eslint [$] via  v18.16.0 took 5s 
❯ pnpm lint:js

> nebula-web@0.0.0 lint:js /Users/calebjasik/Git/defined.net/webclient
> eslint . --rulesdir ./eslint-rules --cache --cache-strategy content


Oops! Something went wrong! :(

ESLint: 8.56.0

TypeError: Cannot read properties of undefined (reading 'some')
Occurred while linting /Users/calebjasik/Git/defined.net/webclient/eslint-rules/jsx-no-target-blank.js:23
Rule: "@typescript-eslint/prefer-nullish-coalescing"
    at LogicalExpression[operator = "||"] (/Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/@typescript-eslint+eslint-plugin@6.19.0_@typescript-eslint+parser@6.19.0_eslint@8.56.0_typescript@5.2.2/node_modules/@typescript-eslint/eslint-plugin/dist/rules/prefer-nullish-coalescing.js:267:32)
    at ruleErrorHandler (/Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
    at /Users/calebjasik/Git/defined.net/webclient/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/linter.js:1111:32
 ELIFECYCLE  Command failed with exit code 2.

moyitpro pushed a commit to chikorita157/Sharkey-sakura that referenced this issue Jan 21, 2024
prefer-nullish-coalescing broke in the 6.19.0 update with a funky bug which has an open PR to be fixed typescript-eslint/typescript-eslint#8261
gluxon added a commit to gluxon/pnpm that referenced this issue Jan 21, 2024
typescript-eslint/typescript-eslint#8261

```
TypeError: Cannot read properties of undefined (reading 'some')
Occurred while linting /home/runner/work/pnpm/pnpm/cli/default-reporter/src/reporterForClient/pkgsDiff.ts:70
Rule: "@typescript-eslint/prefer-nullish-coalescing"
    at LogicalExpression[operator = "||"] (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/@typescript-eslint+eslint-plugin@6.19.0_@typescript-eslint+parser@6.19.0_eslint@8.56.0_typescript@5.3.3/node_modules/@typescript-eslint/eslint-plugin/dist/rules/prefer-nullish-coalescing.js:267:32)
    at ruleErrorHandler (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
    at /home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/linter.js:1111:32
```
zkochan pushed a commit to pnpm/pnpm that referenced this issue Jan 21, 2024
* chore: uppdate @typescript-eslint/* 6.11.0 -> 6.18.1

typescript-eslint/typescript-eslint#8261

```
TypeError: Cannot read properties of undefined (reading 'some')
Occurred while linting /home/runner/work/pnpm/pnpm/cli/default-reporter/src/reporterForClient/pkgsDiff.ts:70
Rule: "@typescript-eslint/prefer-nullish-coalescing"
    at LogicalExpression[operator = "||"] (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/@typescript-eslint+eslint-plugin@6.19.0_@typescript-eslint+parser@6.19.0_eslint@8.56.0_typescript@5.3.3/node_modules/@typescript-eslint/eslint-plugin/dist/rules/prefer-nullish-coalescing.js:267:32)
    at ruleErrorHandler (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
    at /home/runner/work/pnpm/pnpm/node_modules/.pnpm/eslint@8.56.0/node_modules/eslint/lib/linter/linter.js:1111:32
```

* refactor: fix instance of no-floating-promises in calc-dep-state package

```
packages/calc-dep-state/src/index.ts
  70:5  error  An array of Promises may be unintentional. Consider handling the promises' fulfillment or rejection with Promise.all or similar, or explicitly marking the expression as ignored with the `void` operator  @typescript-eslint/no-floating-promises
```
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
7 participants