Query module DanglingElse

name
Misleading indentation of dangling ‘else’
description
The ‘else’ clause of an ‘if’ statement should be aligned with the ‘if’ it belongs to.
kind
problem
problem.severity
warning
id
js/misleading-indentation-of-dangling-else
tags
readability statistical non-attributable external/cwe/cwe-483
precision
very-high

Imports

javascript

Provides classes for working with JavaScript programs, as well as JSON, YAML and HTML.

Predicates

elseIndent

Gets the semantic indentation of the else token of statement i, if any.

ifIndent

Gets the semantic indentation of the if token of statement i.

prevTokenOnSameLine

Holds if prev precedes tk on the same line, where val is the value of tk and prevVal is the value of prev.

semanticIndent

Gets the semantic indentation of token tk.

Classes

RelevantToken

A token that is relevant for this query, that is, an if, else or } token.