import-js/eslint-plugin-import

[BUG] `no-unused-modules` doesn't support the export-default-from syntax

Open

#1,938 opened on 2020年11月8日

GitHub で見る
 (0 comments) (0 reactions) (0 assignees)JavaScript (1,540 forks)batch import
bughelp wanted

Repository metrics

Stars
 (4,946 stars)
PR merge metrics
 (平均マージ 138d 22h) (30d で 3 merged PRs)

説明

When using the version 2.22.1, the syntax described in the ECMAScript Proposal export default from doesn't seem to be supported by the rule no-unused-modules:

// index.js
export Component from './Component';
$ eslint .
Oops! Something went wrong! :(

ESLint: 7.12.1

TypeError: Cannot read property 'name' of undefined
Occurred while linting /Users/me/project/src/components/index.js:2
    at /Users/me/project/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:675:46
    at Array.forEach (<anonymous>)
    at /Users/me/project/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:671:32
    at Array.forEach (<anonymous>)
    at updateImportUsage (/Users/me/project/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:664:17)
    at Program:exit (/Users/me/project/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:895:9)
    at /Users/me/project/node_modules/babel-eslint/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/me/project/node_modules/babel-eslint/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/me/project/node_modules/babel-eslint/node_modules/eslint/lib/linter/node-event-generator.js:254:26)

As a workaround, we could use this syntax to achieve the same goal:

// index.js
export { default as Component } from './Component';

コントリビューターガイド