sonarjs/no-empty-alternatives
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/no-empty-alternatives": "error",
},
},
];Alternation in regular expressions should not contain empty alternatives
/Jack|Peter|/.test('John'); // Noncompliant - returns 'true'
/Jack||Peter/.test('John'); // Noncompliant - returns 'true'/Jack|Peter/.test('John'); // returns 'false'Examples from the ESLint documentation.
sonarjs/no-empty-alternatives
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-empty-alternatives": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Reluctant quantifiers in regular expressions should be followed by an expression that can't match the empty string
Empty character classes should not be used
Collection elements should not be replaced unconditionally
Empty collections should not be accessed or iterated
Two branches in a conditional structure should not have exactly the same implementation
Regular expressions should not contain empty groups