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

org.sonar.css.checks.l10n.scss.if-elseif-same-condition.html Maven / Gradle / Ivy

There is a newer version: 4.13
Show newest version

A chain of @if / @else if directives is evaluated from top to bottom. At most, only one branch will be executed: the first one with a condition that evaluates to true.

Therefore, duplicating a condition automatically leads to dead code. Usually, this is due to a copy/paste error. At best, it's simply dead code and at worst, it's a bug that is likely to induce further bugs as the code is maintained, and obviously it could lead to unexpected behavior.

Noncompliant Code Example

@if $x == 0 {
  do-something();
} @else if $x == 1 {
  do-something-different();
} @else if $x == 0 {  /* Noncompliant: Same condition as in the @if directive */
  do-something-else();
}

Compliant Solution

@if $x == 0 {
  do-something();
} @else if $x == 1 {
  do-something-different();
} @else if $x == 2 {
  do-something-else();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy