-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New rule no-if-statement. Requested in #54.
- Loading branch information
1 parent
09c1723
commit 8cab79c
Showing
5 changed files
with
64 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as ts from "typescript"; | ||
import * as Lint from "tslint"; | ||
import { | ||
createInvalidNode, | ||
CheckNodeResult, | ||
createCheckNodeRule | ||
} from "./shared/check-node"; | ||
|
||
type Options = {}; | ||
|
||
// tslint:disable-next-line:variable-name | ||
export const Rule = createCheckNodeRule( | ||
checkNode, | ||
"Unexpected if, use tenary operator instead." | ||
); | ||
|
||
function checkNode( | ||
node: ts.Node, | ||
_ctx: Lint.WalkContext<Options> | ||
): CheckNodeResult { | ||
return node && node.kind === ts.SyntaxKind.IfStatement | ||
? { invalidNodes: [createInvalidNode(node)] } | ||
: { | ||
invalidNodes: [] | ||
}; | ||
} |
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,10 @@ | ||
var x = 0; | ||
|
||
if(i === 1) { | ||
~~~~~~~~~~~~~ | ||
x = 2; | ||
~~~~~~~~~~ | ||
} | ||
~ [failure] | ||
|
||
[failure]: Unexpected if, use tenary operator instead. |
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,6 @@ | ||
{ | ||
"rulesDirectory": ["../../../../rules"], | ||
"rules": { | ||
"no-if-statement": true | ||
} | ||
} |
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