Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(eslint-plugin): [consistent-type-imports] support fixing to inline types#5050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
31 commits
Select commitHold shift + click to select a range
fb41191
feat(eslint-plugin): [consistent-type-imports] support fixing to inli…
snewcomerMay 23, 2022
f78de8c
first pass fix to simpler fixer
snewcomerJun 5, 2022
4bfcabf
cleanup pass 2
snewcomerJun 5, 2022
0cbcc64
add test for default import
snewcomerJun 5, 2022
2ed8a09
add some docs
snewcomerJun 5, 2022
19dbb49
add moar test cases
snewcomerJun 5, 2022
6751315
add failing test
snewcomerJun 5, 2022
be1930a
use aImportIsOnlyTypes instead of inlineTypes message
snewcomerJun 5, 2022
2b727f8
wip
snewcomerJun 6, 2022
24df1da
fix for default import inline
snewcomerJun 6, 2022
14241ae
fix another case with as
snewcomerJun 6, 2022
0925a7f
simplify by using existing typeOverValue func
snewcomerJun 6, 2022
71bbdf6
add some commentse
snewcomerJun 6, 2022
6b2f1a7
add another test for two imports from same source
snewcomerJun 6, 2022
4f43a77
better doc with link to 4.5
snewcomerJun 6, 2022
043933e
fix lint
snewcomerJun 6, 2022
a50cd23
cleanup comments
snewcomerJun 6, 2022
cf703a0
Update packages/eslint-plugin/docs/rules/consistent-type-imports.md
snewcomerJul 25, 2022
6798d7e
Update packages/eslint-plugin/docs/rules/consistent-type-imports.md
snewcomerJul 25, 2022
055db8d
Update packages/eslint-plugin/docs/rules/consistent-type-imports.md
snewcomerJul 25, 2022
7104930
Update packages/eslint-plugin/src/rules/consistent-type-imports.ts
snewcomerJul 25, 2022
696ddb5
Update packages/eslint-plugin/src/rules/consistent-type-imports.ts
snewcomerJul 25, 2022
821add2
fix changelog formatting
snewcomerNov 6, 2022
849c2eb
Update packages/eslint-plugin/docs/rules/consistent-type-imports.md
snewcomerNov 7, 2022
77298af
try single quotest
snewcomerNov 7, 2022
2b18686
cleanup not valid comment anymore
snewcomerNov 7, 2022
ec60d5b
Update packages/eslint-plugin/tests/rules/consistent-type-imports.tes…
snewcomerNov 7, 2022
83d095b
Update packages/eslint-plugin/tests/rules/consistent-type-imports.tes…
snewcomerNov 7, 2022
12dad78
rm comment
snewcomerNov 7, 2022
5c26e08
improve documentation with feedback
snewcomerNov 7, 2022
f92cefd
add tabs
snewcomerNov 7, 2022
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
40 changes: 39 additions & 1 deletionpackages/eslint-plugin/docs/rules/consistent-type-imports.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@ This allows transpilers to drop imports without knowing the types of the depende

This option defines the expected import kind for type-only imports. Valid values for `prefer` are:

- `type-imports` will enforce that you always use `import type Foo from '...'` except referenced by metadata of decorators. It is default.
- `type-imports` will enforce that you always use `import type Foo from '...'` except referenced by metadata of decorators. It isthedefault.
- `no-type-imports` will enforce that you always use `import Foo from '...'`.

Examples of **correct** code with `{prefer: 'type-imports'}`, and **incorrect** code with `{prefer: 'no-type-imports'}`.
Expand All@@ -36,6 +36,44 @@ type T = Foo;
const x: Bar = 1;
```

### `fixStyle`

This option defines the expected type modifier to be added when an import is detected as used only in the type position. Valid values for `fixStyle` are:

- `separate-type-imports` will add the type keyword after the import keyword `import type { A } from '...'`. It is the default.
- `inline-type-imports` will inline the type keyword `import { type A } from '...'` and is only available in TypeScript 4.5 and onwards. See [documentation here](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#type-modifiers-on-import-names 'TypeScript 4.5 documentation on type modifiers and import names').

<!--tabs-->

#### ❌ Incorrect

```ts
import { Foo } from 'Foo';
import Bar from 'Bar';
type T = Foo;
const x: Bar = 1;
```

#### ✅ With `separate-type-imports`

```ts
import type { Foo } from 'Foo';
import type Bar from 'Bar';
type T = Foo;
const x: Bar = 1;
```

#### ✅ With `inline-type-imports`

```ts
import { type Foo } from 'Foo';
import type Bar from 'Bar';
type T = Foo;
const x: Bar = 1;
```

<!--tabs-->

### `disallowTypeAnnotations`

If `true`, type imports in type annotations (`import()`) are not allowed.
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp