-
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
10 changed files
with
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as Lint from "tslint"; | ||
import * as ts from "typescript"; | ||
|
||
class NoDupActionsRule extends Lint.RuleWalker { | ||
public actionNames: string[] = []; | ||
|
||
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") { | ||
for (const argument of node.arguments) { | ||
if (this.actionNames.indexOf(argument.getText()) !== -1) { | ||
this.addFailureAtNode(argument, "Duplicate redux action"); | ||
return; | ||
} | ||
this.actionNames.push(argument.getText()); | ||
} | ||
} | ||
if (node.expression.escapedText === "createAction") { | ||
if (this.actionNames.indexOf(node.arguments[0].getText()) !== -1) { | ||
this.addFailureAtNode(node.arguments[0], "Duplicate redux action"); | ||
return; | ||
} | ||
this.actionNames.push(node.arguments[0].getText()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// 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 NoDupActionsRule(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,22 @@ | ||
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>(); | ||
|
||
export const setFabricDataWithUrls = createAction( | ||
"FABRIC/SET_DATA_WITH_URLS", | ||
(resolve) => (data: IFabricData) => resolve(data) | ||
); | ||
|
||
export const addImage = createAction( | ||
"FABRIC/ADD_IMAGE_TO_EDITOR", | ||
(resolve) => (url: string) => resolve(url) | ||
); | ||
|
||
export const addShape = createAction( | ||
"FABRIC/ADD_IMAGE_TO_EDITOR", | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Duplicate redux action] | ||
(resolve) => (url: string) => resolve(url) | ||
); |
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": { | ||
"no-dup-actions": true | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
test/rules/no-dup-actions/create-async-actions-dup/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,14 @@ | ||
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>(); | ||
|
||
export const addToCart = createAsyncActions( | ||
"CART/ADD_TO_CART", | ||
~~~~~~~~~~~~~~~~~~ [Duplicate redux action] | ||
"CART/ADD_TO_CART_PENDING", | ||
"CART/ADD_TO_CART_FULFILLED", | ||
"CART/ADD_TO_CART_REJECTED" | ||
)<IAddToCartPayload, null, null, null>(); |
7 changes: 7 additions & 0 deletions
7
test/rules/no-dup-actions/create-async-actions-dup/tsconfig.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,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es5", | ||
"lib": ["es6"] | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test/rules/no-dup-actions/create-async-actions-dup/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,8 @@ | ||
{ | ||
"rulesDirectory": [ | ||
"../../../../lib" | ||
], | ||
"rules": { | ||
"no-dup-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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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>(); | ||
|
||
export const setFabricDataWithUrls = createAction( | ||
"FABRIC/SET_DATA_WITH_URLS", | ||
(resolve) => (data: IFabricData) => resolve(data) | ||
); | ||
|
||
export const addImage = createAction( | ||
"FABRIC/ADD_IMAGE_TO_EDITOR", | ||
(resolve) => (url: string) => resolve(url) | ||
); | ||
|
||
export const addShape = createAction( | ||
"FABRIC/ADD_SHAPE_TO_EDITOR", | ||
(resolve) => (url: string) => resolve(url) | ||
); |
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": { | ||
"no-dup-actions": true | ||
} | ||
} |