From c7837edb5424f210ba111f99223b2c100f83801d Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Tue, 21 Mar 2017 11:11:03 +0200 Subject: [PATCH] refactor: lint test apps --- ng-sample/app/app.ts | 25 ++-- .../examples/action-bar/action-bar-test.ts | 17 ++- .../animation/animation-enter-leave-test.ts | 30 ++--- .../animation/animation-keyframes-test.ts | 30 ++--- .../animation/animation-ngclass-test.ts | 7 +- .../animation/animation-states-test.ts | 16 +-- ng-sample/app/examples/http/http-test.ts | 20 +-- ng-sample/app/examples/image/image-test.ts | 26 ++-- ng-sample/app/examples/list/data.service.ts | 11 +- .../app/examples/list/list-test-async.ts | 16 ++- ng-sample/app/examples/list/list-test.ts | 20 +-- .../app/examples/list/template-selector.ts | 19 +-- .../livesync-test/livesync-test-app.ts | 2 +- ng-sample/app/examples/modal/modal-content.ts | 6 +- ng-sample/app/examples/modal/modal-test.ts | 8 +- .../platform-directives-test.ts | 5 +- ng-sample/app/examples/renderer-test.ts | 22 ++-- .../app/examples/router/clear-history-test.ts | 16 ++- ng-sample/app/examples/router/login-test.ts | 22 ++-- .../router/page-router-outlet-nested-test.ts | 22 ++-- .../router/page-router-outlet-test.ts | 10 +- .../app/examples/router/router-outlet-test.ts | 12 +- .../app/examples/tab-view/tab-view-test.ts | 15 +-- ng-sample/app/performance/benchmark.ts | 52 ++++---- ng-sample/app/performance/profiling.ts | 20 ++- ng-sample/app/starter.ts | 9 +- ng-sample/package.json | 20 +-- ng-sample/tslint.json | 117 ++++++++++++++++++ tests/app/first.component.ts | 4 +- tests/app/lazy-loaded.module.ts | 6 +- tests/app/main.ts | 23 ++-- tests/app/multi-page-main.component.ts | 4 +- tests/app/second.component.ts | 4 +- tests/app/single-page-main.component.ts | 4 +- tests/app/snippets/gestures.component.ts | 30 ++--- tests/app/snippets/icon-font.component.ts | 8 +- tests/app/snippets/layouts.component.ts | 16 +-- .../list-view/template-selector.component.ts | 11 +- tests/app/snippets/navigation/page-outlet.ts | 12 +- tests/app/snippets/navigation/route-params.ts | 9 +- .../snippets/navigation/router-extensions.ts | 8 +- .../app/snippets/navigation/router-outlet.ts | 10 +- tests/app/tests/detached-loader-tests.ts | 26 ++-- tests/app/tests/http.ts | 39 +++--- tests/app/tests/list-view-tests.ts | 10 +- tests/app/tests/mocks/ns-file-system.mock.ts | 13 +- tests/app/tests/modal-dialog.ts | 8 +- tests/app/tests/ns-location-strategy.ts | 9 +- tests/app/tests/platform-filter-components.ts | 20 ++- tests/app/tests/property-sets.ts | 29 ++--- tests/app/tests/renderer-tests.ts | 36 ++++-- tests/app/tests/snippets.ts | 37 ++++-- tests/app/tests/style-properties.ts | 4 +- tests/app/tests/test-app.ts | 30 +++-- tests/app/tests/test-config.ts | 4 +- tests/app/tests/test-utils.ts | 14 +-- tests/app/tests/third-party-view.ts | 2 +- tests/app/tests/third-party.ts | 28 +++-- tests/app/tests/value-accessor-tests.ts | 48 +++---- tests/app/tests/xhr-paths.ts | 12 +- tests/package.json | 4 +- tests/tslint.json | 117 ++++++++++++++++++ 62 files changed, 788 insertions(+), 446 deletions(-) create mode 100644 ng-sample/tslint.json create mode 100644 tests/tslint.json diff --git a/ng-sample/app/app.ts b/ng-sample/app/app.ts index 2dc904021..a0a135a04 100644 --- a/ng-sample/app/app.ts +++ b/ng-sample/app/app.ts @@ -1,12 +1,7 @@ -//import "globals"; -// import "./modules"; -//global.registerModule("./main-page", function () { return require("./main-page"); }); +import { NativeScriptModule } from "nativescript-angular/nativescript.module"; +import { platformNativeScriptDynamic } from "nativescript-angular/platform"; +import { NativeScriptAnimationsModule } from "nativescript-angular/animations"; -//import * as profiling from "./profiling"; -//profiling.start("application-start"); - -// "nativescript-angular/application" import should be first in order to load some required settings (like globals and reflect-metadata) -import { NativeScriptModule, platformNativeScriptDynamic } from "nativescript-angular/platform"; import { onAfterLivesync, onBeforeLivesync } from "nativescript-angular/platform-common"; import { NgModule } from "@angular/core"; import { Router } from "@angular/router"; @@ -69,9 +64,9 @@ import { AnimationStatesTest } from "./examples/animation/animation-states-test" class ExampleModule { } function makeExampleModule(componentType) { - let imports: any[] = [ExampleModule]; + let imports: any[] = [ExampleModule, NativeScriptAnimationsModule]; if (componentType.routes) { - imports.push(NativeScriptRouterModule.forRoot(componentType.routes)) + imports.push(NativeScriptRouterModule.forRoot(componentType.routes)); } let exports: any[] = []; if (componentType.exports) { @@ -111,7 +106,7 @@ const customPageFactoryProvider = { } }; -platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RendererTest)); +// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RendererTest)); // platformNativeScriptDynamic(undefined, [customPageFactoryProvider]).bootstrapModule(makeExampleModule(RendererTest)); // platformNativeScriptDynamic().bootstrapModule(makeExampleModule(TabViewTest)); // platformNativeScriptDynamic().bootstrapModule(makeExampleModule(Benchmark)); @@ -135,10 +130,10 @@ platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RendererTest)); // platformNativeScriptDynamic().bootstrapModule(makeExampleModule(AnimationStatesTest)); // platformNativeScriptDynamic().bootstrapModule(makeExampleModule(AnimationNgClassTest)); // platformNativeScriptDynamic().bootstrapModule(makeExampleModule(AnimationKeyframesTest)); -// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(AnimationEnterLeaveTest)); +platformNativeScriptDynamic().bootstrapModule(makeExampleModule(AnimationEnterLeaveTest)); -//Livesync test -var cachedUrl: string; +// Livesync test +let cachedUrl: string; onBeforeLivesync.subscribe((moduleRef) => { console.log("------- onBeforeLivesync"); if (moduleRef) { @@ -157,5 +152,5 @@ onAfterLivesync.subscribe((moduleRef) => { } }); -//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(LivesyncApp)); +// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(LivesyncApp)); console.log("APP RESTART"); diff --git a/ng-sample/app/examples/action-bar/action-bar-test.ts b/ng-sample/app/examples/action-bar/action-bar-test.ts index a4e23ed4e..2186e2427 100644 --- a/ng-sample/app/examples/action-bar/action-bar-test.ts +++ b/ng-sample/app/examples/action-bar/action-bar-test.ts @@ -1,5 +1,5 @@ -import { Component } from '@angular/core'; -import { Page} from "ui/page"; +import { Component } from "@angular/core"; +import { Page } from "ui/page"; @Component({ selector: "first", @@ -29,7 +29,6 @@ class FirstComponent { @Component({ selector: "nested-component", template: ` - @@ -70,7 +69,7 @@ class SecondComponent { } @Component({ - selector: 'action-bar-test', + selector: "action-bar-test", template: ` @@ -79,14 +78,12 @@ class SecondComponent { }) export class ActionBarTest { static routes = [ - { path: '', component: FirstComponent }, - { path: 'second', component: SecondComponent }, - ] + { path: "", component: FirstComponent }, + { path: "second", component: SecondComponent }, + ]; static entries = [ FirstComponent, SecondComponent, - ] + ]; } - - diff --git a/ng-sample/app/examples/animation/animation-enter-leave-test.ts b/ng-sample/app/examples/animation/animation-enter-leave-test.ts index ce527cac9..307534574 100644 --- a/ng-sample/app/examples/animation/animation-enter-leave-test.ts +++ b/ng-sample/app/examples/animation/animation-enter-leave-test.ts @@ -1,39 +1,39 @@ -import {Component, trigger, style, animate, state, transition } from '@angular/core'; +import {Component, trigger, style, animate, state, transition } from "@angular/core"; @Component({ - selector: 'animation-enter-leave', - templateUrl: './examples/animation/animation-enter-leave-test.html', - styleUrls: [ './examples/animation/animation-enter-leave-test.css' ], + selector: "animation-enter-leave", + templateUrl: "./examples/animation/animation-enter-leave-test.html", + styleUrls: [ "./examples/animation/animation-enter-leave-test.css" ], animations: [ - trigger('state', [ - state('in', style({ 'background-color': 'red', 'opacity': 1 })), - state('void', style({ 'background-color': 'white', 'opacity': 0 })), - transition('void => *', [ animate('600ms ease-out') ]), - transition('* => void', [ animate('600ms ease-out')]) + trigger("state", [ + state("in", style({ "background-color": "red", "opacity": 1 })), + state("void", style({ "background-color": "white", "opacity": 0 })), + transition("void => *", [ animate("600ms ease-out") ]), + transition("* => void", [ animate("600ms ease-out")]) ]) ] }) export class AnimationEnterLeaveTest { - + public items: Array; constructor() { this.items = []; - for (var i = 0; i < 3; i++) { + for (let i = 0; i < 3; i++) { this.items.push("Item " + i); } } - + onAddTap() { this.items.push("Item " + (this.items.length + 1)); } - + onRemoveAllTap() { this.items = []; } - + onItemTap(event) { - var index = this.items.indexOf(event.object.text); + let index = this.items.indexOf(event.object.text); this.items.splice(index, 1); } } diff --git a/ng-sample/app/examples/animation/animation-keyframes-test.ts b/ng-sample/app/examples/animation/animation-keyframes-test.ts index b4e4ab864..cfc7089e4 100644 --- a/ng-sample/app/examples/animation/animation-keyframes-test.ts +++ b/ng-sample/app/examples/animation/animation-keyframes-test.ts @@ -1,35 +1,35 @@ -import { Component } from '@angular/core'; -import { trigger, style, animate, state, transition, keyframes } from '@angular/animations'; +import { Component } from "@angular/core"; +import { trigger, style, animate, state, transition, keyframes } from "@angular/animations"; @Component({ - selector: 'animation-states', + selector: "animation-states", template: ` `, animations: [ - trigger('state', [ - state('active', style({ opacity: 1 })), - state('inactive', style({ opacity: 0.2 })), - transition('inactive => active', [ + trigger("state", [ + state("active", style({ opacity: 1 })), + state("inactive", style({ opacity: 0.2 })), + transition("inactive => active", [ animate(300, keyframes([ - style({opacity: 0.2, transform: 'translateX(-100)', offset: 0}), - style({opacity: 1, transform: 'translateX(15)', offset: 0.3}), - style({opacity: 1, transform: 'translateX(0)', offset: 1.0}) + style({opacity: 0.2, transform: "translateX(-100),translateY(100)", offset: 0}), + style({opacity: 1, transform: "translateX(15)", offset: 0.3}), + style({opacity: 1, transform: "translateX(0)", offset: 1.0}) ])) ]), - transition('active => inactive', [ + transition("active => inactive", [ animate(300, keyframes([ - style({opacity: 1, transform: 'translateX(0)', offset: 0}), - style({opacity: 1, transform: 'translateX(-15)', offset: 0.7}), - style({opacity: 0.2, transform: 'translateX(100)', offset: 1.0}) + style({opacity: 1, transform: "translateX(0)", offset: 0}), + style({opacity: 1, transform: "translateX(-15)", offset: 0.7}), + style({opacity: 0.2, transform: "translateX(100)", offset: 1.0}) ])) ]) ]) ] }) export class AnimationKeyframesTest { - + isOn = false; onTap() { diff --git a/ng-sample/app/examples/animation/animation-ngclass-test.ts b/ng-sample/app/examples/animation/animation-ngclass-test.ts index 516dc34f0..c0d7b0ba7 100644 --- a/ng-sample/app/examples/animation/animation-ngclass-test.ts +++ b/ng-sample/app/examples/animation/animation-ngclass-test.ts @@ -13,11 +13,6 @@ export class AnimationNgClassTest { onTap() { this.isOn = !this.isOn; - if (this.isOn) { - this.text = "Toggled"; - } - else { - this.text = "Normal"; - } + this.text = this.isOn ? "Toggled" : "Normal"; } } diff --git a/ng-sample/app/examples/animation/animation-states-test.ts b/ng-sample/app/examples/animation/animation-states-test.ts index b72ae4df9..ba6288ea5 100644 --- a/ng-sample/app/examples/animation/animation-states-test.ts +++ b/ng-sample/app/examples/animation/animation-states-test.ts @@ -1,22 +1,22 @@ -import {Component, trigger, style, animate, state, transition } from '@angular/core'; +import {Component, trigger, style, animate, state, transition } from "@angular/core"; @Component({ - selector: 'animation-states', + selector: "animation-states", template: ` `, animations: [ - trigger('state', [ - state('inactive', style({ 'background-color': 'red' })), - state('active', style({ 'background-color': 'green' })), - transition('inactive => active', [ animate('600ms ease-out') ]), - transition('active => inactive', [ animate('600ms ease-out') ]), + trigger("state", [ + state("inactive", style({ "background-color": "red" })), + state("active", style({ "background-color": "green" })), + transition("inactive => active", [ animate("600ms ease-out") ]), + transition("active => inactive", [ animate("600ms ease-out") ]), ]) ] }) export class AnimationStatesTest { - + isOn = false; onTap() { diff --git a/ng-sample/app/examples/http/http-test.ts b/ng-sample/app/examples/http/http-test.ts index c661a749b..ae2c4b8ca 100644 --- a/ng-sample/app/examples/http/http-test.ts +++ b/ng-sample/app/examples/http/http-test.ts @@ -1,15 +1,17 @@ -import {Component} from '@angular/core'; -import {Http} from '@angular/http'; -import 'rxjs/add/operator/map'; +import {Component} from "@angular/core"; +import {Http} from "@angular/http"; +import "rxjs/add/operator/map"; /* IMPORTANT -In order to test out the full image example, to fix the App Transport Security error in iOS 9, you will need to follow this after adding the iOS platform: +In order to test out the full image example, +to fix the App Transport Security error in iOS 9, +you will need to follow this after adding the iOS platform: https://blog.nraboy.com/2015/12/fix-ios-9-app-transport-security-issues-in-nativescript/ */ @Component({ - selector: 'http-test', + selector: "http-test", template: ` @@ -28,12 +30,12 @@ export class HttpTest { public title: string; public description: string; - constructor(private http: Http) { - + constructor(private http: Http) { + } - + public loadLocal() { - this.http.get('~/examples/http/data.json').map(res => res.json()).subscribe((response: any) => { + this.http.get("~/examples/http/data.json").map(res => res.json()).subscribe((response: any) => { let user = response.results[0]; this.title = user.title; this.description = user.description; diff --git a/ng-sample/app/examples/image/image-test.ts b/ng-sample/app/examples/image/image-test.ts index 6d21c9840..8df56a6e6 100644 --- a/ng-sample/app/examples/image/image-test.ts +++ b/ng-sample/app/examples/image/image-test.ts @@ -1,13 +1,15 @@ -import {Component} from '@angular/core'; +import { Component } from "@angular/core"; /* IMPORTANT -In order to test out the full image example, to fix the App Transport Security error in iOS 9, you will need to follow this after adding the iOS platform: +In order to test out the full image example, +to fix the App Transport Security error in iOS 9, +you will need to follow this after adding the iOS platform: https://blog.nraboy.com/2015/12/fix-ios-9-app-transport-security-issues-in-nativescript/ */ @Component({ - selector: 'image-test', + selector: "image-test", template: ` @@ -22,19 +24,19 @@ https://blog.nraboy.com/2015/12/fix-ios-9-app-transport-security-issues-in-nativ ` }) export class ImageTest { - + public currentImage: string; private images: Array = [ - 'res://300x300.jpg', - '~/examples/image/img/Default.png', - 'http://www.codeproject.com/KB/mobile/883465/NativeScript.png' + "res://300x300.jpg", + "~/examples/image/img/Default.png", + "http://www.codeproject.com/KB/mobile/883465/NativeScript.png" ]; private cnt: number = 0; - constructor() { + constructor() { this.currentImage = this.images[this.cnt]; } - + changeImage(direction: number) { if (direction > 0) { this.cnt++; @@ -50,12 +52,12 @@ export class ImageTest { } this.currentImage = this.images[this.cnt]; } - + addImage(e: any, name: string): void { - if (name.indexOf('http') === -1) { + if (name.indexOf("http") === -1) { alert(`Must be a valid url to an image starting with 'http'!`); } else { - this.images.push(name); + this.images.push(name); this.currentImage = this.images[this.images.length - 1]; } } diff --git a/ng-sample/app/examples/list/data.service.ts b/ng-sample/app/examples/list/data.service.ts index e7139138b..2aef70c26 100644 --- a/ng-sample/app/examples/list/data.service.ts +++ b/ng-sample/app/examples/list/data.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable } from "@angular/core"; import { BehaviorSubject } from "rxjs/BehaviorSubject"; export class DataItem { @@ -10,13 +10,13 @@ export class DataService { private _intervalId; private _counter = 0; private _currentItems: Array; - + public items$: BehaviorSubject>; constructor() { this._currentItems = []; - for (var i = 0; i < 3; i++) { - this.appendItem() + for (let i = 0; i < 3; i++) { + this.appendItem(); } this.items$ = new BehaviorSubject(this._currentItems); @@ -51,4 +51,5 @@ export class DataService { this._currentItems.push(new DataItem(this._counter, "data item " + this._counter)); this._counter++; } -} \ No newline at end of file +} + diff --git a/ng-sample/app/examples/list/list-test-async.ts b/ng-sample/app/examples/list/list-test-async.ts index 5b0b76bcf..146ee9cba 100644 --- a/ng-sample/app/examples/list/list-test-async.ts +++ b/ng-sample/app/examples/list/list-test-async.ts @@ -1,12 +1,12 @@ -import { Component, ChangeDetectionStrategy } from '@angular/core'; +import { Component, ChangeDetectionStrategy } from "@angular/core"; import { DataItem, DataService } from "./data.service"; import { Observable } from "rxjs/Observable"; import { BehaviorSubject } from "rxjs/BehaviorSubject"; import "rxjs/add/operator/combineLatest"; @Component({ - selector: 'list-test-async', - styleUrls: ['examples/list/styles.css'], + selector: "list-test-async", + styleUrls: ["examples/list/styles.css"], providers: [DataService], changeDetection: ChangeDetectionStrategy.OnPush, template: ` @@ -29,7 +29,11 @@ import "rxjs/add/operator/combineLatest"; - + ` }) @@ -54,8 +58,8 @@ export class ListTestAsync { } @Component({ - selector: 'list-test-async-filter', - styleUrls: ['examples/list/styles.css'], + selector: "list-test-async-filter", + styleUrls: ["examples/list/styles.css"], providers: [DataService], changeDetection: ChangeDetectionStrategy.OnPush, template: ` diff --git a/ng-sample/app/examples/list/list-test.ts b/ng-sample/app/examples/list/list-test.ts index 1a08a1075..ccec8a964 100644 --- a/ng-sample/app/examples/list/list-test.ts +++ b/ng-sample/app/examples/list/list-test.ts @@ -1,14 +1,14 @@ -import {Component, Input, WrappedValue, ChangeDetectionStrategy, AfterViewChecked, DoCheck} from '@angular/core'; -import {Label} from 'ui/label'; -import {ObservableArray} from 'data/observable-array'; +import {Component, Input, WrappedValue, ChangeDetectionStrategy, AfterViewChecked, DoCheck} from "@angular/core"; +import {Label} from "ui/label"; +import {ObservableArray} from "data/observable-array"; class DataItem { constructor(public id: number, public name: string) { } } @Component({ - selector: 'item-component', - styleUrls: ['examples/list/styles.css'], + selector: "item-component", + styleUrls: ["examples/list/styles.css"], changeDetection: ChangeDetectionStrategy.OnPush, template: ` @@ -34,8 +34,8 @@ export class ItemComponent implements AfterViewChecked, DoCheck { } @Component({ - selector: 'list-test', - styleUrls: ['examples/list/styles.css'], + selector: "list-test", + styleUrls: ["examples/list/styles.css"], changeDetection: ChangeDetectionStrategy.OnPush, template: ` @@ -58,7 +58,7 @@ export class ItemComponent implements AfterViewChecked, DoCheck { // IN-PLACE TEMPLATE // @@ -70,7 +70,7 @@ export class ListTest { constructor() { this.myItems = []; this.counter = 0; - for (var i = 0; i < 100; i++) { + for (let i = 0; i < 100; i++) { this.myItems.push(new DataItem(i, "data item " + i)); this.counter = i; } @@ -87,5 +87,5 @@ export class ListTest { public static entries = [ ItemComponent - ] + ]; } diff --git a/ng-sample/app/examples/list/template-selector.ts b/ng-sample/app/examples/list/template-selector.ts index 1fce9e816..4557b7e9c 100644 --- a/ng-sample/app/examples/list/template-selector.ts +++ b/ng-sample/app/examples/list/template-selector.ts @@ -1,4 +1,4 @@ -import { Component, Input, ChangeDetectionStrategy, DoCheck } from '@angular/core'; +import { Component, Input, ChangeDetectionStrategy, DoCheck } from "@angular/core"; class DataItem { private static count = 0; @@ -9,8 +9,8 @@ class DataItem { } @Component({ - selector: 'item-component', - styleUrls: ['examples/list/styles.css'], + selector: "item-component", + styleUrls: ["examples/list/styles.css"], changeDetection: ChangeDetectionStrategy.OnPush, template: `` }) @@ -20,8 +20,8 @@ export class ItemComponent implements DoCheck { } @Component({ - selector: 'header-component', - styleUrls: ['examples/list/styles.css'], + selector: "header-component", + styleUrls: ["examples/list/styles.css"], changeDetection: ChangeDetectionStrategy.OnPush, template: `` }) @@ -31,14 +31,17 @@ export class HeaderComponent implements DoCheck { } @Component({ - selector: 'list-test', - styleUrls: ['examples/list/styles.css'], + selector: "list-test", + styleUrls: ["examples/list/styles.css"], changeDetection: ChangeDetectionStrategy.OnPush, template: ` - +