Skip to content

Commit

Permalink
chore(linting): add global tslint rules (angular-redux#35)
Browse files Browse the repository at this point in the history
Adds tslint rules to be run across the workspace based off of the latest preset with some tweaks to taste

BREAKING CHANGE:
- ConnectArray has been renamed to ConnectArrayDirective
- ReactiveConnect has been renamed to ReactiveConnectDirective
- Connect has been renamed to ConnectDirective
- interfaces with an "I" prefix have had that prefix removed (e.g "IAppStore" -> "AppStore")
closes angular-redux#4.
  • Loading branch information
smithad15 committed Nov 8, 2018
1 parent d047bb2 commit 336cc60
Show file tree
Hide file tree
Showing 89 changed files with 531 additions and 784 deletions.
8 changes: 6 additions & 2 deletions jest/tests-setup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// TODO: Should be able to remove this once dev dependencies are hoisted to the workspace
// tslint:disable:no-implicit-dependencies
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js';
import 'zone.js/dist/proxy';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import 'zone.js/dist/proxy';
import 'zone.js/dist/sync-test';
// This must be loaded in after ZoneJS
// tslint:disable-next-line:ordered-imports
import 'jest-zone-patch';

import { TestBed } from '@angular/core/testing';
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"clean:workspace-deps": "rimraf node_modules",
"clean:package-deps": "rimraf packages/*/node_modules",
"clean:coverage": "rimraf coverage",
"lint": "npm-run-all -p lint:*",
"lint": "tslint -p tsconfig.json",
"lint:packages": "lerna run lint",
"lint:prettier": "prettier -l \"**/*.*(ts|js|css|scss|json|md)\"",
"test": "jest --coverage",
Expand All @@ -31,14 +31,17 @@
"@commitlint/config-conventional": "7.0.1",
"@commitlint/prompt-cli": "7.0.0",
"@types/jest": "23.1.6",
"codelyzer": "4.4.2",
"husky": "0.14.3",
"jest": "23.4.1",
"jest-junit": "5.1.0",
"jest-preset-angular": "5.2.3",
"jest-zone-patch": "0.0.8",
"lerna": "2.11.0",
"lint-staged": "7.2.0",
"npm-run-all": "4.1.3",
"prettier": "1.13.7",
"rimraf": "2.6.2"
"rimraf": "2.6.2",
"tslint": "5.11.0"
}
}
15 changes: 0 additions & 15 deletions packages/example-app/circle.yml

This file was deleted.

2 changes: 0 additions & 2 deletions packages/example-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
"@angular/compiler-cli": "^4.1.0",
"@types/node": "~6.0.71",
"@types/redux-logger": "^3.0.0",
"codelyzer": "~3.0.1",
"protractor": "~5.1.1",
"ts-node": "~3.0.2",
"tslint": "~5.1.0",
"typescript": "^2.4.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component, Input } from '@angular/core';
import { TestBed, async } from '@angular/core/testing';
import { async, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AnimalListComponent } from './component';
import { CoreModule } from '../../core/module';
import { AnimalType } from '../model';
import { AnimalListComponent } from './component';

@Component({ selector: 'zoo-animal', template: '' })
class MockAnimalComponent {
Expand All @@ -19,7 +19,7 @@ xdescribe('AnimalListComponent', () => {
}).compileComponents();
}));

it(`should have as title 'Welcome to the Zoo'`, async(() => {
it("should have as title 'Welcome to the Zoo'", async(() => {
const fixture = TestBed.createComponent(AnimalListComponent);
const animalList = fixture.debugElement.componentInstance;

Expand Down
8 changes: 4 additions & 4 deletions packages/example-app/src/app/animals/animal-list/component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { IAnimal } from '../model';
import { Animal } from '../model';

@Component({
selector: 'zoo-animal-list',
Expand All @@ -11,14 +11,14 @@ import { IAnimal } from '../model';
export class AnimalListComponent {
@Input() animalsName: string;
@Input() animalType: string;
@Input() animals: Observable<IAnimal[]>;
@Input() animals: Observable<Animal[]>;
@Input() loading: Observable<boolean>;
@Input() error: Observable<any>;

// Since we're observing an array of items, we need to set up a 'trackBy'
// parameter so Angular doesn't tear down and rebuild the list's DOM every
// time there's an update.
getKey(_, animal: IAnimal) {
getKey(_, animal: Animal) {
return animal.id;
}
}
8 changes: 4 additions & 4 deletions packages/example-app/src/app/animals/animal/component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { async, TestBed } from '@angular/core/testing';
import {
NgReduxTestingModule,
MockNgRedux,
NgReduxTestingModule,
} from '@angular-redux/store/testing';
import { AnimalComponent } from './component';
import { CoreModule } from '../../core/module';
import { async, TestBed } from '@angular/core/testing';
import 'rxjs/add/operator/toArray';
import { CoreModule } from '../../core/module';
import { AnimalComponent } from './component';

xdescribe('AnimalComponent', () => {
let fixture;
Expand Down
6 changes: 3 additions & 3 deletions packages/example-app/src/app/animals/animal/component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
import { dispatch, select, select$, WithSubStore } from '@angular-redux/store';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Observable } from 'rxjs/Observable';

import { Animal } from '../model';
import { animalComponentReducer } from './reducers';
import { IAnimal } from '../model';

export const toSubTotal = (obs$: Observable<IAnimal>): Observable<number> =>
export const toSubTotal = (obs$: Observable<Animal>): Observable<number> =>
obs$.map(s => s.ticketPrice * s.tickets);

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/example-app/src/app/animals/animal/reducers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Reducer, Action } from 'redux';
import { Action, Reducer } from 'redux';
import { AnimalComponent } from './component';

export const ticketsReducer: Reducer<number> = (
Expand Down
6 changes: 3 additions & 3 deletions packages/example-app/src/app/animals/api/actions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable } from '@angular/core';
import { dispatch } from '@angular-redux/store';
import { Injectable } from '@angular/core';
import { FluxStandardAction } from 'flux-standard-action';
import { IAnimal, AnimalType } from '../model';
import { Animal, AnimalType } from '../model';

// Flux-standard-action gives us stronger typing of our actions.
type Payload = IAnimal[];
type Payload = Animal[];
interface MetaData {
animalType: AnimalType;
}
Expand Down
14 changes: 7 additions & 7 deletions packages/example-app/src/app/animals/api/epics.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Injectable } from '@angular/core';
import { Epic, createEpicMiddleware } from 'redux-observable';
import { of } from 'rxjs/observable/of';
import { createEpicMiddleware, Epic } from 'redux-observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/startWith';
import { of } from 'rxjs/observable/of';

import { IAppState } from '../../store/model';
import { AppState } from '../../store/model';
import { AnimalType } from '../model';
import { AnimalAPIAction, AnimalAPIActions } from './actions';
import { AnimalAPIService } from './service';

const animalsNotAlreadyFetched = (
animalType: AnimalType,
state: IAppState,
state: AppState,
): boolean =>
!(
state[animalType] &&
Expand All @@ -32,13 +32,13 @@ export class AnimalAPIEpics {
private actions: AnimalAPIActions,
) {}

public createEpic(animalType: AnimalType) {
createEpic(animalType: AnimalType) {
return createEpicMiddleware(this.createLoadAnimalEpic(animalType));
}

private createLoadAnimalEpic(
animalType: AnimalType,
): Epic<AnimalAPIAction, IAppState> {
): Epic<AnimalAPIAction, AppState> {
return (action$, store) =>
action$
.ofType(AnimalAPIActions.LOAD_ANIMALS)
Expand Down
10 changes: 5 additions & 5 deletions packages/example-app/src/app/animals/api/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AnimalAPIAction, AnimalAPIActions } from './actions';
import { IAnimalList, AnimalType } from '../model';
import { indexBy, prop } from 'ramda';
import { Action } from 'redux';
import { AnimalList, AnimalType } from '../model';
import { AnimalAPIAction, AnimalAPIActions } from './actions';

const INITIAL_STATE: IAnimalList = {
const INITIAL_STATE: AnimalList = {
items: {},
loading: false,
error: null,
Expand All @@ -13,9 +13,9 @@ const INITIAL_STATE: IAnimalList = {
// that only responds to actions for that particular animal type.
export function createAnimalAPIReducer(animalType: AnimalType) {
return function animalReducer(
state: IAnimalList = INITIAL_STATE,
state: AnimalList = INITIAL_STATE,
a: Action,
): IAnimalList {
): AnimalList {
const action = a as AnimalAPIAction;
if (!action.meta || action.meta.animalType !== animalType) {
return state;
Expand Down
8 changes: 4 additions & 4 deletions packages/example-app/src/app/animals/api/service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';

import { ANIMAL_TYPES, AnimalType, IAnimal, fromServer } from '../model';
import { Animal, ANIMAL_TYPES, AnimalType, fromServer } from '../model';

// A fake API on the internets.
const URLS = {
Expand All @@ -16,7 +16,7 @@ const URLS = {
export class AnimalAPIService {
constructor(private http: Http) {}

getAll = (animalType: AnimalType): Observable<IAnimal[]> =>
getAll = (animalType: AnimalType): Observable<Animal[]> =>
this.http
.get(URLS[animalType])
.map(resp => resp.json())
Expand Down
6 changes: 3 additions & 3 deletions packages/example-app/src/app/animals/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ export const ANIMAL_TYPES = {
// TODO: is there a way to improve this?
export type AnimalType = string;

export interface IAnimal {
export interface Animal {
id: string;
animalType: AnimalType;
name: string;
ticketPrice: number;
tickets: number;
}

export interface IAnimalList {
export interface AnimalList {
items: {};
loading: boolean;
error: any;
}

export const fromServer = (record: any): IAnimal => ({
export const fromServer = (record: any): Animal => ({
id: record.name.toLowerCase(),
animalType: record.animalType,
name: record.name,
Expand Down
4 changes: 2 additions & 2 deletions packages/example-app/src/app/animals/module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import { CoreModule } from '../core/module';
import { StoreModule } from '../store/module';
import { AnimalListComponent } from './animal-list/component';
import { AnimalAPIActions } from './api/actions';
import { AnimalAPIEpics } from './api/epics';
import { AnimalAPIService } from './api/service';
import { StoreModule } from '../store/module';

import { AnimalComponent } from './animal/component';

Expand Down
2 changes: 1 addition & 1 deletion packages/example-app/src/app/component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>
{{title}}
{{ title }}
</h1>
<nav>
<a routerLink="/elephants" routerLinkActive="active">Elephants</a>
Expand Down
4 changes: 2 additions & 2 deletions packages/example-app/src/app/component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestBed, async } from '@angular/core/testing';
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './component';

Expand All @@ -10,7 +10,7 @@ xdescribe('AppComponent', () => {
}).compileComponents();
}));

it(`should have as title 'Welcome to the Zoo'`, async(() => {
it("should have as title 'Welcome to the Zoo'", async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('Welcome to the Zoo');
Expand Down
2 changes: 1 addition & 1 deletion packages/example-app/src/app/component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ChangeDetectionStrategy } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'zoo-root',
Expand Down
4 changes: 2 additions & 2 deletions packages/example-app/src/app/core/counter/component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
Output,
ChangeDetectionStrategy,
EventEmitter,
} from '@angular/core';

@Component({
Expand Down
2 changes: 1 addition & 1 deletion packages/example-app/src/app/core/error-well/component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Input, Component, ChangeDetectionStrategy } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Observable } from 'rxjs/Observable';

@Component({
Expand Down
6 changes: 3 additions & 3 deletions packages/example-app/src/app/core/module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import { SpinnerComponent } from './spinner/component';
import { ErrorWellComponent } from './error-well/component';
import { CounterComponent } from './counter/component';
import { ErrorWellComponent } from './error-well/component';
import { SpinnerComponent } from './spinner/component';

@NgModule({
declarations: [SpinnerComponent, ErrorWellComponent, CounterComponent],
Expand Down
4 changes: 2 additions & 2 deletions packages/example-app/src/app/elephants/module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import { ElephantPageComponent } from './page';
import { AnimalModule } from '../animals/module';
import { CoreModule } from '../core/module';
import { StoreModule } from '../store/module';
import { ElephantPageComponent } from './page';

@NgModule({
declarations: [ElephantPageComponent],
Expand Down
10 changes: 5 additions & 5 deletions packages/example-app/src/app/elephants/page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { TestBed } from '@angular/core/testing';
import {
NgReduxTestingModule,
MockNgRedux,
NgReduxTestingModule,
} from '@angular-redux/store/testing';
import { TestBed } from '@angular/core/testing';

import { Component, Input } from '@angular/core';

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/toArray';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/toArray';
import { Observable } from 'rxjs/Observable';

import { ElephantPageComponent } from './page';
import { AnimalAPIActions } from '../animals/api/actions';
import { ANIMAL_TYPES } from '../animals/model';
import { ElephantPageComponent } from './page';

@Component({
selector: 'zoo-animal-list',
Expand Down

0 comments on commit 336cc60

Please sign in to comment.