-
Notifications
You must be signed in to change notification settings - Fork 44
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
Question: any options to sort the objects like expected? #436
Comments
This is not a real bug, nor a new rule proposal or a rule change request. But the repo doesn't have discussion page setup, so I posted it using bug template. Feel free to close or move it. |
Hi @ntnyq
|
Thanks for your reply. I'll leave this issue open to track it. |
@hugop95 When this is array-based customGroups is implemented for For example, I'm using panda CSS, and I have objects like:
I know can limit my rule with I would really like to leave the keys for
By convention I like to have the properties under |
This is already possible with the current {
"perfectionist/sort-objects": [
"error",
{
"useConfigurationIf": { // Make `slots` go before `base`
"callingFunctionNamePattern": "sva" // Make sure to update the plugin to v4.6.0 to get the latest fix for this: https://github.com/azat-io/eslint-plugin-perfectionist/pull/437
},
"groups": [
"slots",
"base"
],
"customGroups": {
"slots": "slots",
"base": "base"
}
},
{
"useConfigurationIf": { // Order the `base` object keys
"allNamesMatchPattern": "^root|container|nav|cta$"
},
"groups": [
"root",
"container",
"nav",
"cta"
],
"customGroups": {
"root": "root",
"container": "container",
"nav": "nav",
"cta": "cta"
}
}
]
} Explanation:Based on your expected results, I see they are two things that need to be enforced:
The array-based |
Hi @hugop95 I checked the sort-object-types docs about Is it possible to custom a group based on the property value? There is an use case: export const foobar = {
// single-line property
bar: 'bar is very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long',
// single-line property
foo: 'foo',
} I wish to define |
Hi @ntnyq |
Describe the bug
Currently, both property
baz
andbar
matches the groupmethod
and sorts alphabetically inside group.However
bar
also matches the groupmultiline
. As the docs said:It seems the first matched group owns a higher priority in sorting.
Except using
partitionBy*
orcustomGroups
, is there any options to sort the objects like the expected result?Code example
ESLint config
Output
Expected
ESLint version
Latest
ESLint Plugin Perfectionist version
Latest
Additional comments
No response
Validations
The text was updated successfully, but these errors were encountered: