-
Notifications
You must be signed in to change notification settings - Fork 45
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
Feature: Support for case-insensitive elementNamePattern
RegExp
#462
Comments
This is how I support case-insensitive pattern matching now: const sizesOrder = [
{
name: 'size-larger-than-xl',
pattern: '^(?:.*?[0-9]+[xX][lL])$',
order: 'desc',
},
{ name: 'size-xl', pattern: '^(?:[a-zA-Z-_]*[xX][lL])$' },
{ name: 'size-lg', pattern: '^(?:.*[lL][gG])$' },
{ name: 'size-md', pattern: '^(?:.*[mM][dD])$' },
{
name: 'size-base',
pattern: '^(?:.*(?:[bB][aA][sS][eE]|[rR][eE][gG][uU][lL][aA][rR]))$',
},
{ name: 'size-sm', pattern: '^(?:.*[sS][mM])$' },
{ name: 'size-xs', pattern: '^(?:[a-zA-Z-_]*[xX][sS])$' },
{ name: 'size-smaller-than-xs', pattern: '^(?:.*?[0-9]+[xX][sS])$' },
]; |
Hi @letelete I had this issue in mind when implementing the RegExp matcher, but thought that there wasn't a need yet to support more advanced cases. 😅
ESLint configurations need to be serializable (in theory at least), which is why we handle RegExp strings without their options. Allowing non-serializable options (even if they would work in practice today) is risky as this can potentially break at any moment depending on what the ESLint Team decides on doing.
In my opinion, I think it's better to go toward a more generic approach: see how users can pass RegExp options ( |
I think that the following API can be suitable (for any other option that currently supports RegExp strings as well): |
Hi @hugop95, Considering the need to support serialization, |
So there's currently no other way to handle my problem other than what I've defined here, right? |
At this very moment, no: lowercase and uppercase characters need to appear in the expression, but the feature shouldn't take long to be implemented. |
Awesome! I'm looking forward to seeing it live :) |
What rule do you want to change?
sort-objects
Describe the problem
I'm trying to define a linear order for size definitions commonly used in my codebase.
I generate
groups
andcustomGroups
dynamically using a flat ESLint config.My custom groups work as intended for lowercase keys. However, to support all possible cases, I need to explicitly define all the variations (for example:
^(?:.*?[0-9]+xl)$
->^(?:.*?[0-9]+[xX][lL])$
). As you can imagine, this becomes a bit of a hassle when working with multiple groups, and it also makes my patterns harder to understand.It would be great to have a nice API for handling case-insensitive pattern matching using the
elementNamePattern
option. Any ideas? Perhaps it’s already supported, and I’m just missing something.Code example
Additional comments
Proposal for the new API
Allow
elementNamePattern
to be a RegExp object.Allowing users to define
elementNamePattern
as a RegExp object would enable case-insensitive matching out of the box:Add an
ignoreCase
option toelementNamePattern
.Another solution would be to allow users to specify an
ignoreCase
option that applies toelementNamePattern
, similar to the existing API for thesort-objects
rule.This is slightly related to issue #419.
Let me know what you think!
Validations
The text was updated successfully, but these errors were encountered: