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
Allow disabling of regexp character sorting #468
Allow disabling of regexp character sorting #468
Conversation
docs/rules/regex-shorthand.md
Outdated
Type: `boolean`\ | ||
Default: `false` | ||
|
||
Disables optimizations that affects the sorting of characters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description here needs to be clearer about what exactly will be sorted. "characters" is too ambiguous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sindresorhus There are two options as I see it:
- Get into the specifics of regexp-tree and be up front about the disabling of
charClassClassrangesMerge
, which the sorting is a needed side-effect of. This is probably too implementation specific and doesn't convey the purpose clearly. - Clearly convey the intended effect by naming it
sortCharacters
/sortCharacterClasses
(which the description of maybe could be spelled out in a somewhat more specific manner, but I have a hard time pinpointing that, maybe due to me not being the best at Regexp terminology).
I lean towards the second and I get the impression that you do as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, missed this. Yes, 2
. Could you also add an example? Not everyone knows what character classes are.
Does Also we probably want use object like this
so options will like {
charClassClassrangesMerge: false,
charSurrogatePairToSingleUnicode: true,
} |
@voxpelli great work, indeed this prevent sorting |
@voxpelli would you mind if I refactor the option logic? we don't need that blacklist logic. |
@fisker Because of reasons outlined in #468 (comment) I think the logic around regexp-tree should be kept as an internal implementation of this rule and not be exposed to the outside world. That way this rule can more easily be adapted to future changes in regexp-tree and/or to future alternative modules. Therefore I think that all we should do for now is to convey to regexp-tree that we want this very rule to sometimes be disabled, as made possible through DmitrySoshnikov/regexp-tree#200 Reason why I've implemented the blacklist feature myself here is to make this feature be easily upgraded once that PR has been merged and to have the intention in this code to be clear, I do not like the idea of: {
charClassClassrangesMerge: false,
charSurrogatePairToSingleUnicode: true,
} That exposes way too much about the internal implementation and pushes too many decisions onto the user rather than abstract them in a way that makes sense from the purpose of this rule (which has a different target audience than the one of regexp-tree). |
@voxpelli Your comment make sense, but I still think let users have all the options is good. Also this /[GgHhIiå.Z:a-f"0-8%A*ä]/
/["%*.0-8:AG-IZa-iäå]/ the |
@fisker The fact that it disables is a reason why I want to expose the disabling of sorting, as that enables this rule to evolve to separate those additional fixes from the actual sorting, which a raw option of Such a shortcoming can be mentioned in the documentation of a |
I have a regex I guess not only me, people may also need this. If it happends, we'll need to add another option again. Why not make it easier |
I think we disagree on what makes it easier 🙂 I think exposing of internal implementation details makes the API more complicated while you consider it to make it easier. I guess we can agree to disagree and have someone else, like @sindresorhus, chime in with his views? |
I agree with @voxpelli, we shouldn't expose the internals of |
I would argue this is actually an argument for not exposing all the options. The rule is actually improving your code and you're trying to fight it. By having the
If there's a valid use-case, we can add a well-documented option for it. Exposing everything just leads to users having to waste too much time reading docs and configuring, and we would have to pin the dependency as every patch release of |
@voxpelli The update is out: https://github.com/DmitrySoshnikov/regexp-tree/commits/master Can you update to use the blacklist? |
@sindresorhus @voxpelli I did the request changes |
Thanks @fisker! I was out of office for a few days, so unfortunately didn't have time to fix it :) |
@sindresorhus Is this ready to go you think? |
@voxpelli Did you see #468 (comment)? |
@voxpelli Bump :) |
Done @sindresorhus :) Sorry for me taking so long, I appreciate your bumps to remind me 👍 |
Co-Authored-By: Sindre Sorhus <sindresorhus@gmail.com>
Also rebased it 👍 |
Thank you 👍 |
@sindresorhus Should its default be |
I'm hoping that the author of regexp will fix those extra issues soon. If not, we could do this, yes. |
Fixes #453
Improved by DmitrySoshnikov/regexp-tree#200
Does this look like a good addition?