Skip to content

Commit 4ed7867

Browse files
jablkoljharb
authored andcommitted
[Fix] no-unresolved: ignore type-only imports
1 parent 4d15e26 commit 4ed7867

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
66

77
## [Unreleased]
88

9-
### Changed
10-
- [Refactor] switch to an internal replacement for `pkg-up` and `read-pkg-up` ([#2047], thanks [@mgwalker])
11-
- [patch] TypeScript config: remove `.d.ts` from [`import/parsers` setting] and [`import/extensions` setting] ([#2220], thanks [@jablko])
12-
139
### Added
1410
- [`no-unresolved`]: add `caseSensitiveStrict` option ([#1262], thanks [@sergei-startsev])
1511
- [`no-unused-modules`]: add eslint v8 support ([#2194], thanks [@coderaiser])
1612
- [`no-restricted-paths`]: add/restore glob pattern support ([#2219], thanks [@stropho])
1713
- [`no-unused-modules`]: support dynamic imports ([#1660], [#2212], thanks [@maxkomarychev], [@aladdin-add], [@Hypnosphi])
1814

15+
### Fixed
16+
- [`no-unresolved`]: ignore type-only imports ([#2220], thanks [@jablko])
17+
18+
### Changed
19+
- [Refactor] switch to an internal replacement for `pkg-up` and `read-pkg-up` ([#2047], thanks [@mgwalker])
20+
- [patch] TypeScript config: remove `.d.ts` from [`import/parsers` setting] and [`import/extensions` setting] ([#2220], thanks [@jablko])
21+
1922
## [2.24.2] - 2021-08-24
2023

2124
### Fixed

src/rules/no-unresolved.js

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

2929
function checkSourceValue(source) {
30+
// ignore type-only imports
31+
if (source.parent && source.parent.importKind === 'type') {
32+
return;
33+
}
34+
3035
const caseSensitive = !CASE_SENSITIVE_FS && options.caseSensitive !== false;
3136
const caseSensitiveStrict = !CASE_SENSITIVE_FS && options.caseSensitiveStrict;
3237

tests/src/rules/no-unresolved.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path';
22

3-
import { test, SYNTAX_CASES, testVersion } from '../utils';
3+
import { getTSParsers, test, SYNTAX_CASES, testVersion } from '../utils';
44

55
import { CASE_SENSITIVE_FS } from 'eslint-module-utils/resolve';
66

@@ -441,3 +441,23 @@ ruleTester.run('import() with built-in parser', rule, {
441441
})) || [],
442442
),
443443
});
444+
445+
context('TypeScript', () => {
446+
getTSParsers().filter(x => x !== require.resolve('typescript-eslint-parser')).forEach((parser) => {
447+
ruleTester.run(`${parser}: no-unresolved ignore type-only`, rule, {
448+
valid: [
449+
test({
450+
code: 'import type { JSONSchema7Type } from "@types/json-schema";',
451+
parser,
452+
}),
453+
],
454+
invalid: [
455+
test({
456+
code: 'import { JSONSchema7Type } from "@types/json-schema";',
457+
errors: [ "Unable to resolve path to module '@types/json-schema'." ],
458+
parser,
459+
}),
460+
],
461+
});
462+
});
463+
});

0 commit comments

Comments
 (0)