Skip to content

Commit

Permalink
[Fix] Fixing typo in IDE section
Browse files Browse the repository at this point in the history
  • Loading branch information
darkartur committed May 3, 2020
1 parent 92caa35 commit 4278444
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/rules/no-unused-modules.js
Expand Up @@ -656,13 +656,12 @@ module.exports = {
if (astNode.source) {
resolvedPath = resolve(astNode.source.raw.replace(/('|")/g, ''), context)
astNode.specifiers.forEach(specifier => {
let name
if (specifier.exported.name === DEFAULT) {
name = IMPORT_DEFAULT_SPECIFIER
const name = specifier.local.name
if (specifier.local.name === DEFAULT) {
newDefaultImports.add(resolvedPath)
} else {
name = specifier.local.name
newImports.set(name, resolvedPath)
}
newImports.set(name, resolvedPath)
})
}
}
Expand Down
@@ -0,0 +1 @@
export default function ComponentA() {}
@@ -0,0 +1 @@
export default function ComponentB() {}
2 changes: 2 additions & 0 deletions tests/files/no-unused-modules/renameDefault-2/components.js
@@ -0,0 +1,2 @@
export { default as ComponentA } from "./ComponentA";
export { default as ComponentB } from "./ComponentB";
1 change: 1 addition & 0 deletions tests/files/no-unused-modules/renameDefault-2/usage.js
@@ -0,0 +1 @@
import { ComponentA, ComponentB } from './components'
1 change: 1 addition & 0 deletions tests/files/no-unused-modules/renameDefault/Component.js
@@ -0,0 +1 @@
export default function Component() {}
1 change: 1 addition & 0 deletions tests/files/no-unused-modules/renameDefault/components.js
@@ -0,0 +1 @@
export { default as Component } from './Component'
1 change: 1 addition & 0 deletions tests/files/no-unused-modules/renameDefault/usage.js
@@ -0,0 +1 @@
import { Component } from './components'
25 changes: 25 additions & 0 deletions tests/src/rules/no-unused-modules.js
Expand Up @@ -442,6 +442,31 @@ ruleTester.run('no-unused-modules', rule, {
invalid: [],
})

describe('renameDefault', () => {
ruleTester.run('no-unused-modules', rule, {
valid: [
test({ options: unusedExportsOptions,
code: 'export { default as Component } from "./Component"',
filename: testFilePath('./no-unused-modules/renameDefault/components.js')}),
test({ options: unusedExportsOptions,
code: 'export default function Component() {}',
filename: testFilePath('./no-unused-modules/renameDefault/Component.js')}),
],
invalid: [],
})
ruleTester.run('no-unused-modules', rule, {
valid: [
test({ options: unusedExportsOptions,
code: 'export { default as ComponentA } from "./ComponentA";export { default as ComponentB } from "./ComponentB";',
filename: testFilePath('./no-unused-modules/renameDefault-2/components.js')}),
test({ options: unusedExportsOptions,
code: 'export default function ComponentA() {};',
filename: testFilePath('./no-unused-modules/renameDefault-2/ComponentA.js')}),
],
invalid: [],
})
})

describe('test behaviour for new file', () => {
before(() => {
fs.writeFileSync(testFilePath('./no-unused-modules/file-added-0.js'), '', {encoding: 'utf8'})
Expand Down

0 comments on commit 4278444

Please sign in to comment.