Skip to content

Commit 760f888

Browse files
committed
[Fix] extensions: ignore unresolvable type-only imports
1 parent 46c4709 commit 760f888

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/rules/extensions.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ module.exports = {
136136
}
137137

138138
function checkFileExtension(source, node) {
139-
// ignore type-only imports
140-
if (node.importKind === 'type') {
141-
return;
142-
}
143-
144139
// bail if the declaration doesn't have a source, e.g. "export { foo };", or if it's only partially typed like in an editor
145140
if (!source || !source.value) return;
146141

@@ -170,6 +165,8 @@ module.exports = {
170165
) || isScoped(importPath);
171166

172167
if (!extension || !importPath.endsWith(`.${extension}`)) {
168+
// ignore type-only imports
169+
if (node.importKind === 'type') return;
173170
const extensionRequired = isUseOfExtensionRequired(extension, isPackage);
174171
const extensionForbidden = isUseOfExtensionForbidden(extension);
175172
if (extensionRequired && !extensionForbidden) {

tests/src/rules/extensions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ describe('TypeScript', () => {
606606
ruleTester.run(`${parser}: extensions ignore type-only`, rule, {
607607
valid: [
608608
test({
609-
code: 'import type { T } from "./typescript-declare";',
609+
code: 'import type T from "./typescript-declare";',
610610
options: [
611611
'always',
612612
{ ts: 'never', tsx: 'never', js: 'never', jsx: 'never' },
@@ -616,7 +616,7 @@ describe('TypeScript', () => {
616616
],
617617
invalid: [
618618
test({
619-
code: 'import { T } from "./typescript-declare";',
619+
code: 'import T from "./typescript-declare";',
620620
errors: ['Missing file extension for "./typescript-declare"'],
621621
options: [
622622
'always',

0 commit comments

Comments
 (0)