Skip to content

Commit

Permalink
[Fix] extensions: ignore unresolvable type-only imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Oct 25, 2021
1 parent 46c4709 commit 760f888
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/rules/extensions.js
Expand Up @@ -136,11 +136,6 @@ module.exports = {
}

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 Expand Up @@ -170,6 +165,8 @@ module.exports = {
) || isScoped(importPath);

if (!extension || !importPath.endsWith(`.${extension}`)) {
// ignore type-only imports
if (node.importKind === 'type') return;
const extensionRequired = isUseOfExtensionRequired(extension, isPackage);
const extensionForbidden = isUseOfExtensionForbidden(extension);
if (extensionRequired && !extensionForbidden) {
Expand Down
4 changes: 2 additions & 2 deletions tests/src/rules/extensions.js
Expand Up @@ -606,7 +606,7 @@ describe('TypeScript', () => {
ruleTester.run(`${parser}: extensions ignore type-only`, rule, {
valid: [
test({
code: 'import type { T } from "./typescript-declare";',
code: 'import type T from "./typescript-declare";',
options: [
'always',
{ ts: 'never', tsx: 'never', js: 'never', jsx: 'never' },
Expand All @@ -616,7 +616,7 @@ describe('TypeScript', () => {
],
invalid: [
test({
code: 'import { T } from "./typescript-declare";',
code: 'import T from "./typescript-declare";',
errors: ['Missing file extension for "./typescript-declare"'],
options: [
'always',
Expand Down

0 comments on commit 760f888

Please sign in to comment.