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

Fix crash due to export * with no-unused-modules #1496

Merged
merged 1 commit into from
Dec 5, 2019
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`import/order`]: fix autofix to not move imports across fn calls ([#1253], thanks [@tihonove])
- [`prefer-default-export`]: fix false positive with type export ([#1506], thanks [@golopot])
- [`extensions`]: Fix `ignorePackages` to produce errors ([#1521], thanks [@saschanaz])
- [`no-unused-modules`]: fix crash due to `export *` ([#1496], thanks [@Taranys])

### Docs
- [`no-useless-path-segments`]: add docs for option `commonjs` ([#1507], thanks [@golopot])
@@ -626,6 +627,7 @@ for info on changes for earlier releases.
[#1519]: https://github.com/benmosher/eslint-plugin-import/pull/1519
[#1507]: https://github.com/benmosher/eslint-plugin-import/pull/1507
[#1506]: https://github.com/benmosher/eslint-plugin-import/pull/1506
[#1496]: https://github.com/benmosher/eslint-plugin-import/pull/1496
[#1495]: https://github.com/benmosher/eslint-plugin-import/pull/1495
[#1472]: https://github.com/benmosher/eslint-plugin-import/pull/1472
[#1470]: https://github.com/benmosher/eslint-plugin-import/pull/1470
@@ -1016,3 +1018,4 @@ for info on changes for earlier releases.
[@brendo]: https://github.com/brendo
[@saschanaz]: https://github.com/saschanaz
[@brettz9]: https://github.com/brettz9
[@Taranys]: https://github.com/Taranys
9 changes: 7 additions & 2 deletions src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
@@ -88,8 +88,13 @@ const prepareImportsAndExports = (srcFiles, context) => {

// dependencies === export * from
const currentExportAll = new Set()
dependencies.forEach(value => {
currentExportAll.add(value().path)
dependencies.forEach(getDependency => {
const dependency = getDependency()
if (dependency === null) {
return
}

currentExportAll.add(dependency.path)
})
exportAll.set(file, currentExportAll)

7 changes: 7 additions & 0 deletions tests/files/no-unused-modules/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Simple import extracted from 'redux-starter-kit' compiled file

function isPlain(val) {
return true;
}

exports.isPlain = isPlain;
1 change: 1 addition & 0 deletions tests/files/no-unused-modules/filte-r.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './cjs'
16 changes: 16 additions & 0 deletions tests/src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
@@ -453,6 +453,11 @@ describe('test behaviour for new file', () => {
test({ options: unusedExportsOptions,
code: `export * from '${testFilePath('./no-unused-modules/file-added-0.js')}'`,
filename: testFilePath('./no-unused-modules/file-0.js')}),
// Test export * from 'external-compiled-library'
test({ options: unusedExportsOptions,
code: `export * from 'external-compiled-library'`,
filename: testFilePath('./no-unused-modules/file-r.js'),
}),
],
invalid: [
test({ options: unusedExportsOptions,
@@ -670,3 +675,14 @@ describe('correctly report flow types', () => {
],
})
})

describe('Avoid errors if re-export all from umd compiled library', () => {
ruleTester.run('no-unused-modules', rule, {
valid: [
test({ options: unusedExportsOptions,
code: `export * from '${testFilePath('./no-unused-modules/bin.js')}'`,
filename: testFilePath('./no-unused-modules/main/index.js')}),
],
invalid: [],
})
})