Skip to content

Commit 6ac3d03

Browse files
committed
add some tests, add doc comment
1 parent 14e3560 commit 6ac3d03

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

docs/rules/extensions.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ import express from 'express/index';
106106
import * as path from 'path';
107107
```
108108

109+
The following patterns are considered problems when the configuration is set to "never" and the option "checkTypeImports" is set to `true`:
110+
111+
```js
112+
import type { Foo } from './foo.ts';
113+
114+
export type { Foo } from './foo.ts';
115+
```
116+
109117
The following patterns are considered problems when configuration set to "always":
110118

111119
```js
@@ -169,7 +177,7 @@ import express from 'express';
169177
import foo from '@/foo';
170178
```
171179

172-
The following patterns are considered problems when the option "checkTypeImports" is set to `true`:
180+
The following patterns are considered problems when the configuration is set to "always" and the option "checkTypeImports" is set to `true`:
173181

174182
```js
175183
import type { Foo } from './foo';

tests/src/rules/extensions.js

+49
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import rule from 'rules/extensions';
33
import { getTSParsers, test, testFilePath, parsers } from '../utils';
44

55
const ruleTester = new RuleTester();
6+
const ruleTesterWithTypeScriptImports = new RuleTester({
7+
settings: {
8+
'import/resolver': {
9+
typescript: {
10+
alwaysTryTypes: true,
11+
},
12+
},
13+
},
14+
});
615

716
ruleTester.run('extensions', rule, {
817
valid: [
@@ -660,5 +669,45 @@ describe('TypeScript', () => {
660669
}),
661670
],
662671
});
672+
ruleTesterWithTypeScriptImports.run(`${parser}: (with TS resolver) extensions are enforced for type imports/export when checkTypeImports is set`, rule, {
673+
valid: [
674+
test({
675+
code: 'import type { MyType } from "./typescript-declare.ts";',
676+
options: [
677+
'always',
678+
{ checkTypeImports: true },
679+
],
680+
parser,
681+
}),
682+
test({
683+
code: 'export type { MyType } from "./typescript-declare.ts";',
684+
options: [
685+
'always',
686+
{ checkTypeImports: true },
687+
],
688+
parser,
689+
}),
690+
],
691+
invalid: [
692+
test({
693+
code: 'import type { MyType } from "./typescript-declare";',
694+
errors: ['Missing file extension "ts" for "./typescript-declare"'],
695+
options: [
696+
'always',
697+
{ checkTypeImports: true },
698+
],
699+
parser,
700+
}),
701+
test({
702+
code: 'export type { MyType } from "./typescript-declare";',
703+
errors: ['Missing file extension "ts" for "./typescript-declare"'],
704+
options: [
705+
'always',
706+
{ checkTypeImports: true },
707+
],
708+
parser,
709+
}),
710+
],
711+
});
663712
});
664713
});

0 commit comments

Comments
 (0)