fix(eslint-plugin): [naming-convention] support unicode in regex #2241
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support for unicode regular expressions.
The rule docs present the example below, saying "You can use the filter option to ignore names that require quoting":
(Aside: Ideally there should be a selector for detecting quoted names, since quotes can be a useful shorthand for bypassing lint rules. But let's ignore that for now. Instead we will follow the above example's premise, of substituting "must this name be quoted?" as an approximation of "was this name quoted?")
The example criteria of "does it have a minus or space?" is not an accurate test. Instead, it should be more like "Does it contain characters other than letters, numbers, and underscores?" Something like this:
But the Spanish identifier
_animación
will fail this test. To support languages besides English, the expression needs to be generalized to something like this:Unfortunately we can't do this today with
@typescript-eslint/naming-convention
, because its RegExp doesn't accept Unicode character classes.This PR fixes that.