Skip to content

Instantly share code, notes, and snippets.

View phenomnomnominal's full-sized avatar
🥑
Hangry

Craig Spence phenomnomnominal

🥑
Hangry
View GitHub Profile
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
@NgModule({
imports: [
RouterModule.forChild([{
path: '',
loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule)
}])
]
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
@NgModule({
imports: [
RouterModule.forChild([{
path: '',
loadChildren: './lazy/lazy.module#LazyModule'
}])
]
@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();
// 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 = `
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(() => {})
);
};
`);
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()
@Injectable()
export class MyEffects {
@Effect()
public myEffect$: Observable<void> = this.action$.pipe(
// ...
// Do something observable-y
// ...
catchError(error => {
// handle error
})
@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(`
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;