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

Conversation

snewcomer
Copy link
Contributor

@snewcomer snewcomer commented May 23, 2022

PR Checklist

Overview

This PR adds a configuration option inline-type-imports that users can utilize to inline their type imports.

Previously, as on Typescript 3.8, we had the ability to import type. This import would be elided from the build deterministically.

import A, { CType } from 'foo';
import type { AType } from 'foo';
import { BType } from 'foo';

As of 4.5, we can inline that type, making it easier to manage top level imports.

import A, { type CType } from 'foo';
import type { AType } from 'foo';
import { type BType } from 'foo';

The summation of the discussion and work is as follows.

  1. fixes a Type import to Inline Type - [New] consistent-type-specifier-style: add rule import-js/eslint-plugin-import#2473.
  2. (this PR) fixes a Value import to Inline Type
  3. adds support for resolving duplicate Type imports to Inline Types to existing import source [New] no-duplicates: support inline type import with prefer-inline option import-js/eslint-plugin-import#2475

@nx-cloud
Copy link

nx-cloud bot commented May 23, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit f92cefd. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 46 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @snewcomer!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@netlify
Copy link

netlify bot commented May 23, 2022

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit f92cefd
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6369892a4ef328000850035b
😎 Deploy Preview https://deploy-preview-5050--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@snewcomer snewcomer changed the title feat: inline types feat(eslint-plugin): inline types May 23, 2022
@snewcomer snewcomer force-pushed the sn/inline-type branch 5 times, most recently from 6386e8f to c050a8f Compare May 23, 2022 14:53
@bradzacher bradzacher changed the title feat(eslint-plugin): inline types feat(eslint-plugin): [consistent-type-imports] support fixing to inline types May 23, 2022
@bradzacher bradzacher added the enhancement: plugin rule option New rule option for an existing eslint-plugin rule label May 23, 2022
@snewcomer snewcomer force-pushed the sn/inline-type branch 4 times, most recently from 1b8e40e to 19c73d2 Compare May 25, 2022 14:57
@snewcomer
Copy link
Contributor Author

Fixing a bug with inlining to a value ImportDefaultSpecifier....leaving in draft

@snewcomer snewcomer force-pushed the sn/inline-type branch 4 times, most recently from d54fbf9 to 3d525af Compare May 26, 2022 13:10
@snewcomer snewcomer force-pushed the sn/inline-type branch 5 times, most recently from 3cdb01f to fe407d4 Compare May 28, 2022 20:09
@snewcomer snewcomer marked this pull request as ready for review May 28, 2022 20:17
@snewcomer
Copy link
Contributor Author

Just a small fYI. Looks like the ember.js repo with this fixer ran on it works.

emberjs/ember.js#20101

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks very snazzy and great at first glance, thanks for sending it! I just want to confirm with @bradzacher that it's not doing more than it should? (I suspect the part of the fixer that merges imports together is not needed)

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome - thanks so much for iterating on this with us @snewcomer! I'm pumped to get this shipped 😄

@ysulyma
Copy link

ysulyma commented Nov 13, 2022

Can this be removed from the docs (https://typescript-eslint.io/rules/consistent-type-imports/#fixstyle) until it is released? I just spent several minutes troubleshooting

Error: .eslintrc.json:
	Configuration for rule "@typescript-eslint/consistent-type-imports" is invalid:
	Value {"fixStyle":"inline-type-imports"} should NOT have additional properties.

@JoshuaKGoldberg
Copy link
Member

@ysulyma sorry about that - please see #5939

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Nov 15, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) | devDependencies | minor | [`5.42.1` -> `5.43.0`](https://renovatebot.com/diffs/npm/@typescript-eslint%2feslint-plugin/5.42.1/5.43.0) |
| [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint) | devDependencies | minor | [`5.42.1` -> `5.43.0`](https://renovatebot.com/diffs/npm/@typescript-eslint%2fparser/5.42.1/5.43.0) |

---

### Release Notes

<details>
<summary>typescript-eslint/typescript-eslint (@&#8203;typescript-eslint/eslint-plugin)</summary>

### [`v5.43.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#&#8203;5430-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5421v5430-2022-11-14)

[Compare Source](typescript-eslint/typescript-eslint@v5.42.1...v5.43.0)

##### Bug Fixes

-   **eslint-plugin:** \[no-shadow] handle false positives on generics and parameters ([#&#8203;5902](typescript-eslint/typescript-eslint#5902)) ([769e8c8](typescript-eslint/typescript-eslint@769e8c8))
-   **eslint-plugin:** \[promise-function-async] handle keyword token ([#&#8203;5907](typescript-eslint/typescript-eslint#5907)) ([f25a94f](typescript-eslint/typescript-eslint@f25a94f))

##### Features

-   **eslint-plugin:** \[consistent-type-imports] support fixing to inline types ([#&#8203;5050](typescript-eslint/typescript-eslint#5050)) ([75dcdf1](typescript-eslint/typescript-eslint@75dcdf1))
-   **eslint-plugin:** \[naming-convention] add support for "override" and "async" modifiers ([#&#8203;5310](typescript-eslint/typescript-eslint#5310)) ([#&#8203;5610](typescript-eslint/typescript-eslint#5610)) ([c759da1](typescript-eslint/typescript-eslint@c759da1))
-   **eslint-plugin:** \[prefer-optional-chain] support suggesting `!foo || !foo.bar` as a valid match for the rule ([#&#8203;5594](typescript-eslint/typescript-eslint#5594)) ([923d486](typescript-eslint/typescript-eslint@923d486))

#### [5.42.1](typescript-eslint/typescript-eslint@v5.42.0...v5.42.1) (2022-11-07)

##### Bug Fixes

-   **eslint-plugin:** isTypeReadonly stack overflow ([#&#8203;5875](typescript-eslint/typescript-eslint#5875)) ([#&#8203;5876](typescript-eslint/typescript-eslint#5876)) ([2d9a33c](typescript-eslint/typescript-eslint@2d9a33c))

</details>

<details>
<summary>typescript-eslint/typescript-eslint (@&#8203;typescript-eslint/parser)</summary>

### [`v5.43.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/parser/CHANGELOG.md#&#8203;5430-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5421v5430-2022-11-14)

[Compare Source](typescript-eslint/typescript-eslint@v5.42.1...v5.43.0)

**Note:** Version bump only for package [@&#8203;typescript-eslint/parser](https://github.com/typescript-eslint/parser)

#### [5.42.1](typescript-eslint/typescript-eslint@v5.42.0...v5.42.1) (2022-11-07)

**Note:** Version bump only for package [@&#8203;typescript-eslint/parser](https://github.com/typescript-eslint/parser)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMSJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1639
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party enhancement: plugin rule option New rule option for an existing eslint-plugin rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[consistent-type-imports] prefer inline type import syntax
6 participants