This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prefer-conditional-expression: don't check else-if by default (#2963)
- Loading branch information
Showing
5 changed files
with
84 additions
and
14 deletions.
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
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
5 changes: 5 additions & 0 deletions
5
test/rules/prefer-conditional-expression/check-else-if/tslint.json
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,5 @@ | ||
{ | ||
"rules": { | ||
"prefer-conditional-expression": [true, "check-else-if"] | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
test/rules/prefer-conditional-expression/default/test.ts.lint
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,53 @@ | ||
let x; | ||
if (true) { | ||
~~ [err % ('x')] | ||
x = 1; | ||
} else { | ||
x = 2; | ||
} | ||
|
||
if (true) | ||
x = "TRUE"; | ||
else if (false) | ||
x = "FALSE"; | ||
else | ||
x = "FILE_NOT_FOUND"; | ||
|
||
// Must assign same variable | ||
if (true) { | ||
x = 1; | ||
} else { | ||
y = 2; | ||
} | ||
|
||
// All branches must be present | ||
if (true) { | ||
x = 1; | ||
} | ||
|
||
// Must not be a multi-statement block. | ||
if (true) { | ||
x = 1; | ||
} else { | ||
x = 2; | ||
y = 3; | ||
} | ||
|
||
// Or even multi-line. | ||
if (true) | ||
x = [ | ||
1, | ||
2 | ||
]; | ||
else | ||
x = 3; | ||
|
||
// Works for complex left hand side. | ||
if (true) { | ||
~~ [err % ('foo(bar).baz')] | ||
foo(bar).baz = 0; | ||
} else { | ||
foo(bar).baz = 1; | ||
} | ||
|
||
[err]: Use a conditional expression instead of assigning to '%s' in multiple places. |
File renamed without changes.