Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 31 commits into from Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fb41191
feat(eslint-plugin): [consistent-type-imports] support fixing to inli…
snewcomer May 23, 2022
f78de8c
first pass fix to simpler fixer
snewcomer Jun 5, 2022
4bfcabf
cleanup pass 2
snewcomer Jun 5, 2022
0cbcc64
add test for default import
snewcomer Jun 5, 2022
2ed8a09
add some docs
snewcomer Jun 5, 2022
19dbb49
add moar test cases
snewcomer Jun 5, 2022
6751315
add failing test
snewcomer Jun 5, 2022
be1930a
use aImportIsOnlyTypes instead of inlineTypes message
snewcomer Jun 5, 2022
2b727f8
wip
snewcomer Jun 6, 2022
24df1da
fix for default import inline
snewcomer Jun 6, 2022
14241ae
fix another case with as
snewcomer Jun 6, 2022
0925a7f
simplify by using existing typeOverValue func
snewcomer Jun 6, 2022
71bbdf6
add some commentse
snewcomer Jun 6, 2022
6b2f1a7
add another test for two imports from same source
snewcomer Jun 6, 2022
4f43a77
better doc with link to 4.5
snewcomer Jun 6, 2022
043933e
fix lint
snewcomer Jun 6, 2022
a50cd23
cleanup comments
snewcomer Jun 6, 2022
cf703a0
Update packages/eslint-plugin/docs/rules/consistent-type-imports.md
snewcomer Jul 25, 2022
6798d7e
Update packages/eslint-plugin/docs/rules/consistent-type-imports.md
snewcomer Jul 25, 2022
055db8d
Update packages/eslint-plugin/docs/rules/consistent-type-imports.md
snewcomer Jul 25, 2022
7104930
Update packages/eslint-plugin/src/rules/consistent-type-imports.ts
snewcomer Jul 25, 2022
696ddb5
Update packages/eslint-plugin/src/rules/consistent-type-imports.ts
snewcomer Jul 25, 2022
821add2
fix changelog formatting
snewcomer Nov 6, 2022
849c2eb
Update packages/eslint-plugin/docs/rules/consistent-type-imports.md
snewcomer Nov 7, 2022
77298af
try single quotest
snewcomer Nov 7, 2022
2b18686
cleanup not valid comment anymore
snewcomer Nov 7, 2022
ec60d5b
Update packages/eslint-plugin/tests/rules/consistent-type-imports.tes…
snewcomer Nov 7, 2022
83d095b
Update packages/eslint-plugin/tests/rules/consistent-type-imports.tes…
snewcomer Nov 7, 2022
12dad78
rm comment
snewcomer Nov 7, 2022
5c26e08
improve documentation with feedback
snewcomer Nov 7, 2022
f92cefd
add tabs
snewcomer Nov 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 39 additions & 1 deletion packages/eslint-plugin/docs/rules/consistent-type-imports.md
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 is the default.
- `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