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

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

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

Having inconsistent indentation and omitting curly braces from a control structure, such as an if statement or for loop, is misleading and can induce bugs.

This rule raises an issue when the indentation of the lines after a control structure indicates an intent to include those lines in the block, but the omission of curly braces means the lines will be unconditionally executed once.

The following patterns are recognized:

if (condition)
  firstActionInBlock();
  secondAction();  // Noncompliant: secondAction is executed unconditionally
thirdAction();
if (condition) firstActionInBlock(); secondAction();  // Noncompliant: secondAction is executed unconditionally
if (condition) firstActionInBlock();  // Noncompliant
  secondAction();  // Executed unconditionally
if (condition); secondAction();  // Noncompliant: secondAction is executed unconditionally
let str = undefined;
for (let i = 0; i < array.length; i++)
  str = array[i];
  doTheThing(str);  // Noncompliant: executed only on the last element

Note that this rule considers tab characters to be equivalent to 1 space. When mixing spaces and tabs, a code may look fine in one editor but be confusing in another configured differently.

Resources





© 2015 - 2024 Weber Informatics LLC | Privacy Policy