You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
9
9
### Added
10
10
- support eslint v9 ([#2996], thanks [@G-Rath][@michaelfaith])
11
11
-[`order`]: allow validating named imports ([#3043], thanks [@manuth])
12
+
-[`extensions`]: add the `checkTypeImports` option ([#2817], thanks [@phryneas])
12
13
13
14
### Fixed
14
15
-`ExportMap` / flat config: include `languageOptions` in context ([#3052], thanks [@michaelfaith])
@@ -1187,6 +1188,7 @@ for info on changes for earlier releases.
Copy file name to clipboardExpand all lines: docs/rules/extensions.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,8 @@ For example, `["error", "never", { "svg": "always" }]` would require that all ex
56
56
In that case, if you still want to specify extensions, you can do so inside the **pattern** property.
57
57
Default value of `ignorePackages` is `false`.
58
58
59
+
By default, `import type` and `export type` style imports/exports are ignored. If you want to check them as well, you can set the `checkTypeImports` option to `true`.
60
+
59
61
### Exception
60
62
61
63
When disallowing the use of certain extensions this rule makes an exception and allows the use of extension when the file would not be resolvable without extension.
@@ -104,6 +106,14 @@ import express from 'express/index';
104
106
import*aspathfrom'path';
105
107
```
106
108
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
+
importtype { Foo } from'./foo.ts';
113
+
114
+
exporttype { Foo } from'./foo.ts';
115
+
```
116
+
107
117
The following patterns are considered problems when configuration set to "always":
108
118
109
119
```js
@@ -167,6 +177,14 @@ import express from 'express';
167
177
importfoofrom'@/foo';
168
178
```
169
179
180
+
The following patterns are considered problems when the configuration is set to "always" and the option "checkTypeImports" is set to `true`:
181
+
182
+
```js
183
+
importtype { Foo } from'./foo';
184
+
185
+
exporttype { Foo } from'./foo';
186
+
```
187
+
170
188
## When Not To Use It
171
189
172
190
If you are not concerned about a consistent usage of file extension.
ruleTesterWithTypeScriptImports.run(`${parser}: (with TS resolver) extensions are enforced for type imports/export when checkTypeImports is set`,rule,{
722
+
valid: [
723
+
test({
724
+
code: 'import type { MyType } from "./typescript-declare.ts";',
725
+
options: [
726
+
'always',
727
+
{checkTypeImports: true},
728
+
],
729
+
parser,
730
+
}),
731
+
test({
732
+
code: 'export type { MyType } from "./typescript-declare.ts";',
733
+
options: [
734
+
'always',
735
+
{checkTypeImports: true},
736
+
],
737
+
parser,
738
+
}),
739
+
],
740
+
invalid: [
741
+
test({
742
+
code: 'import type { MyType } from "./typescript-declare";',
743
+
errors: ['Missing file extension "ts" for "./typescript-declare"'],
744
+
options: [
745
+
'always',
746
+
{checkTypeImports: true},
747
+
],
748
+
parser,
749
+
}),
750
+
test({
751
+
code: 'export type { MyType } from "./typescript-declare";',
752
+
errors: ['Missing file extension "ts" for "./typescript-declare"'],
0 commit comments