Comments (4)
I haven't really used nested character classes yet
Same. I only used them when writing tests for v
flag regexes thus far. These simplifications are just a suggestion.
I'm looking forward to using the v
flag in practice though. I had to write quite a few regexes like /(?!\s)[\w\x80-\uFFFF]/
in the past, and I can now rewrite them, e.g. as /[[\w\P{ASCII}]--\s]/v
.
We might even want to make a rule for that. If a regex has the v
flag, then transform (?=[x])[y]
=> [y&&x]
and (?![x])[y]
=> [y--x]
. Let me make an issue for that.
from eslint-plugin-regexp.
I was working on no-useless-character-class
rule and noticed that it supports two patterns. #593
/[[abc]]/v
->/[abc]/v
/[[^\w&&\d]]/v
->/[^\w&&\d]/v
However, the following patterns are not supported yet. I'm wondering whether we should support them with no-useless-character-class
rule or create a separate rule.
/[^[abc]]/v
->/[^abc]/
/[[abc][def]ghi]/v
->/[abcdefghi]/v
By the way, I think it would be better to use a separate rule to check patterns that rewrite the following expressions. Because I think it's an optimization problem.
/[a&&[^b]]/v
->/[a--b]/v
/[a--[^b]]/v
->/[a&&b]/v
/[[^a]&&[^b]]/v
->/[^ab]/v
from eslint-plugin-regexp.
However, the following patterns are not supported yet. I'm wondering whether we should support them with
no-useless-character-class
rule or create a separate rule.
/[^[abc]]/v
->/[^abc]/
/[[abc][def]ghi]/v
->/[abcdefghi]/v
I thought for a moment and thought the rule should support them, so I'll change the rule.
from eslint-plugin-regexp.
Thank you for the rule suggestions! I haven't really used nested character classes yet, but I think the rule is very useful!
from eslint-plugin-regexp.
Related Issues (20)
- Module organization in `lib/utils`? HOT 1
- Disable `require-jsdoc` rule? HOT 1
- Use expression character class instead of lookaround
- Add `require-unicode-sets-regexp`
- `regexp/no-super-linear-move`: default for `ignoreSticky` differs from docs HOT 2
- Add `no-useless-string-literal`
- Force one grapheme in the disjunction of string literals
- Prepare for v2 release. HOT 8
- prefer-predefined-assertion does not recognize `(\.(?!$)|$))` HOT 7
- Make `no-useless-assertion` detect `(?!$)$`
- Add suggestions for `no-useless-assertion`
- `regexp/use-ignore-case` creates a bug HOT 2
- False positive of `regexp/no-unused-capturing-group` with `hasIndices` HOT 1
- Add option to rule `no-unused-capturing-group` to allow unused named capturing groups HOT 2
- Additional `/` character was added to my character class in autofix HOT 2
- Support flat config (eslint.config.js) HOT 6
- Unexpected `regexp/no-useless-escape` report with `RegExp` constructor HOT 3
- Change default configuration of `prefer-d` HOT 1
- Prefer long unicode class names over the short ones HOT 1
- Publish type declarations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-regexp.