diff --git a/CHANGELOG.md b/CHANGELOG.md index 89e7f66e80..1c8a1bb9d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ### Changed - [Tests] `named`: Run all TypeScript test ([#2427], thanks [@ProdigySim]) +### Fixed +- [`no-unresolved`, `extensions`]: ignore type only exports ([#2436], thanks [@Lukas-Kullmann]) + ## [2.26.0] - 2022-04-05 ### Added diff --git a/src/rules/extensions.js b/src/rules/extensions.js index 8596cbfd0f..0de8d5a5e6 100644 --- a/src/rules/extensions.js +++ b/src/rules/extensions.js @@ -138,7 +138,7 @@ module.exports = { function checkFileExtension(source, node) { // 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; - + const importPathWithQueryString = source.value; // don't enforce anything on builtins @@ -164,8 +164,8 @@ module.exports = { ) || isScoped(importPath); if (!extension || !importPath.endsWith(`.${extension}`)) { - // ignore type-only imports - if (node.importKind === 'type') return; + // ignore type-only imports and exports + if (node.importKind === 'type' || node.importKind === 'type') return; const extensionRequired = isUseOfExtensionRequired(extension, isPackage); const extensionForbidden = isUseOfExtensionForbidden(extension); if (extensionRequired && !extensionForbidden) { diff --git a/src/rules/no-unresolved.js b/src/rules/no-unresolved.js index b9dae97c8e..dafc7cb13f 100644 --- a/src/rules/no-unresolved.js +++ b/src/rules/no-unresolved.js @@ -27,8 +27,8 @@ module.exports = { const options = context.options[0] || {}; function checkSourceValue(source, node) { - // ignore type-only imports - if (node.importKind === 'type') { + // ignore type-only imports and exports + if (node.importKind === 'type' || node.exportKind === 'type') { return; } diff --git a/tests/src/rules/extensions.js b/tests/src/rules/extensions.js index cf93fac9f4..82ea7b3b1e 100644 --- a/tests/src/rules/extensions.js +++ b/tests/src/rules/extensions.js @@ -613,6 +613,14 @@ describe('TypeScript', () => { ], parser, }), + test({ + code: 'export type T from "./typescript-declare";', + options: [ + 'always', + { ts: 'never', tsx: 'never', js: 'never', jsx: 'never' }, + ], + parser, + }), ], invalid: [ test({ @@ -624,6 +632,15 @@ describe('TypeScript', () => { ], parser, }), + test({ + code: 'export T from "./typescript-declare";', + errors: ['Missing file extension for "./typescript-declare"'], + options: [ + 'always', + { ts: 'never', tsx: 'never', js: 'never', jsx: 'never' }, + ], + parser, + }), ], }); }); diff --git a/tests/src/rules/no-unresolved.js b/tests/src/rules/no-unresolved.js index c0252ad19d..2efaff38da 100644 --- a/tests/src/rules/no-unresolved.js +++ b/tests/src/rules/no-unresolved.js @@ -451,6 +451,10 @@ context('TypeScript', () => { code: 'import type { JSONSchema7Type } from "@types/json-schema";', parser, }), + test({ + code: 'export type { JSONSchema7Type } from "@types/json-schema";', + parser, + }), ], invalid: [ test({ @@ -458,6 +462,11 @@ context('TypeScript', () => { errors: [ "Unable to resolve path to module '@types/json-schema'." ], parser, }), + test({ + code: 'export { JSONSchema7Type } from "@types/json-schema";', + errors: [ "Unable to resolve path to module '@types/json-schema'." ], + parser, + }), ], }); });