Skip to content

Instantly share code, notes, and snippets.

View phenomnomnominal's full-sized avatar
🥑
Hangry

Craig Spence phenomnomnominal

🥑
Hangry
View GitHub Profile
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 => {
// 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.
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();
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);
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;
@phenomnomnominal
phenomnomnominal / noFdescribeOrFitRule.spec.ts
Created September 16, 2018 08:20
Full spec for the noFdescribeOrFitRule lint rule
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(`
@Injectable()
export class MyEffects {
@Effect()
public myEffect$: Observable<void> = this.action$.pipe(
// ...
// Do something observable-y
// ...
catchError(error => {
// handle error
})
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()
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(() => {})
);
};
`);
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(() => {})
);
};
`);