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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## [Unreleased]

### Fixed
- [`extensions`]: ignore type-only imports ([#2270], [@jablko])

## [2.25.2] - 2021-10-12

### Fixed
Expand Down Expand Up @@ -929,6 +932,7 @@ for info on changes for earlier releases.

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

[#2270]: https://github.com/import-js/eslint-plugin-import/pull/2270
[#2240]: https://github.com/import-js/eslint-plugin-import/pull/2240
[#2233]: https://github.com/import-js/eslint-plugin-import/pull/2233
[#2226]: https://github.com/import-js/eslint-plugin-import/pull/2226
Expand Down
7 changes: 6 additions & 1 deletion src/rules/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ module.exports = {
return false;
}

function checkFileExtension(source) {
function checkFileExtension(source, node) {
// ignore type-only imports
if (node.importKind === 'type') {
return;
}

// bail if the declaration doesn't have a source, e.g. "export { foo };", or if it's only partially typed like in an editor
if (!source || !source.value) return;

Expand Down
33 changes: 32 additions & 1 deletion tests/src/rules/extensions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RuleTester } from 'eslint';
import rule from 'rules/extensions';
import { test, testFilePath } from '../utils';
import { getTSParsers, test, testFilePath } from '../utils';

const ruleTester = new RuleTester();

Expand Down Expand Up @@ -597,3 +597,34 @@ ruleTester.run('extensions', rule, {
}),
],
});

describe('TypeScript', () => {
getTSParsers()
// Type-only imports were added in TypeScript ESTree 2.23.0
.filter((parser) => parser !== require.resolve('typescript-eslint-parser'))
.forEach((parser) => {
ruleTester.run(`${parser}: extensions ignore type-only`, rule, {
valid: [
test({
code: 'import type { T } from "./typescript-declare";',
options: [
'always',
{ ts: 'never', tsx: 'never', js: 'never', jsx: 'never' },
],
parser,
}),
],
invalid: [
test({
code: 'import { T } from "./typescript-declare";',
errors: ['Missing file extension for "./typescript-declare"'],
options: [
'always',
{ ts: 'never', tsx: 'never', js: 'never', jsx: 'never' },
],
parser,
}),
],
});
});
});