Comments (6)
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.
I'm not by convinced by "misused", is there any case that insert ?:
will result differently?
from eslint-plugin-regexp.
Expect backreferences numbers after it.
from eslint-plugin-regexp.
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.
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"
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.
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)
- `regexp/use-ignore-case` changes matched strings with Unicode HOT 2
- Sort string alternatives HOT 1
- Remove unnecessary elements in class intersections and subtractions HOT 1
- Simplify nested characters classes and expression character classes HOT 4
- 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
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.