ota-meshi / eslint-plugin-regexp

ESLint plugin for finding regex mistakes and style guide violations.

Home Page:https://ota-meshi.github.io/eslint-plugin-regexp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect report of `no-unused-capturing-group` for `/^\.{1,2}(\/.*)?$/`

JounQin opened this issue · comments

Information: v8.18.0

  • ESLint version:
  • eslint-plugin-regexp version: 1.7.0

Description

const RELATIVE_PATH_PATTERN = /^\.{1,2}(\/.*)?$/

()? should not be reported?

If you don't use a capturing group, I think you can use a non-capturing group instead.

const RELATIVE_PATH_PATTERN = /^\.{1,2}(?:\/.*)?$/

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Groups_and_Ranges#:~:text=(%3F%3Ax)-,Non%2Dcapturing%20group,-%3A%20Matches%20%22x

Seems my regexp skill is not good enough then. 🤣

Can this plugin provide suggestions? (Auto fix maybe incorrect and risky.)

Seems my regexp skill is not good enough then. 🤣

I made this plugin and no-unused-capturing-group rule, because I made many similar mistakes before 😏

no-unused-capturing-group rule already supports the suggestion API.

If you tolerate the risk, you can optionally make an auto-fix.
https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-unused-capturing-group.html#options

closing since expected