Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin) [sort-type-union-intersection-members] rename to sort-type-constituents#5879
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
JoshuaKGoldberg merged 5 commits intotypescript-eslint:mainfromJoshuaKGoldberg:rename-sort-type-union-intersection-membersOct 27, 2022
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
90476de
feat(eslint-plugin) [sort-type-union-intersection-members] rename to …
JoshuaKGoldberga439f58
Sigh, test rename
JoshuaKGoldbergf0969a6
Added back rule, with replacedBy
JoshuaKGoldberg3ae3756
Fixed up rules exports
JoshuaKGoldberg03bcb7f
Merge branch 'main' into rename-sort-type-union-intersection-members
JoshuaKGoldbergFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion.eslintrc.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletionspackages/eslint-plugin/docs/rules/sort-type-constituents.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
description: 'Enforce constituents of a type union/intersection to be sorted alphabetically.' | ||
--- | ||
> 🛑 This file is source code, not the primary documentation location! 🛑 | ||
> | ||
> See **https://typescript-eslint.io/rules/sort-type-constituents** for documentation. | ||
Sorting union (`|`) and intersection (`&`) types can help: | ||
- keep your codebase standardized | ||
- find repeated types | ||
- reduce diff churn | ||
This rule reports on any types that aren't sorted alphabetically. | ||
> Types are sorted case-insensitively and treating numbers like a human would, falling back to character code sorting in case of ties. | ||
## Examples | ||
<!--tabs--> | ||
### ❌ Incorrect | ||
```ts | ||
type T1 = B | A; | ||
type T2 = { b: string } & { a: string }; | ||
type T3 = [1, 2, 4] & [1, 2, 3]; | ||
type T4 = | ||
| [1, 2, 4] | ||
| [1, 2, 3] | ||
| { b: string } | ||
| { a: string } | ||
| (() => void) | ||
| (() => string) | ||
| 'b' | ||
| 'a' | ||
| 'b' | ||
| 'a' | ||
| readonly string[] | ||
| readonly number[] | ||
| string[] | ||
| number[] | ||
| B | ||
| A | ||
| string | ||
| any; | ||
``` | ||
### ✅ Correct | ||
```ts | ||
type T1 = A | B; | ||
type T2 = { a: string } & { b: string }; | ||
type T3 = [1, 2, 3] & [1, 2, 4]; | ||
type T4 = | ||
| any | ||
| string | ||
| A | ||
| B | ||
| number[] | ||
| string[] | ||
| readonly number[] | ||
| readonly string[] | ||
| 'a' | ||
| 'b' | ||
| 'a' | ||
| 'b' | ||
| (() => string) | ||
| (() => void) | ||
| { a: string } | ||
| { b: string } | ||
| [1, 2, 3] | ||
| [1, 2, 4]; | ||
``` | ||
## Options | ||
### `groupOrder` | ||
Each constituent of the type is placed into a group, and then the rule sorts alphabetically within each group. | ||
The ordering of groups is determined by this option. | ||
- `conditional` - Conditional types (`A extends B ? C : D`) | ||
- `function` - Function and constructor types (`() => void`, `new () => type`) | ||
- `import` - Import types (`import('path')`) | ||
- `intersection` - Intersection types (`A & B`) | ||
- `keyword` - Keyword types (`any`, `string`, etc) | ||
- `literal` - Literal types (`1`, `'b'`, `true`, etc) | ||
- `named` - Named types (`A`, `A['prop']`, `B[]`, `Array<C>`) | ||
- `object` - Object types (`{ a: string }`, `{ [key: string]: number }`) | ||
- `operator` - Operator types (`keyof A`, `typeof B`, `readonly C[]`) | ||
- `tuple` - Tuple types (`[A, B, C]`) | ||
- `union` - Union types (`A | B`) | ||
- `nullish` - `null` and `undefined` |
5 changes: 5 additions & 0 deletionspackages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionpackages/eslint-plugin/src/configs/all.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletionspackages/eslint-plugin/src/rules/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.