Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions eslint/__snapshots__/typescript-node.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@
"@typescript-eslint/consistent-indexed-object-style": [2],
"@typescript-eslint/consistent-type-assertions": [2],
"@typescript-eslint/consistent-type-definitions": [1, "type"],
"@typescript-eslint/consistent-type-imports": [
1,
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": [
2,
{
Expand Down Expand Up @@ -437,6 +444,7 @@
"@typescript-eslint/no-for-in-array": [2],
"@typescript-eslint/no-generated-empty-object-type": [2],
"@typescript-eslint/no-implied-eval": [2],
"@typescript-eslint/no-import-type-side-effects": [1],
"@typescript-eslint/no-inferrable-types": [2],
"@typescript-eslint/no-invalid-void-type": [2],
"@typescript-eslint/no-meaningless-void-operator": [2],
Expand Down Expand Up @@ -2107,6 +2115,13 @@
"@typescript-eslint/consistent-indexed-object-style": [2],
"@typescript-eslint/consistent-type-assertions": [2],
"@typescript-eslint/consistent-type-definitions": [0, "type"],
"@typescript-eslint/consistent-type-imports": [
1,
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": [
2,
{
Expand Down Expand Up @@ -2338,6 +2353,7 @@
"@typescript-eslint/no-for-in-array": [2],
"@typescript-eslint/no-generated-empty-object-type": [2],
"@typescript-eslint/no-implied-eval": [2],
"@typescript-eslint/no-import-type-side-effects": [1],
"@typescript-eslint/no-inferrable-types": [2],
"@typescript-eslint/no-invalid-void-type": [2],
"@typescript-eslint/no-meaningless-void-operator": [2],
Expand Down Expand Up @@ -4010,6 +4026,13 @@
"@typescript-eslint/consistent-indexed-object-style": [2],
"@typescript-eslint/consistent-type-assertions": [0],
"@typescript-eslint/consistent-type-definitions": [1, "type"],
"@typescript-eslint/consistent-type-imports": [
1,
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": [
2,
{
Expand Down Expand Up @@ -4241,6 +4264,7 @@
"@typescript-eslint/no-for-in-array": [2],
"@typescript-eslint/no-generated-empty-object-type": [2],
"@typescript-eslint/no-implied-eval": [2],
"@typescript-eslint/no-import-type-side-effects": [1],
"@typescript-eslint/no-inferrable-types": [2],
"@typescript-eslint/no-invalid-void-type": [2],
"@typescript-eslint/no-meaningless-void-operator": [2],
Expand Down
32 changes: 32 additions & 0 deletions eslint/__snapshots__/typescript-react.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,13 @@
"@typescript-eslint/consistent-indexed-object-style": [2],
"@typescript-eslint/consistent-type-assertions": [2],
"@typescript-eslint/consistent-type-definitions": [1, "type"],
"@typescript-eslint/consistent-type-imports": [
1,
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": [
2,
{
Expand Down Expand Up @@ -745,6 +752,7 @@
"@typescript-eslint/no-for-in-array": [2],
"@typescript-eslint/no-generated-empty-object-type": [2],
"@typescript-eslint/no-implied-eval": [2],
"@typescript-eslint/no-import-type-side-effects": [1],
"@typescript-eslint/no-inferrable-types": [2],
"@typescript-eslint/no-invalid-void-type": [2],
"@typescript-eslint/no-meaningless-void-operator": [2],
Expand Down Expand Up @@ -2656,6 +2664,13 @@
"@typescript-eslint/consistent-indexed-object-style": [2],
"@typescript-eslint/consistent-type-assertions": [2],
"@typescript-eslint/consistent-type-definitions": [1, "type"],
"@typescript-eslint/consistent-type-imports": [
1,
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": [
2,
{
Expand Down Expand Up @@ -2887,6 +2902,7 @@
"@typescript-eslint/no-for-in-array": [2],
"@typescript-eslint/no-generated-empty-object-type": [2],
"@typescript-eslint/no-implied-eval": [2],
"@typescript-eslint/no-import-type-side-effects": [1],
"@typescript-eslint/no-inferrable-types": [2],
"@typescript-eslint/no-invalid-void-type": [2],
"@typescript-eslint/no-meaningless-void-operator": [2],
Expand Down Expand Up @@ -4881,6 +4897,13 @@
"@typescript-eslint/consistent-indexed-object-style": [2],
"@typescript-eslint/consistent-type-assertions": [0],
"@typescript-eslint/consistent-type-definitions": [1, "type"],
"@typescript-eslint/consistent-type-imports": [
1,
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": [
2,
{
Expand Down Expand Up @@ -5112,6 +5135,7 @@
"@typescript-eslint/no-for-in-array": [2],
"@typescript-eslint/no-generated-empty-object-type": [2],
"@typescript-eslint/no-implied-eval": [2],
"@typescript-eslint/no-import-type-side-effects": [1],
"@typescript-eslint/no-inferrable-types": [2],
"@typescript-eslint/no-invalid-void-type": [2],
"@typescript-eslint/no-meaningless-void-operator": [2],
Expand Down Expand Up @@ -7026,6 +7050,13 @@
"@typescript-eslint/consistent-indexed-object-style": [2],
"@typescript-eslint/consistent-type-assertions": [0],
"@typescript-eslint/consistent-type-definitions": [1, "type"],
"@typescript-eslint/consistent-type-imports": [
1,
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": [
2,
{
Expand Down Expand Up @@ -7257,6 +7288,7 @@
"@typescript-eslint/no-for-in-array": [2],
"@typescript-eslint/no-generated-empty-object-type": [2],
"@typescript-eslint/no-implied-eval": [2],
"@typescript-eslint/no-import-type-side-effects": [1],
"@typescript-eslint/no-inferrable-types": [2],
"@typescript-eslint/no-invalid-void-type": [2],
"@typescript-eslint/no-meaningless-void-operator": [2],
Expand Down
24 changes: 24 additions & 0 deletions eslint/__snapshots__/typescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@
"@typescript-eslint/consistent-indexed-object-style": [2],
"@typescript-eslint/consistent-type-assertions": [2],
"@typescript-eslint/consistent-type-definitions": [1, "type"],
"@typescript-eslint/consistent-type-imports": [
1,
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": [
2,
{
Expand Down Expand Up @@ -437,6 +444,7 @@
"@typescript-eslint/no-for-in-array": [2],
"@typescript-eslint/no-generated-empty-object-type": [2],
"@typescript-eslint/no-implied-eval": [2],
"@typescript-eslint/no-import-type-side-effects": [1],
"@typescript-eslint/no-inferrable-types": [2],
"@typescript-eslint/no-invalid-void-type": [2],
"@typescript-eslint/no-meaningless-void-operator": [2],
Expand Down Expand Up @@ -2107,6 +2115,13 @@
"@typescript-eslint/consistent-indexed-object-style": [2],
"@typescript-eslint/consistent-type-assertions": [2],
"@typescript-eslint/consistent-type-definitions": [0, "type"],
"@typescript-eslint/consistent-type-imports": [
1,
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": [
2,
{
Expand Down Expand Up @@ -2338,6 +2353,7 @@
"@typescript-eslint/no-for-in-array": [2],
"@typescript-eslint/no-generated-empty-object-type": [2],
"@typescript-eslint/no-implied-eval": [2],
"@typescript-eslint/no-import-type-side-effects": [1],
"@typescript-eslint/no-inferrable-types": [2],
"@typescript-eslint/no-invalid-void-type": [2],
"@typescript-eslint/no-meaningless-void-operator": [2],
Expand Down Expand Up @@ -4010,6 +4026,13 @@
"@typescript-eslint/consistent-indexed-object-style": [2],
"@typescript-eslint/consistent-type-assertions": [0],
"@typescript-eslint/consistent-type-definitions": [1, "type"],
"@typescript-eslint/consistent-type-imports": [
1,
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": [
2,
{
Expand Down Expand Up @@ -4241,6 +4264,7 @@
"@typescript-eslint/no-for-in-array": [2],
"@typescript-eslint/no-generated-empty-object-type": [2],
"@typescript-eslint/no-implied-eval": [2],
"@typescript-eslint/no-import-type-side-effects": [1],
"@typescript-eslint/no-inferrable-types": [2],
"@typescript-eslint/no-invalid-void-type": [2],
"@typescript-eslint/no-meaningless-void-operator": [2],
Expand Down
16 changes: 16 additions & 0 deletions eslint/presets/typescript.test/type-imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Should be an error: Channel is only used as a type
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import { Channel } from "./type-imports/channel.ts";
// Types and values from the same module can be imported in one statement
import { type Message, createMessage } from "./type-imports/message.ts";
// Imports that only contain types should use a top-level `import type`
import type { Recipient } from "./type-imports/recipient.ts";
// Should be an error: with verbatimModuleSyntax this compiles to a side-effect import
// eslint-disable-next-line @typescript-eslint/no-import-type-side-effects
import { type Sender } from "./type-imports/sender.ts";

export const send = (sender: Sender, recipient: Recipient, channel: Channel): Message =>
createMessage(`${sender.name} → ${recipient.name} via ${channel.name}`);

// import() type annotations are allowed since they are always erased
export type MessageModule = typeof import("./type-imports/message.ts");
3 changes: 3 additions & 0 deletions eslint/presets/typescript.test/type-imports/channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type Channel = {
name: string;
};
5 changes: 5 additions & 0 deletions eslint/presets/typescript.test/type-imports/message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type Message = {
text: string;
};

export const createMessage = (text: string): Message => ({ text });
3 changes: 3 additions & 0 deletions eslint/presets/typescript.test/type-imports/recipient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type Recipient = {
name: string;
};
3 changes: 3 additions & 0 deletions eslint/presets/typescript.test/type-imports/sender.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type Sender = {
name: string;
};
13 changes: 13 additions & 0 deletions eslint/rules/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export const typescript =
],
"@typescript-eslint/class-literal-property-style": "off", // https://typescript-eslint.io/rules/class-literal-property-style
"@typescript-eslint/consistent-type-definitions": ["warn", "type"], // https://typescript-eslint.io/rules/consistent-type-definitions
// Inline type specifiers avoid a second import statement from the same module.
// Combined with no-import-type-side-effects, imports that only contain types
// still use `import type` so that they are fully erased under verbatimModuleSyntax.
// `import("a").A` type annotations are allowed since they are always erased
// and are commonly used in test mocks, e.g. `importOriginal<typeof import("a")>()`.
"@typescript-eslint/consistent-type-imports": [
// https://typescript-eslint.io/rules/consistent-type-imports
"warn",
{ disallowTypeAnnotations: false, fixStyle: "inline-type-imports" },
],
"@typescript-eslint/explicit-member-accessibility": [
// https://typescript-eslint.io/rules/explicit-member-accessibility
"warn",
Expand Down Expand Up @@ -69,6 +79,9 @@ export const typescript =
],
"@typescript-eslint/no-empty-function": "off", // https://typescript-eslint.io/rules/no-empty-function
"@typescript-eslint/no-empty-interface": "off", // https://typescript-eslint.io/rules/no-empty-interface
// With verbatimModuleSyntax, `import { type A } from "a"` is compiled to `import "a"`
// which keeps the module (and its side-effects) in the bundle.
"@typescript-eslint/no-import-type-side-effects": "warn", // https://typescript-eslint.io/rules/no-import-type-side-effects
// `any` is sometimes useful for small and abstract functions.
// Should only be used in isolated parts of the codebase.
// Appropriate usage can only be checked in a PR review.
Expand Down
30 changes: 30 additions & 0 deletions oxlint/__snapshots__/typescript-node.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@
"typescript/class-literal-property-style": "allow",
"typescript/consistent-return": "warn",
"typescript/consistent-type-definitions": ["warn", ["type"]],
"typescript/consistent-type-imports": [
"warn",
[
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
]
],
"typescript/explicit-member-accessibility": [
"warn",
[
Expand All @@ -249,6 +258,7 @@
"typescript/no-floating-promises": "warn",
"typescript/no-for-in-array": "warn",
"typescript/no-implied-eval": "warn",
"typescript/no-import-type-side-effects": "warn",
"typescript/no-meaningless-void-operator": "warn",
"typescript/no-misused-new": "warn",
"typescript/no-misused-spread": "warn",
Expand Down Expand Up @@ -567,6 +577,15 @@
"typescript/class-literal-property-style": "allow",
"typescript/consistent-return": "warn",
"typescript/consistent-type-definitions": "allow",
"typescript/consistent-type-imports": [
"warn",
[
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
]
],
"typescript/explicit-member-accessibility": [
"warn",
[
Expand All @@ -593,6 +612,7 @@
"typescript/no-floating-promises": "warn",
"typescript/no-for-in-array": "warn",
"typescript/no-implied-eval": "warn",
"typescript/no-import-type-side-effects": "warn",
"typescript/no-meaningless-void-operator": "warn",
"typescript/no-misused-new": "warn",
"typescript/no-misused-spread": "warn",
Expand Down Expand Up @@ -919,6 +939,15 @@
"typescript/consistent-return": "warn",
"typescript/consistent-type-assertions": "allow",
"typescript/consistent-type-definitions": ["warn", ["type"]],
"typescript/consistent-type-imports": [
"warn",
[
{
"disallowTypeAnnotations": false,
"fixStyle": "inline-type-imports"
}
]
],
"typescript/explicit-member-accessibility": [
"warn",
[
Expand All @@ -945,6 +974,7 @@
"typescript/no-floating-promises": "warn",
"typescript/no-for-in-array": "warn",
"typescript/no-implied-eval": "warn",
"typescript/no-import-type-side-effects": "warn",
"typescript/no-meaningless-void-operator": "warn",
"typescript/no-misused-new": "warn",
"typescript/no-misused-spread": "warn",
Expand Down
Loading
Loading