sonarjs/no-empty-collection
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/no-empty-collection": "error",
},
},
];Empty collections should not be accessed or iterated
let strings = [];
if (strings.includes("foo")) {} // Noncompliant
for (str of strings) {} // Noncompliant
strings.forEach(str => doSomething(str)); // NoncompliantThe documentation shows no correct example for this rule.
Examples from the ESLint documentation.
sonarjs/no-empty-collection
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-empty-collection": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Empty character classes should not be used
Regular expressions should not contain empty groups
Alternation in regular expressions should not contain empty alternatives
Parameterized tests should not have empty datasets
Reluctant quantifiers in regular expressions should be followed by an expression that can't match the empty string
Test and suite titles should not be empty or whitespace-only