-
Notifications
You must be signed in to change notification settings - Fork 45
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
Feature: Customizable sort-array
#422
Comments
What do you think about this? Curious to hear your opinions? |
Looks good. But it's going to be a breaking change. And I'd rather do it later. Since we had a major release recently. |
@azat-io We could keep |
@hugop95, I like the idea very much: powerful and I confess I would use it since there are many contexts where order doesn't matter. Just wondering if |
I think it's better to have two separate |
@hugop95 What would be the default settings for this rule? |
@OlivierZal Placeholder name for now! We can think about that later! @azat-io A configuration that does what |
I'm a little concerned that this is a pretty insecure feature and the order of the arrays matters. And code safety is a top priority for us. So it makes sense to discuss how it will work. |
By default, the rule would do the same as what
For example: Default configuration to sort the same as {
'perfectionist/sort-array': [
'error',
{
useConfigurationIf: {
anyOf: [
{
isArrayDeclaration: true,
calledMethodMatchesPattern: "^includes$" // Sort array includes
}
]
},
},
{
type: 'unsorted' // Fallback configuration: don't sort anything else
}
],
} The main drawbacks is that:
Advantages:
Let me know if something isn't clear! |
Describe the rule
I often build enums and associated types from constant arrays in my projects:
I would like all of those arrays to be sorted.
Today,
sort-array-includes
andsort-sets
don't affect them.Current rules
sort-array-includes
andsort-sets
generally do the same things: they sortarrays
under different condition. This feature proposal is also related to sortingarrays
, but with another different condition.Proposal
Create a new rule
sort-array
while allowing users to choose the configuration they want depending on their needs.sort-array-includes
andsort-sets
could be deprecated until next major version release.Example configuration with
useConfigurationIf
(placeholder option names)Advantages
Cons
Validations
The text was updated successfully, but these errors were encountered: