regexp/no-useless-flag
⚠️ This rule warns in the following configs: 🟢 flat/recommended, 🔵 recommended.
🔧 This rule is automatically fixable by the --fix CLI option.
disallow unnecessary regex flags
📖 Rule Details
This will point out present regex flags that do not change the pattern.
i flag (ignoreCase)
The i flag is only necessary if the pattern contains any characters with case variations. If the pattern contains no such characters, the flag will be unnecessary. E.g. /\.{3}/i
m flag (multiline)
The m flag changes the behavior of the ^ and $ assertions. If the pattern doesn't contain these anchors, the m flag will be unnecessary. E.g. /foo|[^\r\n]*/m
s flag (dotAll)
The s flag makes the dot (.) match all characters instead of the usually non-line-terminator characters. If the pattern doesn't contain a dot character set, the s flag will be unnecessary. E.g. /[.:]/s
g flag (global)
The g flag is used when you need to test a regular expression against all possible string match. If not, it will be unnecessary.
y flag (sticky)
The y flag is used when you need to do a sticky search. If not, it will be unnecessary.
other flags
No other flags will be checked.
🔧 Options
{
"regexp/no-useless-flag": ["error",
{
"ignore": [], // An array of "i", "m", "s", "g" and "y".
"strictTypes": true
}
]
}ignore... An array of flags to ignore from the check.strictTypes... Iftrue, strictly check the type of object to determine if the regex instance was used insearch()andsplit(). Default istrue. This option is only effective for verifying thegandyflags.
This option is always on when using TypeScript.
"ignore": ["s", "g"]
"strictTypes": false
❤️ Compatibility
This rule is compatible with clean-regex/no-unnecessary-flag rule.
🚀 Version
This rule was introduced in eslint-plugin-regexp v0.9.0