Skip to content

Commit 2962628

Browse files
be5invisneurolag
authored andcommitted
[Fix] order/newline-after-import: ignore TypeScript's "export import object"
Co-authored-by: be5invis <[email protected]> Co-authored-by: Manuel Thalmann <[email protected]>
1 parent 4a38ef4 commit 2962628

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1212
- [`order`]/TypeScript: properly support `import = object` expressions ([#1823], thanks [@manuth])
1313
- [`no-extraneous-dependencies`]/TypeScript: do not error when importing type from dev dependencies ([#1820], thanks [@fernandopasik])
1414
- [`default`]: avoid crash with `export =` ([#1822], thanks [@AndrewLeedham])
15+
- [`order`]/[`newline-after-import`]: ignore TypeScript's "export import object" ([#1830], thanks [@be5invis])
1516

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

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

716+
[#1830]: https://github.com/benmosher/eslint-plugin-import/pull/1830
715717
[#1824]: https://github.com/benmosher/eslint-plugin-import/pull/1824
716718
[#1823]: https://github.com/benmosher/eslint-plugin-import/pull/1823
717719
[#1822]: https://github.com/benmosher/eslint-plugin-import/pull/1822
@@ -1235,3 +1237,4 @@ for info on changes for earlier releases.
12351237
[@fernandopasik]: https://github.com/fernandopasik
12361238
[@taye]: https://github.com/taye
12371239
[@AndrewLeedham]: https://github.com/AndrewLeedham
1240+
[@be5invis]: https://github.com/be5invis

src/rules/newline-after-import.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,13 @@ after ${type} statement not followed by another ${type}.`,
119119
const { parent } = node
120120
const nodePosition = parent.body.indexOf(node)
121121
const nextNode = parent.body[nodePosition + 1]
122+
123+
// skip "export import"s
124+
if (node.type === 'TSImportEqualsDeclaration' && node.isExport) {
125+
return
126+
}
122127

123-
if (nextNode && nextNode.type !== 'ImportDeclaration' && nextNode.type !== 'TSImportEqualsDeclaration') {
128+
if (nextNode && nextNode.type !== 'ImportDeclaration' && (nextNode.type !== 'TSImportEqualsDeclaration' || nextNode.isExport)) {
124129
checkForNewLine(node, nextNode, 'import')
125130
}
126131
}

src/rules/order.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ module.exports = {
615615
TSImportEqualsDeclaration: function handleImports(node) {
616616
let name
617617
let type
618+
// skip "export import"s
619+
if (node.isExport) {
620+
return
621+
}
618622
if (node.moduleReference.type === 'TSExternalModuleReference') {
619623
name = node.moduleReference.expression.value
620624
type = 'import'

tests/src/rules/newline-after-import.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,24 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
213213
parser: parser,
214214
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
215215
},
216+
{
217+
code: `
218+
export import a = obj;\nf(a);
219+
`,
220+
parser: parser,
221+
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
222+
},
223+
{
224+
code: `
225+
import { a } from "./a";
226+
227+
export namespace SomeNamespace {
228+
export import a2 = a;
229+
f(a);
230+
}`,
231+
parser: parser,
232+
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
233+
},
216234
]),
217235
],
218236

tests/src/rules/order.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,21 @@ ruleTester.run('order', rule, {
753753
},
754754
],
755755
}),
756+
test({
757+
code: `
758+
import { a } from "./a";
759+
export namespace SomeNamespace {
760+
export import a2 = a;
761+
}
762+
`,
763+
parser,
764+
options: [
765+
{
766+
groups: ['external', 'index'],
767+
alphabetize: { order: 'asc' },
768+
},
769+
],
770+
}),
756771
]),
757772
],
758773
invalid: [

0 commit comments

Comments
 (0)