Created
September 16, 2018 08:58
-
-
Save phenomnomnominal/592bdfab89738927352be6d1bf56d00f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Dependencies: | |
import { tsquery } from '@phenomnomnominal/tsquery'; | |
import { RuleFailure, Rules } from 'tslint'; | |
import { SourceFile } from 'typescript'; | |
// Constants: | |
const CATCH_ERROR_QUERY = 'ClassDeclaration > PropertyDeclaration:has(Decorator Identifier[name="Effect"]) > CallExpression > CallExpression > Identifier[name="catchError"]'; | |
const FAILURE_MESSAGE = ` | |
Using "catchError" on the outermost Observable chain of an effect can | |
cause the entire stream of actions to break. | |
See https://medium.com/city-pantry/handling-errors-in-ngrx-effects-a95d918490d9 for more details. | |
`; | |
export class Rule extends Rules.AbstractRule { | |
public apply(sourceFile: SourceFile): Array<RuleFailure> { | |
return tsquery(sourceFile, CATCH_ERROR_QUERY).map(result => { | |
return new RuleFailure(result.getSourceFile(), result.getStart(), result.getEnd(), FAILURE_MESSAGE, this.ruleName); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment