Skip to content

Commit

Permalink
Merge b6242b0 into 41aaa18
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Feb 27, 2020
2 parents 41aaa18 + b6242b0 commit ec2843a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Fixed
- [`order`]: fix `isExternalModule` detect on windows ([#1651], thanks [@fisker])
- [`order`]: recognize ".." as a "parent" path ([#1658], thanks [@golopot])
- [`no-duplicates`]: fix fixer on cases with default import ([#1666], thanks [@golopot])

## [2.20.1] - 2020-02-01
### Fixed
Expand Down Expand Up @@ -655,6 +656,7 @@ for info on changes for earlier releases.

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

[#1666]: https://github.com/benmosher/eslint-plugin-import/pull/1666
[#1658]: https://github.com/benmosher/eslint-plugin-import/pull/1658
[#1651]: https://github.com/benmosher/eslint-plugin-import/pull/1651
[#1635]: https://github.com/benmosher/eslint-plugin-import/issues/1635
Expand Down
9 changes: 7 additions & 2 deletions src/rules/no-duplicates.js
Expand Up @@ -136,8 +136,13 @@ function getFix(first, rest, sourceCode) {
fixes.push(fixer.insertTextBefore(closeBrace, specifiersText))
}
} else if (!shouldAddDefault && openBrace == null && shouldAddSpecifiers) {
// `import './foo'` → `import {...} from './foo'`
fixes.push(fixer.insertTextAfter(firstToken, ` {${specifiersText}} from`))
if (first.specifiers.length === 0) {
// `import './foo'` → `import {...} from './foo'`
fixes.push(fixer.insertTextAfter(firstToken, ` {${specifiersText}} from`))
} else {
// `import def from './foo'` → `import def, {...} from './foo'`
fixes.push(fixer.insertTextAfter(first.specifiers[0], `, {${specifiersText}}`))
}
} else if (!shouldAddDefault && openBrace != null && closeBrace != null) {
// `import {...} './foo'` → `import {..., ...} from './foo'`
fixes.push(fixer.insertTextBefore(closeBrace, specifiersText))
Expand Down
6 changes: 6 additions & 0 deletions tests/src/rules/no-duplicates.js
Expand Up @@ -168,6 +168,12 @@ ruleTester.run('no-duplicates', rule, {
errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'],
}),

test({
code: "import def from './foo'; import {x} from './foo'",
output: "import def, {x} from './foo'; ",
errors: ['\'./foo\' imported multiple times.', '\'./foo\' imported multiple times.'],
}),

test({
code: "import {x} from './foo'; import def from './foo'",
output: "import def, {x} from './foo'; ",
Expand Down

0 comments on commit ec2843a

Please sign in to comment.