Skip to content
This repository has been archived by the owner on May 23, 2021. It is now read-only.

Commit

Permalink
fix(on-reducer-explicit-return-type): return primitives
Browse files Browse the repository at this point in the history
Closes #38
  • Loading branch information
timdeschryver committed Jun 21, 2020
1 parent 805b9e1 commit ae50461
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/rules/ngrxOnReducerExplicitReturnTypeRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ export class Rule extends Lint.Rules.TypedRule {
): Lint.RuleFailure[] {
const creators = tsquery(
sourceFile,
'CallExpression:has(Identifier[name=createReducer]) CallExpression:has(Identifier[name=on]) > ArrowFunction:not(:has(TypeReference),:has(CallExpression))',
) as ts.CallExpression[]
'CallExpression[expression.name="createReducer"] > CallExpression[expression.name="on"] > ArrowFunction:not(:has(CallExpression))',
) as ts.ArrowFunction[]

const failures = creators.map(
(node): Lint.RuleFailure =>
new Lint.RuleFailure(
sourceFile,
node.getStart(),
node.getStart() + node.getWidth(),
Rule.FAILURE_STRING,
this.ruleName,
),
)
const failures = creators
.filter(node => !node.type)
.map(
(node): Lint.RuleFailure =>
new Lint.RuleFailure(
sourceFile,
node.getStart(),
node.getStart() + node.getWidth(),
Rule.FAILURE_STRING,
this.ruleName,
),
)
return failures
}
}
10 changes: 10 additions & 0 deletions test/rules/ngrx-on-reducer-explicit-return-type/fixture.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ on(

)

// https://github.com/timdeschryver/ngrx-tslint-rules/issues/38
export const onlineStateReducer = createReducer<boolean>(
onlineInitialState,
on(appIsOnline, (_currentState, _action): boolean => {
return true;
}),
on(appIsOffline, (_currentState, _action): boolean => {
return false;
}),
);

[on-reducer-explicit-return-type]: On reducers should have an explicit return type when using arrow functions, on(action, (state):State => {}

0 comments on commit ae50461

Please sign in to comment.