eslint-config-hardcore icon indicating copy to clipboard operation
eslint-config-hardcore copied to clipboard

Enforce alphabetical sorting of things

Open EvgenyOrekhov opened this issue 2 years ago • 3 comments

Or not?

I've never been a fan of alphabetical sorting, but I'm willing to give it a go.

Note: CSS has a better alternative (implemented in stylelint-config-recess-order and included in @twinscom/stylelint-config).

Related: https://github.com/EvgenyOrekhov/eslint-config-hardcore/issues/453

EvgenyOrekhov avatar Feb 11 '22 23:02 EvgenyOrekhov

  • I like to sort my imports by type (https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/order.md). Unless you are talking about https://eslint.org/docs/rules/sort-imports; that seems fine to me!

  • https://eslint.org/docs/rules/sort-vars has problems when variables depend on another defined in the same block:

 const b = 5, a = b + 10;

sort-vars wants me to reverse the order of a and b, but that'll throw an error due to b not being defined.

RedGuy12 avatar Feb 11 '22 23:02 RedGuy12

@RedGuy12 import/order will remain by type:

https://github.com/EvgenyOrekhov/eslint-config-hardcore/blob/755a05129b0f4801aba74819fb6d83525c86ff13/base.json#L465-L479

but inside each group items will also be sorted alphabetically, see the alphabetize option.

Regarding sort-vars, "one-var": ["error", "never"] will enforce this style which doesn't have the problem you described:

const b = 5;
const a = b + 10;

EvgenyOrekhov avatar Feb 12 '22 00:02 EvgenyOrekhov

Oh, I see that sort-vars doesn't sort separate statements, so it doesn't make sense to enable it.

EvgenyOrekhov avatar Feb 12 '22 00:02 EvgenyOrekhov