prefer-named-capture-group
eslint
Suggestion
eslint.config.js
export default [
{
rules: {
"prefer-named-capture-group": "error",
},
},
];Enforce using named capture group in regular expression
const foo = /(ba[rz])/;
const bar = new RegExp('(ba[rz])');
const baz = RegExp('(ba[rz])');
foo.exec('bar')[1]; // Retrieve the group result.const foo = /(?<id>ba[rz])/;
const bar = new RegExp('(?<id>ba[rz])');
const baz = RegExp('(?<id>ba[rz])');
const xyz = /xyz(?:zy|abc)/;
foo.exec('bar').groups.id; // Retrieve the group result.Examples from the ESLint documentation.
prefer-named-capture-group
eslint
export default [
{
rules: {
"prefer-named-capture-group": "error",
},
},
];prefer-named-capture-group
eslint plugin · style
{
"rules": {
"prefer-named-capture-group": "error"
}
}style/useNamedCaptureGroup
style · since 2.4.5
{
"linter": {
"rules": {
"style": {
"useNamedCaptureGroup": "error"
}
}
}
}Require or disallow logical assignment operator shorthand
Disallow specified warning terms in comments
Disallow specified modules when loaded by import
Require function names to match the name of the variable or property to which they are assigned
Disallow null comparisons without type-checking operators