Skip to content

Commit 0481dcf

Browse files
jablkoljharb
authored andcommittedOct 25, 2021
[Fix] extensions: ignore unresolvable type-only imports
1 parent 46c4709 commit 0481dcf

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed
 

‎CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
77
## [Unreleased]
88

99
### Fixed
10-
- [`extensions`]: ignore type-only imports ([#2270], [@jablko])
10+
- [`extensions`]: ignore unresolveable type-only imports ([#2270], [#2271], [@jablko])
1111

1212
## [2.25.2] - 2021-10-12
1313

@@ -932,6 +932,7 @@ for info on changes for earlier releases.
932932

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

935+
[#2271]: https://github.com/import-js/eslint-plugin-import/pull/2271
935936
[#2270]: https://github.com/import-js/eslint-plugin-import/pull/2270
936937
[#2240]: https://github.com/import-js/eslint-plugin-import/pull/2240
937938
[#2233]: https://github.com/import-js/eslint-plugin-import/pull/2233

‎src/rules/extensions.js

+2-5
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

+2-2
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)
Please sign in to comment.