Skip to content

Commit 3715dd5

Browse files
author
Lukas Kullmann
committed
[Fix] no-unresolved, extensions: ignore type-only exports
1 parent 995c12c commit 3715dd5

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1212
### Changed
1313
- [Tests] `named`: Run all TypeScript test ([#2427], thanks [@ProdigySim])
1414

15+
### Fixed
16+
- [`no-unresolved`, `extensions`]: ignore type only exports ([#], thanks [@Lukas-Kullmann])
17+
1518
## [2.26.0] - 2022-04-05
1619

1720
### Added

src/rules/extensions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ module.exports = {
138138
function checkFileExtension(source, node) {
139139
// bail if the declaration doesn't have a source, e.g. "export { foo };", or if it's only partially typed like in an editor
140140
if (!source || !source.value) return;
141-
141+
142142
const importPathWithQueryString = source.value;
143143

144144
// don't enforce anything on builtins
@@ -164,8 +164,8 @@ module.exports = {
164164
) || isScoped(importPath);
165165

166166
if (!extension || !importPath.endsWith(`.${extension}`)) {
167-
// ignore type-only imports
168-
if (node.importKind === 'type') return;
167+
// ignore type-only imports and exports
168+
if (node.importKind === 'type' || node.importKind === 'type') return;
169169
const extensionRequired = isUseOfExtensionRequired(extension, isPackage);
170170
const extensionForbidden = isUseOfExtensionForbidden(extension);
171171
if (extensionRequired && !extensionForbidden) {

src/rules/no-unresolved.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ module.exports = {
2727
const options = context.options[0] || {};
2828

2929
function checkSourceValue(source, node) {
30-
// ignore type-only imports
31-
if (node.importKind === 'type') {
30+
// ignore type-only imports and exports
31+
if (node.importKind === 'type' || node.exportKind === 'type') {
3232
return;
3333
}
3434

tests/src/rules/extensions.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,14 @@ describe('TypeScript', () => {
613613
],
614614
parser,
615615
}),
616+
test({
617+
code: 'export type T from "./typescript-declare";',
618+
options: [
619+
'always',
620+
{ ts: 'never', tsx: 'never', js: 'never', jsx: 'never' },
621+
],
622+
parser,
623+
}),
616624
],
617625
invalid: [
618626
test({
@@ -624,6 +632,15 @@ describe('TypeScript', () => {
624632
],
625633
parser,
626634
}),
635+
test({
636+
code: 'export T from "./typescript-declare";',
637+
errors: ['Missing file extension for "./typescript-declare"'],
638+
options: [
639+
'always',
640+
{ ts: 'never', tsx: 'never', js: 'never', jsx: 'never' },
641+
],
642+
parser,
643+
}),
627644
],
628645
});
629646
});

tests/src/rules/no-unresolved.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,22 @@ context('TypeScript', () => {
451451
code: 'import type { JSONSchema7Type } from "@types/json-schema";',
452452
parser,
453453
}),
454+
test({
455+
code: 'export type { JSONSchema7Type } from "@types/json-schema";',
456+
parser,
457+
}),
454458
],
455459
invalid: [
456460
test({
457461
code: 'import { JSONSchema7Type } from "@types/json-schema";',
458462
errors: [ "Unable to resolve path to module '@types/json-schema'." ],
459463
parser,
460464
}),
465+
test({
466+
code: 'export { JSONSchema7Type } from "@types/json-schema";',
467+
errors: [ "Unable to resolve path to module '@types/json-schema'." ],
468+
parser,
469+
}),
461470
],
462471
});
463472
});

0 commit comments

Comments
 (0)