Skip to content

Commit

Permalink
[fix] no-unused-modules: make import { name as otherName } work
Browse files Browse the repository at this point in the history
  • Loading branch information
rfermann committed Apr 21, 2019
1 parent 12bbfca commit 174afbb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
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

0 comments on commit 174afbb

Please sign in to comment.