Giter Site home page Giter Site logo

Comments (6)

ota-meshi avatar ota-meshi commented on May 17, 2024 2

Thank you for posting the issue!

The report may have misused the regular expression, so I think it should be a suggestion instead of an auto-fix.

from eslint-plugin-regexp.

fisker avatar fisker commented on May 17, 2024

I'm not by convinced by "misused", is there any case that insert ?: will result differently?

from eslint-plugin-regexp.

fisker avatar fisker commented on May 17, 2024

Expect backreferences numbers after it.

from eslint-plugin-regexp.

ota-meshi avatar ota-meshi commented on May 17, 2024

For example, the following program is an example of using the wrong index.
This source code needs to shift the index instead of inserting the ?:.

- '2000-12-31'.replace(/(\d{4})-(\d{2})-(\d{2})/, (y, m, d) => `${y}/${m}/${d}`); // "2000-12-31/2000/12"
+ '2000-12-31'.replace(/(\d{4})-(\d{2})-(\d{2})/, (_, y, m, d) => `${y}/${m}/${d}`); // "2000/12/31"

from eslint-plugin-regexp.

RunDevelopment avatar RunDevelopment commented on May 17, 2024

I'm not by convinced by "misused", is there any case that insert ?: will result differently?
Expect backreferences numbers after it.

Yes.

var replaced = '2000-12-31'.replace(/(\d{4})-(\d{2})-(\d{2})/, '$3') // "2000/12"

image

But this issue can be solved by only fixing a capturing group if it is the last capturing group in the regex.


That being said, I also agree with @ota-meshi that unused capturing groups indicate a potential problem. Auto fixes should only be used where it is at least 99% clear what the correct code is. Suggestions are the right tool here IMO.

from eslint-plugin-regexp.

fisker avatar fisker commented on May 17, 2024

Cases you mentioned all the same as I said. It will effect groups indexes. At least in .test() if there are no indexed backreferences after the unused group, safe to fix.

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.