eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

bug: TypeError: Cannot read property 'get' of undefined

Open pahan35 opened this issue 5 years ago • 5 comments

Originally discovered at https://youtrack.jetbrains.com/issue/WEB-45210

How to reproduce?

  1. Take the repo https://github.com/pahan35/web-ui-boilerplate
  2. Add new component into /src/Components/ with any code with exports. I used the next one with extra space before braces
import React from 'react'

export default function NewComponent () {
  return 'I am new component'
}

What is the expected result

I expect to see the warning from eslint about extra space, etc image

What happened instead?

Eslint fails completely for the whole file with error

TypeError: Cannot read property 'get' of undefined
Occurred while linting /Users/p35/PycharmProjects/report-from-prs-web-ui/src/NewComponent.js:3
    at checkUsage (/Users/p35/PycharmProjects/report-from-prs-web-ui/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:517:33)
    at ExportDefaultDeclaration (/Users/p35/PycharmProjects/report-from-prs-web-ui/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:895:9)
    at /Users/p35/PycharmProjects/report-from-prs-web-ui/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/p35/PycharmProjects/report-from-prs-web-ui/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/p35/PycharmProjects/report-from-prs-web-ui/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/Users/p35/PycharmProjects/report-from-prs-web-ui/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/Users/p35/PycharmProjects/report-from-prs-web-ui/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/Users/p35/PycharmProjects/report-from-prs-web-ui/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:635:23)
    at /Users/p35/PycharmProjects/report-from-prs-web-ui/node_modules/eslint/lib/linter/linter.js:949:32
Process finished with exit code -1

Recorded example

This bug is really critical for me. However, dev from JetBrain's side said that there is something wrong from the plugin side. Please fix it from your side or give advice on how to fix it

pahan35 avatar Jul 02 '20 19:07 pahan35

I can't reproduce this.

That JetBrains thread points out that there is, in fact, a difference between proper/supported eslint usage - invoking it via the CLI once per process - and keeping alive a dev server.

This plugin maintains some internal caching; specifically, it builds up a module graph of your entire codebase so it can lint across files. This works fine with other IDEs/editors, so that suggests it's an issue with JetBrains' implementation, specifically.

ljharb avatar Jul 03 '20 21:07 ljharb

There is also a problem with Visual Studio Code

Recorded example

However, it's less critical since it doesn't lead to problems with other rules.

pahan35 avatar Jul 03 '20 23:07 pahan35

Originally reported problem with creating a new file also is easily reproducible in VS Code

Recorded example

The only difference here, that others lint warnings work here, but import/no-unused-modules produces false-positive warning

pahan35 avatar Jul 04 '20 00:07 pahan35

There’s really nothing an eslint plugin can do with something that’s running eslint improperly :-/ there’d need to be some kind of feature in eslint itself to handle caching mechanisms.

ljharb avatar Jul 04 '20 02:07 ljharb

Same here on neovim, could you solve it?

Brageanth avatar Nov 24 '22 15:11 Brageanth