ajaylns / ajaylns.github.io

0 stars 0 forks source link

A conditionally executed single line should be denoted by indentation #81

Closed ajaylns closed 5 years ago

ajaylns commented 5 years ago

Risk: high

Description

In the absence of enclosing curly braces, the line immediately after a conditional is the one that is conditionally executed. By both convention and good practice, such lines are indented. In the absence of both curly braces and indentation the intent of the original programmer is entirely unclear and perhaps not actually what is executed. Additionally, such code is highly likely to be confusing to maintainers.

Noncompliant Code Example

if (condition)  // Noncompliant
doTheThing();

doTheOtherThing();
somethingElseEntirely();

foo();

Compliant Solution

if (condition)
  doTheThing();

doTheOtherThing();
somethingElseEntirely();

foo();

Recommendation

Use curly braces or indentation to denote the code conditionally executed by this "else".

Code

https://github.com/reyesreg/react-todo/blob/89aa7360990ded17a76364355a35df86d7eee9dc/dist/bundle.js#L520

Horangi detected this issue on 2019-04-12 08:18:18.749541