-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: add sortBy: "value"
related-options
#469
feat: add sortBy: "value"
related-options
#469
Conversation
ce67487
to
9f46202
Compare
- `compare` natively handles `type: unsorted` now, so we don't need those custom conditions anymore.
- This is currently not handled in custom groups.
- To `sort-object-types` and `sort-interfaces`.
- To `sort-object-types` and `sort-interfaces`.
- To `sort-object-types` and `sort-interfaces`.
9f46202
to
f20e334
Compare
LGTM. In the beginning, I thought about using Typescript to solve this problem. To have TypeScript ESLint detect the type of the value and sort them according to the type. For example, if it is a JSX props object. And the types are specified somewhere else. interface Props {
isOpen: boolean
isCompact: boolean
otherProp: string
value: string
onChange: () => {}
}
// Example:
// If booleans should be last in object
export let Component: FC<Props> = ({
onChange,
otherProp
value,
isCompact,
isOpen,
}) => {} P.S. At least I want to try to do it in another plugin: |
@azat-io I think that we would need to dive deeper into how I haven't had the time to l look into that, so I don't know if it's going to end up being hard to implement or not. The benefits can be quite big for a lot of rules from |
The benefits can be quite big, but I'm afraid it could affect the performance. |
It's always something we can put behind an option, similarly to |
Yes 👍 |
Should resolve #68
Description
This PR adds 3
sort by value
related-options tosort-object-types
andsort-interfaces
:customGroups.elementValuePattern
to match property patterns.sortBy: 'name' | 'value'
(by defaultname
).customGroups.sortBy: 'name' | 'value'
to override thesortBy
option in a given custom group.Example
Sort properties by:
ObjectId
.Date
.Users have two ways to write this: use
sortBy: 'value'
by default, and for the last group, usesortBy: 'name'
, or the opposite.Details
Or
Result:
Important notes
❓Can users sort by value alphabetically, then by name alphabetically if the values are the same ?
Currently, no. This means that
will tolerate both
and
We would need to allow users to write
This can come in a later PR.
❓How does
sortBy: 'value'
work with non-properties ?It depends if it's the base
sortBy
option, or thecustomGroups
one.Base
sortBy
optionNon-properties nodes will not have a sort order enforced.
and
are both allowed.
customGroups.sortBy
optionGrouping is still enabled, but within the group, the sort order is not enforced. This essentially means that we are enforcing the non-property member (such as functions) matching the group to be in that group, but the user can choose to move that member inside that group wherever they want.
Commit split
What is the purpose of this pull request?