forked from palantir/tslint
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (palant…
- Loading branch information
1 parent
d4c131c
commit 096524e
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.