Skip to content

[@typescript-eslint/consistent-type-imports] Crash when using default imports #2775

@vlinder

Description

@vlinder
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "extends": [],
  "env": { "es6": true },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "sourceType": "module"
  },
  "plugins": ["@typescript-eslint"],
  "rules": {
    "@typescript-eslint/consistent-type-imports": ["error"]
  }
}
import Default, * as Rest from "module";
const a: Rest.A = "";

Expected Result

Expected rule to not crash.

Actual Result

The rule crashes

Additional Info

  eslint:cli CLI args: [ '<redacted>/packages/<redacted>/setup.ts', '--debug' ] +0ms
  eslint:cli Running on files +4ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '<redacted>', loose: false } ] +0ms
  eslint:ignore-pattern   processed: { basePath: '<redacted>', patterns: [ '/**/node_modules/*' ] } +3ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '<redacted>', loose: false } ] +0ms
  eslint:ignore-pattern   processed: { basePath: '<redacted>', patterns: [ '/**/node_modules/*' ] } +0ms
  eslint:file-enumerator Start to iterate files: [ '<redacted>/packages/<redacted>/setup.ts' ] +0ms
  eslint:file-enumerator File: <redacted>/packages/<redacted>/setup.ts +0ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '<redacted>', loose: false }, IgnorePattern { patterns: [ 'node_modules', 'dist', 'build' ], basePath: '<redacted>', loose: true } ] +562ms
  eslint:ignore-pattern   processed: { basePath: '<redacted>', patterns: [ '/**/node_modules/*', 'node_modules', 'dist', 'build' ] } +0ms
  eslint:ignore-pattern Check { filePath:
   '<redacted>/packages/<redacted>/setup.ts',
  dot: false,
  relativePath: 'packages/<redacted>/setup.ts',
  result: false } +1ms
  eslint:cli-engine Lint <redacted>/packages/<redacted>/setup.ts +0ms
  eslint:linter Linting code for <redacted>/packages/<redacted>/setup.ts (pass 1) +0ms
  eslint:linter Verify +0ms
  eslint:linter With ConfigArray: <redacted>/packages/<redacted>/setup.ts +0ms
  eslint:linter An error occurred while traversing +46ms
  eslint:linter Filename: <redacted>/packages/<redacted>/setup.ts +0ms
  eslint:linter Line: 1 +0ms
  eslint:linter Parser Options: { ecmaVersion: 6,
  sourceType: 'module',
  ecmaFeatures: { globalReturn: false } } +0ms
  eslint:linter Parser Path: <redacted>/node_modules/@typescript-eslint/parser/dist/index.js +0ms
  eslint:linter Settings: {} +1ms

Oops! Something went wrong! :(

ESLint: 7.13.0

TypeError: Cannot read property 'range' of undefined
Occurred while linting <redacted>/packages/<redacted>/setup.ts:1
    at SourceCode.getTokenBefore (<redacted>/node_modules/eslint/lib/source-code/token-store/index.js:298:18)
    at getFixesNamedSpecifiers (<redacted>/node_modules/@typescript-eslint/eslint-plugin/dist/rules/consistent-type-imports.js:287:74)
    at fixToTypeImport (<redacted>/node_modules/@typescript-eslint/eslint-plugin/dist/rules/consistent-type-imports.js:235:42)
    at fixToTypeImport.next (<anonymous>)
    at Object.fix (<redacted>/node_modules/@typescript-eslint/eslint-plugin/dist/rules/consistent-type-imports.js:172:48)
    at fix.next (<anonymous>)
    at Function.from (<anonymous>)
    at normalizeFixes (<redacted>/node_modules/eslint/lib/linter/report-translator.js:182:33)
    at args (<redacted>/node_modules/eslint/lib/linter/report-translator.js:347:49)
    at Object.report (<redacted>/node_modules/eslint/lib/linter/linter.js:920:41)

Versions

package version
@typescript-eslint/eslint-plugin 4.8.0
@typescript-eslint/parser 4.8.0
TypeScript 3.8.3
ESLint 7.13.0
node 10.15.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomerspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy