Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`order`]/TypeScript: properly support `import = object` expressions ([#1823], thanks [@manuth])
- [`no-extraneous-dependencies`]/TypeScript: do not error when importing type from dev dependencies ([#1820], thanks [@fernandopasik])
- [`default`]: avoid crash with `export =` ([#1822], thanks [@AndrewLeedham])
- [`order`]/[`newline-after-import`]: ignore TypeScript's "export import object" ([#1830], thanks [@be5invis])

### Changed
- [`no-extraneous-dependencies`]: add tests for importing types ([#1824], thanks [@taye])
Expand Down Expand Up @@ -712,6 +713,7 @@ for info on changes for earlier releases.

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

[#1830]: https://github.com/benmosher/eslint-plugin-import/pull/1830
[#1824]: https://github.com/benmosher/eslint-plugin-import/pull/1824
[#1823]: https://github.com/benmosher/eslint-plugin-import/pull/1823
[#1822]: https://github.com/benmosher/eslint-plugin-import/pull/1822
Expand Down Expand Up @@ -1235,3 +1237,4 @@ for info on changes for earlier releases.
[@fernandopasik]: https://github.com/fernandopasik
[@taye]: https://github.com/taye
[@AndrewLeedham]: https://github.com/AndrewLeedham
[@be5invis]: https://github.com/be5invis
7 changes: 6 additions & 1 deletion src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@ after ${type} statement not followed by another ${type}.`,
const { parent } = node
const nodePosition = parent.body.indexOf(node)
const nextNode = parent.body[nodePosition + 1]

// skip "export import"s
if (node.type === 'TSImportEqualsDeclaration' && node.isExport) {
return
}

if (nextNode && nextNode.type !== 'ImportDeclaration' && nextNode.type !== 'TSImportEqualsDeclaration') {
if (nextNode && nextNode.type !== 'ImportDeclaration' && (nextNode.type !== 'TSImportEqualsDeclaration' || nextNode.isExport)) {
checkForNewLine(node, nextNode, 'import')
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ module.exports = {
TSImportEqualsDeclaration: function handleImports(node) {
let name
let type
// skip "export import"s
if (node.isExport) {
return
}
if (node.moduleReference.type === 'TSExternalModuleReference') {
name = node.moduleReference.expression.value
type = 'import'
Expand Down
18 changes: 18 additions & 0 deletions tests/src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,24 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
parser: parser,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
},
{
code: `
export import a = obj;\nf(a);
`,
parser: parser,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
},
{
code: `
import { a } from "./a";

export namespace SomeNamespace {
export import a2 = a;
f(a);
}`,
parser: parser,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
},
]),
],

Expand Down
15 changes: 15 additions & 0 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,21 @@ ruleTester.run('order', rule, {
},
],
}),
test({
code: `
import { a } from "./a";
export namespace SomeNamespace {
export import a2 = a;
}
`,
parser,
options: [
{
groups: ['external', 'index'],
alphabetize: { order: 'asc' },
},
],
}),
]),
],
invalid: [
Expand Down