Skip to content

Instantly share code, notes, and snippets.

View phenomnomnominal's full-sized avatar
🥑
Hangry

Craig Spence phenomnomnominal

🥑
Hangry
View GitHub Profile
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(() => {})
);
};
`);
// 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 = `
@phenomnomnominal
phenomnomnominal / example.md
Last active January 29, 2019 18:53
Content projection as inversion of control

Before:

class Car {
    private _engine: Engine;
    private _radio: Radio;
    
    constructor () {
        this._engine = new Engine();
 this._radio = new Radio();