-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn about possible unexpected behavior else followed by a semicolon.
- Loading branch information
1 parent
1a92c01
commit 0b6c261
Showing
4 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# E204: semicolon after else may be causing unexpected behavior. | ||
|
||
A semicolon next to the `else` keyword may cause its body to be executed even when previous `if` statement condition is true. | ||
|
||
if (true) { | ||
console.log("true"); | ||
} else; { | ||
console.log("else"); | ||
} | ||
|
||
Example output | ||
``` | ||
> true | ||
> else | ||
``` | ||
|
||
To avoid this behavior, remove the semicolon between the else keyword and the opening brace of the else block. | ||
|
||
if (true) { | ||
console.log("true"); | ||
} else { | ||
console.log("else"); | ||
} | ||
|
||
Or if the else body is not required remove it completely. | ||
|
||
if (true) { | ||
console.log("true"); | ||
} | ||
console.log("always"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters