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] no-unused-modules: make import { name as otherName } work #1340

Merged
merged 1 commit into from
Apr 21, 2019
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
2 changes: 1 addition & 1 deletion src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ module.exports = {
specifier.type === IMPORT_NAMESPACE_SPECIFIER) {
return
}
newImports.set(specifier.local.name, resolvedPath)
newImports.set(specifier.imported.name, resolvedPath)
})
}
})
Expand Down
30 changes: 29 additions & 1 deletion tests/src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,34 @@ ruleTester.run('no-unused-modules', rule, {
],
})

// add renamed named import for file with named export
ruleTester.run('no-unused-modules', rule, {
valid: [
test({ options: unusedExportsOptions,
code: `import { g as g1 } from '${testFilePath('./no-unused-modules/file-g.js')}'; import eslint from 'eslint'`,
filename: testFilePath('./no-unused-modules/file-0.js')}),
test({ options: unusedExportsOptions,
code: 'export const g = 2',
filename: testFilePath('./no-unused-modules/file-g.js')}),
],
invalid: [],
})

// add different renamed named import for file with named export
ruleTester.run('no-unused-modules', rule, {
valid: [
test({ options: unusedExportsOptions,
code: `import { g1 as g } from '${testFilePath('./no-unused-modules/file-g.js')}'`,
filename: testFilePath('./no-unused-modules/file-0.js')}),
],
invalid: [
test({ options: unusedExportsOptions,
code: 'export const g = 2',
filename: testFilePath('./no-unused-modules/file-g.js'),
errors: [error(`exported declaration 'g' not used within other modules`)]}),
],
})

// remove default import for file with default export
ruleTester.run('no-unused-modules', rule, {
valid: [
Expand Down Expand Up @@ -556,7 +584,7 @@ describe('do not report missing export for ignored file', () => {
test({ options: [{
src: [testFilePath('./no-unused-modules/**/*.js')],
ignoreExports: [testFilePath('./no-unused-modules/*ignored*.js')],
missingExports: true
missingExports: true,
}],
code: 'export const test = true',
filename: testFilePath('./no-unused-modules/file-ignored-a.js')}),
Expand Down