mskelton / eslint-plugin-sort

Auto-fixable sort rules for ESLint.
https://www.npmjs.com/package/eslint-plugin-sort
ISC License
24 stars 1 forks source link

feature request: Array sorting #30

Closed privatenumber closed 1 year ago

privatenumber commented 1 year ago

There are many cases where hard-coded arrays must be in order but is manually enforced.

I think ESLint can be taken advantage of to automate it by opting-in via comments on the specific array:

/* eslint-enable array-order */
/* eslint array-order: ["error", "asc"] */
const array = [1, 2, 3];
/* eslint-disable array-order */

Further examples:

mskelton commented 1 year ago

So, I'm not interested in implementing this feature into this plugin as it goes against the philosophy of this plugin which is to sort properties, imports, etc. without changing behavior of the runtime code. Now, to be fair all sorting does have runtime impact as the order of object keys can be important if you are depending on that specific order when iterating over the object properties, but generally speaking it doesn't have a runtime impact. However, this proposal will almost always have high impact to the code given the fact that arrays are primarily an ordered list of items.

Now, your proposal is reasonable from the standpoint of only sorting when you specify it with comments, but that's a pretty odd way to use an ESLint rule in my opinion as typically comments are going to be for disabling or making minor modifications rather than being the primary way of using a rule.

This coupled with the lack of use cases I see for most users of this plugin, I'm going to close this as I'm not interested in this being part of this plugin.

privatenumber commented 1 year ago

Understandable. Thank you for the thorough explanation!