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

`regexp/use-ignore-case` creates a bug

o-alexandrov opened this issue · comments

Information:

  • ESLint version: 8.52.0
  • eslint-plugin-regexp version: 2.1.1

Description

Rule regexp/use-ignore-case creates a bug in the following RegExp:

const emailRegex = /.*@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-zA-Z\-\d]+\.)+[a-zA-Z]{2,}))$/

It modifies the RegExp to:

const emailRegex = /.*@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-z\-\d]+\.)+[a-z]{2,}))$/I

So a valid email then is ignored:
example@me.com

So a valid email then is ignored:
example@me.com

No, it isn't.

Welcome to Node.js v20.5.1.
Type ".help" for more information.
> /.*@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-zA-Z\-\d]+\.)+[a-zA-Z]{2,}))$/.test("example@me.com")
true
> /.*@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-z\-\d]+\.)+[a-z]{2,}))$/i.test("example@me.com")
true

image

These 2 regexes are exactly equivalent to each other. So either something went wrong during your testing, or this isn't the whole regex, because use-ignore-case transformed this particular regex correctly AFAICT.

Thank you, you are correct, it's the transformation I do for the function that breaks, due to the addition of the i flag.