🌐 AI搜索 & 代理 主页
Skip to content

Bug: [consistent-type-imports] Attempts to fix the wrong import statement #7209

@OpportunityLiu

Description

@OpportunityLiu

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.

Issue Description

@typescript-eslint/consistent-type-imports went wrong with side effect import and type import.

$ /workspaces/consistent-type-imports-repro/node_modules/.bin/eslint baz.ts

Oops! Something went wrong! :(

ESLint: 8.44.0

Error: Non-null Assertion Failed: Expected to find a } for the ImportDeclaration.
Occurred while linting /workspaces/consistent-type-imports-repro/baz.ts:1
Rule: "@typescript-eslint/consistent-type-imports"
    at Object.nullThrows (/workspaces/consistent-type-imports-repro/node_modules/@typescript-eslint/utils/dist/eslint-utils/nullThrows.js:23:15)
    at fixInsertNamedSpecifiersInNamedSpecifierList (/workspaces/consistent-type-imports-repro/node_modules/@typescript-eslint/eslint-plugin/dist/rules/consistent-type-imports.js:406:44)
    at fixToValueImportDeclaration (/workspaces/consistent-type-imports-repro/node_modules/@typescript-eslint/eslint-plugin/dist/rules/consistent-type-imports.js:614:55)
    at fixToValueImportDeclaration.next (<anonymous>)
    at Object.fix (/workspaces/consistent-type-imports-repro/node_modules/@typescript-eslint/eslint-plugin/dist/rules/consistent-type-imports.js:262:56)
    at fix.next (<anonymous>)
    at Function.from (<anonymous>)
    at normalizeFixes (/workspaces/consistent-type-imports-repro/node_modules/eslint/lib/linter/report-translator.js:182:33)
    at /workspaces/consistent-type-imports-repro/node_modules/eslint/lib/linter/report-translator.js:349:49
    at Object.report (/workspaces/consistent-type-imports-repro/node_modules/eslint/lib/linter/linter.js:1021:41)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Reproduction Repository Link

https://github.com/OpportunityLiu/consistent-type-imports-repro

Repro Steps

  1. clone the repo
  2. yarn install
  3. yarn eslint baz.ts

Versions

package version
@typescript-eslint/eslint-plugin 6.0.0
@typescript-eslint/parser 6.0.0
@typescript-eslint/scope-manager 6.0.0
@typescript-eslint/typescript-estree 6.0.0
@typescript-eslint/type-utils 6.0.0
@typescript-eslint/utils 6.0.0
TypeScript 5.1.6
ESLint 8.44.0
node 18.16.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions