All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S4158.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

When a collection is empty with absolute certainty, it makes no sense to access or iterate it. Doing so can lead to unexpected behavior or errors in the code. The most common cause is that population was accidentally omitted or removed.

const strings = [];

if (strings.includes("foo")) {}  // Noncompliant: strings is always empty

for (const str of strings) {}  // Noncompliant

strings.forEach(str => doSomething(str)); // Noncompliant

Make sure your code provides some way to populate the collection if their elements are to be accessed.

const strings = [];

strings.push("foo");

if (strings.includes("foo")) {}

for (const str of strings) {}

strings.forEach(str => doSomething(str));

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy