regexp-tree icon indicating copy to clipboard operation
regexp-tree copied to clipboard

Option for disabling character class and flag sorting in transformations

Open brettz9 opened this issue 5 years ago • 2 comments

Hi,

While I expect this might not be trivial given that the sorting presumably helps in building ranges, it would be very useful if this resorting could be optionally disabled.

In the project, eslint-plugin-unicorn, regexp-tree is being used to otherwise very helpful effect in the rule regex-shorthand (as per https://github.com/sindresorhus/eslint-plugin-unicorn/issues/453 ). This linting rule lints source files--files which are more likely than say distribution files--to call for preserving the original sorting order, whether for better readability or maintainability (e.g., [aAbBcC]) or for causing or necessitating additional modifications of regular expressions per the linting rule any time something might be manually added or changed in a character class to break the code point sorting pattern--especially given that users are not likely to always know or wish to spend time looking up code point values for the characters they are adding.

Similarly, the auto-sorting of flags forces source into enforcing a particular sequence of flags.

Thanks for your consideration!

brettz9 avatar Nov 30 '19 16:11 brettz9

Adding parts of my comment from the other issue:

I agree that this is problematic.

One part of it is that different languages sort characters in different ways. Eg. in Swedish åäö is last in the alphabet and in that order and this rule eg. wants to resort åä to äå. To makes matter even more complicated, German sorts those letters after their dot-less equivalents, so ä after a and ö after o – so one universal true rule is not really possible when sorting purely on letters, unless one wants to enforce a "true" sorting upon everyone else.

voxpelli avatar Dec 03 '19 07:12 voxpelli

Thanks, this makes sense. I have merged the PR, and also we can provide support for more granular options per-transform. E.g. for preserving the order in specific transform, instead of just fully disabling it. As a first step though, having the blacklist is a good option.

DmitrySoshnikov avatar Dec 03 '19 19:12 DmitrySoshnikov