sonarjs/existing-groups
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/existing-groups": "error",
},
},
];Replacement strings should reference existing regular expression groups
const str = 'James Bond';
console.log(str.replace(/(\w+)\s(\w+)/, '$1, $0 $1')); // Noncompliant, index is 1-based, '$0' does not exist, prints 'James, $0 James'
console.log(str.replace(/(?<firstName>\w+)\s(?<lastName>\w+)/, '$<surname>, $<firstName> $<surname>')); // Noncompliant '$<surname>' does not exist, prints ', James 'const str = 'James Bond';
console.log(str.replace(/(\w+)\s(\w+)/, '$2, $1 $2'));
console.log(str.replace(/(?<firstName>\w+)\s(?<lastName>\w+)/, '$<lastName>, $<firstName> $<lastName>'));Examples from the ESLint documentation.
sonarjs/existing-groups
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/existing-groups": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Encryption algorithms should be used with secure mode and padding scheme
Repeated patterns in regular expressions should not match the empty string
File permissions should not be set to world-accessible values
Templates should not be constructed dynamically