-
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.
- Loading branch information
Showing
5 changed files
with
106 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,58 @@ | ||
import * as Lint from "tslint"; | ||
import * as ts from "typescript"; | ||
|
||
class CreateAsyncActionsRule extends Lint.RuleWalker { | ||
constructor( | ||
sourceFile: ts.SourceFile, | ||
options: Lint.IOptions | ||
) { | ||
super(sourceFile, options); | ||
} | ||
|
||
public visitCallExpression(node: ts.CallExpression): void { | ||
super.visitCallExpression(node); | ||
if (ts.isIdentifier(node.expression)) { | ||
if (node.expression.escapedText === "createAsyncActions") { | ||
if (node.arguments.length !== 4) { | ||
this.addFailureAtNode(node, "Number of arguments of createAsyncActions must be 4"); | ||
return; | ||
} | ||
|
||
const firstArg = node.arguments[0].getText(); | ||
const secondArg = node.arguments[1].getText(); | ||
if (secondArg.substring(1, secondArg.length - 1) !== firstArg.substring(1, firstArg.length - 1) + "_PENDING") { | ||
this.addFailureAtNode( | ||
node.arguments[1], | ||
"Second argument of createAsyncActions must be the first argument followed by _PENDING" | ||
); | ||
return; | ||
} | ||
|
||
const thirdArg = node.arguments[2].getText(); | ||
if (thirdArg.substring(1, thirdArg.length - 1) !== firstArg.substring(1, firstArg.length - 1) + "_FULFILLED") { | ||
this.addFailureAtNode( | ||
node.arguments[2], | ||
"Third argument of createAsyncActions must be the first argument followed by _FULFILLED" | ||
); | ||
return; | ||
} | ||
|
||
const fourthArg = node.arguments[3].getText(); | ||
if (fourthArg.substring(1, fourthArg.length - 1) !== firstArg.substring(1, firstArg.length - 1) + "_REJECTED") { | ||
this.addFailureAtNode( | ||
node.arguments[3], | ||
"Fourth argument of createAsyncActions must be the first argument followed by _REJECTED" | ||
); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// tslint:disable-next-line:export-name max-classes-per-file | ||
export class Rule extends Lint.Rules.TypedRule { | ||
public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] { | ||
return this.applyWithWalker(new CreateAsyncActionsRule(sourceFile, this.getOptions())); | ||
} | ||
} |
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,33 @@ | ||
export const addToCart = createAsyncActions("CART/ADD_TO_CART")<IAddToCartPayload, null, null, null>(); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Number of arguments of createAsyncActions must be 4] | ||
|
||
export const addToCart = createAsyncActions( | ||
"CART/ADD_TO_CART", | ||
"", | ||
~~ [Second argument of createAsyncActions must be the first argument followed by _PENDING] | ||
"", | ||
"" | ||
)<IAddToCartPayload, null, null, null>(); | ||
|
||
export const addToCart = createAsyncActions( | ||
"CART/ADD_TO_CART", | ||
"CART/ADD_TO_CART_PENDING", | ||
"", | ||
~~ [Third argument of createAsyncActions must be the first argument followed by _FULFILLED] | ||
"" | ||
)<IAddToCartPayload, null, null, null>(); | ||
|
||
export const addToCart = createAsyncActions( | ||
"CART/ADD_TO_CART", | ||
"CART/ADD_TO_CART_PENDING", | ||
"CART/ADD_TO_CART_FULFILLED", | ||
"" | ||
~~ [Fourth argument of createAsyncActions must be the first argument followed by _REJECTED] | ||
)<IAddToCartPayload, null, null, null>(); | ||
|
||
export const addToCart = createAsyncActions( | ||
"CART/ADD_TO_CART", | ||
"CART/ADD_TO_CART_PENDING", | ||
"CART/ADD_TO_CART_FULFILLED", | ||
"CART/ADD_TO_CART_REJECTED" | ||
)<IAddToCartPayload, null, null, null>(); |
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,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es5", | ||
"lib": ["es6"] | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"rulesDirectory": [ | ||
"../../../../lib" | ||
], | ||
"rules": { | ||
"create-async-actions": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,6 @@ | |
"no-console": [ | ||
true, | ||
"debug", | ||
"info", | ||
"log", | ||
"time", | ||
"timeEnd", | ||
|