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
import { AbstractWalker } from 'tslint'; | |
import { forEachChild, Node, SourceFile, SyntaxKind } from 'typescript'; | |
const FAILURE_MESSAGE = (filter: string) => ` | |
Remember to remove "${filter}" once you have finished working on tests. | |
`; | |
class NoFDescribeOrFItWalker extends AbstractWalker { | |
public walk (sourceFile: SourceFile) { | |
const walkNode = (node: Node): void => { |
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
// Dependencies: | |
import { tsquery } from '@phenomnomnominal/tsquery'; | |
import { Fix, Replacement, RuleFailure, Rules } from 'tslint'; | |
import { SourceFile } from 'typescript'; | |
// Constants: | |
const FDESCRIBE_FIT_QUERY = 'CallExpression > Identifier[name=/^f(describe|it)$/]'; | |
const FAILURE_MESSAGE = (filter: string) => ` | |
Remember to remove "${filter}" once you have finished working on tests. |
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
import { tsquery } from '@phenomnomnominal/tsquery'; | |
import { IOptions, Replacement } from 'tslint'; | |
import { expect } from 'chai'; | |
import { Rule } from './noFdescribeOrFitRule'; | |
describe('noFdescribeOrFitRule', () => { | |
it('should create a lint error if "fdescribe()" is used', () => { | |
const sourceFile = tsquery.ast(` | |
fdescribe(); |
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
it('should not create a lint error if "describe()" is used', () => { | |
const sourceFile = tsquery.ast(` | |
describe(); | |
`); | |
const rule = new Rule({ ruleArguments: [] }); | |
const errors = rule.apply(sourceFile); | |
expect(errors.length).to.equal(0); |
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
it('should create a lint fix if "fdescribe()" is used', () => { | |
const sourceFile = tsquery.ast(` | |
fdescribe(); | |
`); | |
const rule = new Rule({ ruleArguments: [] }); | |
const errors = rule.apply(sourceFile); | |
const [error] = errors; |
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
import { tsquery } from '@phenomnomnominal/tsquery'; | |
import { expect } from 'chai'; | |
import { ineeda } from 'ineeda'; | |
import { IOptions, Replacement } from 'tslint'; | |
import { Rule } from './noFdescribeOrFitRule'; | |
describe('noFdescribeOrFitRule', () => { | |
it('should create a lint error if "fdescribe()" is used', () => { | |
const sourceFile = tsquery.ast(` |
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
@Injectable() | |
export class MyEffects { | |
@Effect() | |
public myEffect$: Observable<void> = this.action$.pipe( | |
// ... | |
// Do something observable-y | |
// ... | |
catchError(error => { | |
// handle error | |
}) |
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
import { tsquery } from '@phenomnomnominal/tsquery'; | |
import { expect } from 'chai'; | |
import { Rule } from './noCatchErrorInEffectChainRule'; | |
describe('noCatchErrorInEffectChainRule', () => { | |
it('should create a lint error if "catchError()" is in an Effect chain', () => { | |
const sourceFile = tsquery.ast(` | |
export class MyEffects { | |
@Effect() |
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
it(`should not create a lint error if the Effect chain doesn't use "catchError()"`, () => { | |
const sourceFile = tsquery.ast(` | |
export class MyEffects { | |
@Effect() | |
public myEffect = something.observable$.pipe( | |
switchMap(() => {}) | |
); | |
}; | |
`); |
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
it(`should not create a lint error if the Effect chain doesn't use "catchError()"`, () => { | |
const sourceFile = tsquery.ast(` | |
export class MyEffects { | |
@Effect() | |
public myEffect = something.observable$.pipe( | |
switchMap(() => {}) | |
); | |
}; | |
`); |