Giter Site home page Giter Site logo

Comments (4)

RunDevelopment avatar RunDevelopment commented on June 1, 2024 2

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.

ota-meshi avatar ota-meshi commented on June 1, 2024 1

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

https://github.com/ota-meshi/eslint-plugin-regexp/pull/593/files#diff-eb1d64f6019f074be64747d51d62981aaddc46eb17bf309a9f11da0789c5fdabR51-R54


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.

ota-meshi avatar ota-meshi commented on June 1, 2024 1

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.

ota-meshi avatar ota-meshi commented on June 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.