pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
regexp/prefer-named-replacement |
enforce using named replacement |
v1.4.0 |
🔧 This rule is automatically fixable by the --fix
CLI option.
enforce using named replacement
This rule reports and fixes $n
parameter in replacement string that do not use the name of their referenced capturing group.
/* eslint regexp/prefer-named-replacement: "error" */
/* ✓ GOOD */
"abc".replace(/a(?<foo>b)c/, '$<foo>');
"abc".replace(/a(b)c/, '$1');
/* ✗ BAD */
"abc".replace(/a(?<foo>b)c/, '$1');
{
"regexp/prefer-named-replacement": ["error", {
"strictTypes": true
}]
}
strictTypes
... Iftrue
, strictly check the type of object to determine if the string instance was used inreplace()
andreplaceAll()
. Default istrue
.
This option is always on when using TypeScript.
- regexp/prefer-named-backreference
- regexp/prefer-named-capture-group
- regexp/prefer-result-array-groups
This rule was introduced in eslint-plugin-regexp v1.4.0