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

[import/no-unused-modules] Report error on export specifier node #2842

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
- [`order`]: partial fix for [#2687] (thanks [@ljharb])
- [`no-duplicates`]: Detect across type and regular imports ([#2835], thanks [@benkrejci])
- [`extensions`]: handle `.` and `..` properly ([#2778], thanks [@benasher44])
- [`no-unused-modules`]: improve schema (thanks [@ljharb])
- [`no-unused-modules`]: improve schema (thanks [@ljharb])
- [`no-unused-modules`]: report error on binding instead of parent export ([#2842], thanks [@Chamion])

### Changed
- [Docs] [`no-duplicates`]: fix example schema ([#2684], thanks [@simmo])
Expand Down Expand Up @@ -1076,6 +1077,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#2842]: https://github.com/import-js/eslint-plugin-import/pull/2842
[#2835]: https://github.com/import-js/eslint-plugin-import/pull/2835
[#2832]: https://github.com/import-js/eslint-plugin-import/pull/2832
[#2778]: https://github.com/import-js/eslint-plugin-import/pull/2778
Expand Down Expand Up @@ -1666,6 +1668,7 @@ for info on changes for earlier releases.
[@bradzacher]: https://github.com/bradzacher
[@brendo]: https://github.com/brendo
[@brettz9]: https://github.com/brettz9
[@Chamion]: https://github.com/Chamion
[@charlessuh]: https://github.com/charlessuh
[@charpeni]: https://github.com/charpeni
[@cherryblossom000]: https://github.com/cherryblossom000
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ module.exports = {
},
ExportNamedDeclaration(node) {
node.specifiers.forEach((specifier) => {
checkUsage(node, specifier.exported.name || specifier.exported.value);
checkUsage(specifier, specifier.exported.name || specifier.exported.value);
});
forEachDeclarationIdentifier(node.declaration, (name) => {
checkUsage(node, name);
Expand Down
46 changes: 30 additions & 16 deletions tests/src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,38 @@ ruleTester.run('no-unused-modules', rule, {
invalid: [
test({
options: unusedExportsOptions,
code: `import eslint from 'eslint'
import fileA from './file-a'
import { b } from './file-b'
import { c1, c2 } from './file-c'
import { d } from './file-d'
import { e } from './file-e'
import { e2 } from './file-e'
import { h2 } from './file-h'
import * as l from './file-l'
export * from './file-n'
export { default, o0, o3 } from './file-o'
export { p } from './file-p'
import s from './file-s'`,
code: `
import eslint from 'eslint'
import fileA from './file-a'
import { b } from './file-b'
import { c1, c2 } from './file-c'
import { d } from './file-d'
import { e } from './file-e'
import { e2 } from './file-e'
import { h2 } from './file-h'
import * as l from './file-l'
export * from './file-n'
export { default, o0, o3 } from './file-o'
export { p } from './file-p'
import s from './file-s'
`,
filename: testFilePath('./no-unused-modules/file-0.js'),
errors: [
error(`exported declaration 'default' not used within other modules`),
error(`exported declaration 'o0' not used within other modules`),
error(`exported declaration 'o3' not used within other modules`),
{
message: `exported declaration 'default' not used within other modules`,
line: 12,
column: 18,
},
{
message: `exported declaration 'o0' not used within other modules`,
line: 12,
column: 27,
},
{
message: `exported declaration 'o3' not used within other modules`,
line: 12,
column: 31,
},
error(`exported declaration 'p' not used within other modules`),
],
}),
Expand Down