From 869dc411709e8cd5897aa7dbd933dffc539423f4 Mon Sep 17 00:00:00 2001 From: Hetty de Vries Date: Sun, 22 Apr 2018 19:42:17 +0200 Subject: [PATCH] Add tslint rules and target es2017 - curly: true, ignore-same-line - newline-before-return: true - sort-object-literal-keys: true --- src/app/app.module.ts | 2 +- src/app/app.routes.ts | 7 ++++++- src/app/core/components/app/app.component.ts | 2 +- src/app/core/components/layout/layout.component.ts | 2 +- .../components/not-found/not-found.component.ts | 2 +- src/app/core/containers/games/games.component.ts | 2 +- src/app/core/containers/header/header.component.ts | 2 +- src/app/core/containers/login/login.component.ts | 4 +--- src/app/core/core.module.ts | 10 +++++----- src/app/core/models/game.interface.ts | 6 ++++-- src/app/core/models/user.interface.ts | 6 ++++-- src/app/core/services/games.service.ts | 1 + src/app/core/services/user.service.ts | 1 + src/app/core/store/reducers/games.reducer.ts | 4 ++-- src/app/core/store/reducers/user.reducer.ts | 4 ++-- .../friday/components/friday/friday.component.ts | 2 +- .../active-game/active-game.component.ts | 2 +- src/app/friday/containers/games/games.component.ts | 2 +- src/app/friday/friday.module.ts | 14 +++++++------- src/app/friday/friday.routes.ts | 2 ++ src/app/friday/services/games.service.ts | 6 ++++++ src/app/friday/store/reducers/games.reducer.ts | 4 ++-- src/app/shared/shared.module.ts | 6 +++--- src/app/store/reducers/index.ts | 3 ++- tsconfig.json | 2 +- tslint.json | 5 +++-- 26 files changed, 61 insertions(+), 42 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 299bfc7..15d9e34 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -31,8 +31,8 @@ import { environment } from '../environments/environment' StoreModule.forRoot(fromStore.reducers, { metaReducers: fromStore.metaReducers }), // DevTools Instrumentation must be imported after importing StoreModule StoreDevtoolsModule.instrument({ - name: 'h82 Games - NgRx DevTools', logOnly: environment.production, + name: 'h82 Games - NgRx DevTools', }), StoreRouterConnectingModule.forRoot({ stateKey: 'router' }), diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 2e8ee6d..68e5690 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -9,23 +9,28 @@ import * as fromComponents from './core/components' export const routes: Routes = [ { path: '', - redirectTo: '/games', + pathMatch: 'full', + redirectTo: '/games', }, { path: 'login', + component: fromContainers.LoginComponent, }, { path: 'games', + component: fromContainers.GamesComponent, }, { path: 'friday', + loadChildren: './friday/friday.module#FridayModule', }, { path: '**', + component: fromComponents.NotFoundComponent, }, ] diff --git a/src/app/core/components/app/app.component.ts b/src/app/core/components/app/app.component.ts index 51712d6..bfedaaa 100644 --- a/src/app/core/components/app/app.component.ts +++ b/src/app/core/components/app/app.component.ts @@ -2,8 +2,8 @@ import { Component } from '@angular/core' @Component({ selector: 'app-root', - templateUrl: './app.component.html', styleUrls: ['./app.component.sass'], + templateUrl: './app.component.html', }) export class AppComponent { title = 'Games' diff --git a/src/app/core/components/layout/layout.component.ts b/src/app/core/components/layout/layout.component.ts index 0cd83db..46bd88b 100644 --- a/src/app/core/components/layout/layout.component.ts +++ b/src/app/core/components/layout/layout.component.ts @@ -3,8 +3,8 @@ import { Component, OnInit, Input } from '@angular/core' @Component({ selector: 'app-layout', - templateUrl: './layout.component.html', styleUrls: ['./layout.component.sass'], + templateUrl: './layout.component.html', }) export class LayoutComponent implements OnInit { @Input() title: string diff --git a/src/app/core/components/not-found/not-found.component.ts b/src/app/core/components/not-found/not-found.component.ts index 448fff1..b7100e5 100644 --- a/src/app/core/components/not-found/not-found.component.ts +++ b/src/app/core/components/not-found/not-found.component.ts @@ -2,8 +2,8 @@ import { Component } from '@angular/core' @Component({ selector: 'app-not-found', - templateUrl: './not-found.component.html', styleUrls: ['./not-found.component.sass'], + templateUrl: './not-found.component.html', }) export class NotFoundComponent { } diff --git a/src/app/core/containers/games/games.component.ts b/src/app/core/containers/games/games.component.ts index a9dea75..000231d 100644 --- a/src/app/core/containers/games/games.component.ts +++ b/src/app/core/containers/games/games.component.ts @@ -8,8 +8,8 @@ import * as fromRoot from '../../../store' @Component({ selector: 'app-games', - templateUrl: './games.component.html', styleUrls: ['./games.component.sass'], + templateUrl: './games.component.html', }) export class GamesComponent implements OnInit { games$ = this.store.pipe(select(fromRoot.getGames)) diff --git a/src/app/core/containers/header/header.component.ts b/src/app/core/containers/header/header.component.ts index 594bd95..7a5bc01 100644 --- a/src/app/core/containers/header/header.component.ts +++ b/src/app/core/containers/header/header.component.ts @@ -6,8 +6,8 @@ import * as fromRoot from '../../../store' @Component({ selector: 'app-header', - templateUrl: './header.component.html', styleUrls: ['./header.component.sass'], + templateUrl: './header.component.html', }) export class HeaderComponent implements OnInit { @Input() title: string diff --git a/src/app/core/containers/login/login.component.ts b/src/app/core/containers/login/login.component.ts index 1bc82e4..7410f5e 100644 --- a/src/app/core/containers/login/login.component.ts +++ b/src/app/core/containers/login/login.component.ts @@ -1,16 +1,14 @@ import { Component, OnInit } from '@angular/core' import { Store, select } from '@ngrx/store' - import { take } from 'rxjs/operators' - import * as fromRoot from '../../../store' @Component({ selector: 'app-login', - templateUrl: './login.component.html', styleUrls: ['./login.component.sass'], + templateUrl: './login.component.html', }) export class LoginComponent implements OnInit { users$ = this.store.pipe(select(fromRoot.getUsers)) diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 68c0105..9d3b75b 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -10,11 +10,6 @@ import * as fromServices from './services' @NgModule({ - imports: [ - CommonModule, - RouterModule, - SharedModule, - ], declarations: [ ...fromComponents.components, ...fromContainers.containers, @@ -22,6 +17,11 @@ import * as fromServices from './services' exports: [ fromComponents.AppComponent, ], + imports: [ + CommonModule, + RouterModule, + SharedModule, + ], }) export class CoreModule { static forRoot() { diff --git a/src/app/core/models/game.interface.ts b/src/app/core/models/game.interface.ts index 3ae6714..ba0cfdb 100644 --- a/src/app/core/models/game.interface.ts +++ b/src/app/core/models/game.interface.ts @@ -1,13 +1,15 @@ export interface Game { id: number - name: string + accessible: boolean + name: string } export const createTestGame = (id = 1): Game => { return { id, - name: 'Test Game', + accessible: true, + name: 'Test Game', } } diff --git a/src/app/core/models/user.interface.ts b/src/app/core/models/user.interface.ts index 4134c10..0de3901 100644 --- a/src/app/core/models/user.interface.ts +++ b/src/app/core/models/user.interface.ts @@ -1,14 +1,16 @@ export interface User { id: number - name: string + email: string + name: string } export const createTestUser = (id = 1): User => { return { id, - name: 'Test User', + email: 'test@example.com', + name: 'Test User', } } diff --git a/src/app/core/services/games.service.ts b/src/app/core/services/games.service.ts index 33e4ced..740eff3 100644 --- a/src/app/core/services/games.service.ts +++ b/src/app/core/services/games.service.ts @@ -16,6 +16,7 @@ export class GamesService { getGames() { const url = environment.api.games + return this.http.get(url) as Observable } } diff --git a/src/app/core/services/user.service.ts b/src/app/core/services/user.service.ts index 0de8eae..27fef87 100644 --- a/src/app/core/services/user.service.ts +++ b/src/app/core/services/user.service.ts @@ -16,6 +16,7 @@ export class UserService { getUsers() { const url = environment.api.users + return this.http.get(url) as Observable } } diff --git a/src/app/core/store/reducers/games.reducer.ts b/src/app/core/store/reducers/games.reducer.ts index a6edc95..8f1bf71 100644 --- a/src/app/core/store/reducers/games.reducer.ts +++ b/src/app/core/store/reducers/games.reducer.ts @@ -46,16 +46,16 @@ export function reducer(state: State = initialState, action: fromGames.GamesActi ...state, entities, ids, - loading: false, loaded: true, + loading: false, } } case fromGames.LOAD_GAMES_FAIL: { return { ...state, - loading: false, loaded: false, + loading: false, } } diff --git a/src/app/core/store/reducers/user.reducer.ts b/src/app/core/store/reducers/user.reducer.ts index 792d7fc..4126ab7 100644 --- a/src/app/core/store/reducers/user.reducer.ts +++ b/src/app/core/store/reducers/user.reducer.ts @@ -48,16 +48,16 @@ export function reducer(state: State = initialState, action: fromUser.UserAction ...state, entities, ids, - loading: false, loaded: true, + loading: false, } } case fromUser.LOAD_USERS_FAIL: { return { ...state, - loading: false, loaded: false, + loading: false, } } diff --git a/src/app/friday/components/friday/friday.component.ts b/src/app/friday/components/friday/friday.component.ts index dc47151..c8e0c4d 100644 --- a/src/app/friday/components/friday/friday.component.ts +++ b/src/app/friday/components/friday/friday.component.ts @@ -3,8 +3,8 @@ import { Component, OnInit } from '@angular/core' @Component({ selector: 'app-fr-friday', - templateUrl: './friday.component.html', styleUrls: ['./friday.component.sass'], + templateUrl: './friday.component.html', }) export class FridayComponent implements OnInit { constructor() { } diff --git a/src/app/friday/containers/active-game/active-game.component.ts b/src/app/friday/containers/active-game/active-game.component.ts index c6aaaf4..2877664 100644 --- a/src/app/friday/containers/active-game/active-game.component.ts +++ b/src/app/friday/containers/active-game/active-game.component.ts @@ -11,8 +11,8 @@ import { FridayGameDetails } from '../../models/friday-game-details.model' @Component({ selector: 'app-fr-active-game', - templateUrl: './active-game.component.html', styleUrls: ['./active-game.component.sass'], + templateUrl: './active-game.component.html', }) export class ActiveGameComponent implements OnInit, OnDestroy { activeId: number diff --git a/src/app/friday/containers/games/games.component.ts b/src/app/friday/containers/games/games.component.ts index 0ea1d8f..a7d74c5 100644 --- a/src/app/friday/containers/games/games.component.ts +++ b/src/app/friday/containers/games/games.component.ts @@ -12,8 +12,8 @@ import { User } from '../../../core/models/user.interface' @Component({ selector: 'app-fr-games', - templateUrl: './games.component.html', styleUrls: ['./games.component.sass'], + templateUrl: './games.component.html', }) export class GamesComponent implements OnInit, OnDestroy { activeGameId: GameId diff --git a/src/app/friday/friday.module.ts b/src/app/friday/friday.module.ts index 6b08035..bf0382a 100644 --- a/src/app/friday/friday.module.ts +++ b/src/app/friday/friday.module.ts @@ -16,6 +16,13 @@ import * as fromStore from './store' @NgModule({ + declarations: [ + ...fromComponents.components, + ...fromContainers.containers, + ], + exports: [ + fromComponents.FridayComponent, + ], imports: [ // Angular CommonModule, @@ -28,13 +35,6 @@ import * as fromStore from './store' // Other SharedModule, ], - declarations: [ - ...fromComponents.components, - ...fromContainers.containers, - ], - exports: [ - fromComponents.FridayComponent, - ], providers: fromServices.services, }) export class FridayModule { } diff --git a/src/app/friday/friday.routes.ts b/src/app/friday/friday.routes.ts index 8af4e52..14aa1c3 100644 --- a/src/app/friday/friday.routes.ts +++ b/src/app/friday/friday.routes.ts @@ -7,10 +7,12 @@ import * as fromComponents from './components' export const routes: Routes = [ { path: '', + component: fromComponents.FridayComponent, }, { path: ':gameId', + component: fromContainers.ActiveGameComponent, }, ] diff --git a/src/app/friday/services/games.service.ts b/src/app/friday/services/games.service.ts index 89a45f9..549ec3c 100644 --- a/src/app/friday/services/games.service.ts +++ b/src/app/friday/services/games.service.ts @@ -18,6 +18,7 @@ export class GamesService { createGame(game: FridayGame) { const url = environment.api.friday.games + return this.http.post(url, game).pipe( delay(1000), ) as Observable @@ -26,6 +27,7 @@ export class GamesService { createGameDetails(gameId: GameId) { const url = environment.api.friday.gameDetails const body = new FridayGameDetails(gameId) + return this.http.post(url, body).pipe( delay(1000), ) as Observable @@ -33,6 +35,7 @@ export class GamesService { deleteGame(gameId: GameId) { const url = environment.api.friday.games + '/' + gameId + return this.http.delete(url).pipe( delay(1000), ) as Observable @@ -40,6 +43,7 @@ export class GamesService { deleteGameDetails(gameId: GameId) { const url = environment.api.friday.gameDetails + '/' + gameId + return this.http.delete(url).pipe( delay(1000), ) as Observable @@ -47,6 +51,7 @@ export class GamesService { getGamesByUser(userId: number) { const url = environment.api.friday.games + `?userId=${userId}` + return this.http.get(url).pipe( delay(1000), ) as Observable @@ -54,6 +59,7 @@ export class GamesService { getGameDetails(gameId: GameId) { const url = environment.api.friday.gameDetails + '/' + gameId + return this.http.get(url).pipe( delay(1000), ) as Observable diff --git a/src/app/friday/store/reducers/games.reducer.ts b/src/app/friday/store/reducers/games.reducer.ts index a30b245..f32899a 100644 --- a/src/app/friday/store/reducers/games.reducer.ts +++ b/src/app/friday/store/reducers/games.reducer.ts @@ -107,8 +107,8 @@ export function reducer(state: State = initialState, action: fromGames.GamesActi return { ...state, error: action.payload, - loading: false, loaded: false, + loading: false, } } @@ -130,8 +130,8 @@ export function reducer(state: State = initialState, action: fromGames.GamesActi entities, error: null, ids, - loading: false, loaded: true, + loading: false, } } diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 79c4f20..3864193 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -5,14 +5,14 @@ import * as fromComponents from './components' @NgModule({ - imports: [ - CommonModule, - ], declarations: [ ...fromComponents.components, ], exports: [ ...fromComponents.components, ], + imports: [ + CommonModule, + ], }) export class SharedModule { } diff --git a/src/app/store/reducers/index.ts b/src/app/store/reducers/index.ts index 3ddbdb6..e0e6579 100644 --- a/src/app/store/reducers/index.ts +++ b/src/app/store/reducers/index.ts @@ -64,8 +64,9 @@ export class CustomRouterStateSerializer implements fromRouter.RouterStateSerial serialize(routerState: RouterStateSnapshot): RouterStateUrl { let route = routerState.root - while (route.firstChild) + while (route.firstChild) { route = route.firstChild + } const { url, root: { queryParams } } = routerState const { params } = route diff --git a/tsconfig.json b/tsconfig.json index 313cada..d1b1cac 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ "moduleResolution": "node", "outDir": "./dist/out-tsc", "sourceMap": true, - "target": "es5", + "target": "es2017", "typeRoots": [ "node_modules/@types" ], diff --git a/tslint.json b/tslint.json index 27699cf..24ccfd4 100644 --- a/tslint.json +++ b/tslint.json @@ -12,7 +12,7 @@ ], "curly": [ true, - "as-needed" + "ignore-same-line" ], "deprecation": { "severity": "warn" @@ -47,6 +47,7 @@ ] } ], + "newline-before-return": true, "no-arg": true, "no-bitwise": true, "no-console": [ @@ -79,7 +80,7 @@ "no-unused-variable": true, "no-use-before-declare": true, "no-var-keyword": true, - "object-literal-sort-keys": false, + "object-literal-sort-keys": true, "one-line": [ true, "check-open-brace",