stylelint / eslint-config-stylelint

Stylelint org's shareable config for eslint
MIT License
60 stars 9 forks source link

An eslint rule to sort items alphabetically in `Set`, `Map`, ... #290

Closed romainmenke closed 1 month ago

romainmenke commented 1 month ago

What is the problem you're trying to solve?

There are several list we like to have sorted alphabetically. Mainly for readability and maintainability.

For example : https://github.com/stylelint/stylelint/blob/9897bf1f712a4788fdffad63a023a93ad67845e1/lib/rules/custom-property-no-missing-var-function/index.mjs#L18-L38

What solution would you like to see?

Can we automate and enforce these with an eslint rule?

Then we don't have to document this and it should ease code review.

ybiquitous commented 1 month ago

Honestly, it seems hard to force all Maps or Sets since all of them don't require alphabetical order... 🤔

romainmenke commented 1 month ago

True, and often the entries aren't string literals, sorting those could have unwanted side effects.

The reason I personally like these to be sorted is to spot duplicates. There seems to have been some progress on a similar request here : https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1559

I am going to close this for now as neither (sorting, or de-duping) actually exists today :) Thank you for your insights :)

ybiquitous commented 1 month ago

Surely, I also want a lint rule to detect duplication in a Map or Set. If it's implemented, let's reconsider to add the rule. 👍🏼