Skip to content

Commit c6f742d

Browse files
committed
Enable tslint and fix complaints.
1 parent d42e37b commit c6f742d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+788
-484
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ install:
3535
- tns error-reporting disable
3636
- cd nativescript-angular
3737
- npm install
38+
- npm run tslint
3839
- cd ../tests
3940
- npm install
4041
- tns platform add android

Diff for: nativescript-angular/animation-driver.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { AnimationPlayer } from "@angular/core";
22
import { AnimationStyles, AnimationKeyframe } from "./private_import_core";
3-
import { NativeScriptAnimationPlayer } from './animation-player';
3+
import { NativeScriptAnimationPlayer } from "./animation-player";
44
import { View } from "ui/core/view";
5-
import { getPropertyByCssName } from 'ui/styling/style-property';
5+
import { getPropertyByCssName } from "ui/styling/style-property";
66

77
export abstract class AnimationDriver {
88
abstract animate(
@@ -16,7 +16,14 @@ export class NativeScriptAnimationDriver implements AnimationDriver {
1616
return (<View>element).style._getValue(getPropertyByCssName(prop));
1717
}
1818

19-
animate(element: any, _startingStyles: AnimationStyles, keyframes: AnimationKeyframe[], duration: number, delay: number, easing: string): AnimationPlayer {
19+
animate(
20+
element: any,
21+
_startingStyles: AnimationStyles,
22+
keyframes: AnimationKeyframe[],
23+
duration: number,
24+
delay: number,
25+
easing: string
26+
): AnimationPlayer {
2027
return new NativeScriptAnimationPlayer(element, keyframes, duration, delay, easing);
2128
}
2229
}

Diff for: nativescript-angular/animation-player.ts

+57-25
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { AnimationPlayer } from "@angular/core";
22
import { AnimationKeyframe } from "./private_import_core";
3-
import { KeyframeAnimation, KeyframeAnimationInfo, KeyframeInfo, KeyframeDeclaration } from 'ui/animation/keyframe-animation';
3+
import {
4+
KeyframeAnimation,
5+
KeyframeAnimationInfo,
6+
KeyframeInfo,
7+
KeyframeDeclaration
8+
} from "ui/animation/keyframe-animation";
49
import { View } from "ui/core/view";
510
import { AnimationCurve } from "ui/enums";
6-
import { ValueSource } from 'ui/core/dependency-observable';
11+
import { ValueSource } from "ui/core/dependency-observable";
712
import { isString } from "utils/types";
8-
import * as styleProperty from 'ui/styling/style-property';
13+
import * as styleProperty from "ui/styling/style-property";
914

1015
export class NativeScriptAnimationPlayer implements AnimationPlayer {
1116

@@ -18,7 +23,13 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
1823
private animation: KeyframeAnimation;
1924
private target: View;
2025

21-
constructor(element: Node, keyframes: AnimationKeyframe[], duration: number, delay: number, easing: string) {
26+
constructor(
27+
element: Node,
28+
keyframes: AnimationKeyframe[],
29+
duration: number,
30+
delay: number,
31+
easing: string
32+
) {
2233

2334
this.parentPlayer = null;
2435

@@ -36,7 +47,9 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
3647
keyframeAnimationInfo.duration = duration;
3748
keyframeAnimationInfo.delay = delay;
3849
keyframeAnimationInfo.iterations = 1;
39-
keyframeAnimationInfo.curve = easing ? NativeScriptAnimationPlayer.animationTimingFunctionConverter(easing) : AnimationCurve.ease;
50+
keyframeAnimationInfo.curve = easing ?
51+
NativeScriptAnimationPlayer.animationTimingFunctionConverter(easing) :
52+
AnimationCurve.ease;
4053
keyframeAnimationInfo.keyframes = new Array<KeyframeInfo>();
4154
keyframeAnimationInfo.isForwards = true;
4255

@@ -53,16 +66,16 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
5366
value = property.valueConverter(<string>value);
5467
}
5568
keyframeInfo.declarations.push({ property: property.name, value: value });
56-
}
57-
else if (typeof value === "string" && substyle === "transform") {
69+
} else if (typeof value === "string" && substyle === "transform") {
5870
NativeScriptAnimationPlayer.parseTransform(<string>value, keyframeInfo);
5971
}
6072
}
6173
}
6274
keyframeAnimationInfo.keyframes.push(keyframeInfo);
6375
}
6476

65-
this.animation = KeyframeAnimation.keyframeAnimationFromInfo(keyframeAnimationInfo, ValueSource.VisualState);
77+
this.animation = KeyframeAnimation.keyframeAnimationFromInfo(
78+
keyframeAnimationInfo, ValueSource.VisualState);
6679
}
6780

6881
init(): void {
@@ -159,8 +172,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
159172
NativeScriptAnimationPlayer.bezieArgumentConverter(bezierArr[1]),
160173
NativeScriptAnimationPlayer.bezieArgumentConverter(bezierArr[2]),
161174
NativeScriptAnimationPlayer.bezieArgumentConverter(bezierArr[3]));
162-
}
163-
else {
175+
} else {
164176
throw new Error("Invalid value for animation: " + value);
165177
}
166178
}
@@ -178,16 +190,14 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
178190
let operations = {};
179191
operations[value] = value;
180192
return operations;
181-
}
182-
else if (isString(value)) {
193+
} else if (isString(value)) {
183194
let operations = {};
184195
let operator = "";
185196
let pos = 0;
186197
while (pos < value.length) {
187198
if (value[pos] === " " || value[pos] === ",") {
188199
pos++;
189-
}
190-
else if (value[pos] === "(") {
200+
} else if (value[pos] === "(") {
191201
let start = pos + 1;
192202
while (pos < value.length && value[pos] !== ")") {
193203
pos++;
@@ -196,14 +206,12 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
196206
operations[operator] = operand.trim();
197207
operator = "";
198208
pos++;
199-
}
200-
else {
209+
} else {
201210
operator += value[pos++];
202211
}
203212
}
204213
return operations;
205-
}
206-
else {
214+
} else {
207215
return undefined;
208216
}
209217
}
@@ -215,29 +223,50 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
215223
for (let transform in newTransform) {
216224
switch (transform) {
217225
case "scaleX":
218-
animationInfo.declarations.push({ property: "scale", value: { x: parseFloat(newTransform[transform]), y: 1 } });
226+
animationInfo.declarations.push({
227+
property: "scale",
228+
value: { x: parseFloat(newTransform[transform]), y: 1 }
229+
});
219230
break;
220231
case "scaleY":
221-
animationInfo.declarations.push({ property: "scale", value: { x: 1, y: parseFloat(newTransform[transform]) } });
232+
animationInfo.declarations.push({
233+
property: "scale",
234+
value: { x: 1, y: parseFloat(newTransform[transform]) }
235+
});
222236
break;
223237
case "scale":
224238
case "scale3d":
225239
values = newTransform[transform].split(",");
226240
if (values.length === 2 || values.length === 3) {
227-
animationInfo.declarations.push({ property: "scale", value: { x: parseFloat(values[0]), y: parseFloat(values[1]) } });
241+
animationInfo.declarations.push({
242+
property: "scale",
243+
value: { x: parseFloat(values[0]), y: parseFloat(values[1]) }
244+
});
228245
}
229246
break;
230247
case "translateX":
231-
animationInfo.declarations.push({ property: "translate", value: { x: parseFloat(newTransform[transform]), y: 0 } });
248+
animationInfo.declarations.push({
249+
property: "translate",
250+
value: { x: parseFloat(newTransform[transform]), y: 0 }
251+
});
232252
break;
233253
case "translateY":
234-
animationInfo.declarations.push({ property: "translate", value: { x: 0, y: parseFloat(newTransform[transform]) } });
254+
animationInfo.declarations.push({
255+
property: "translate",
256+
value: { x: 0, y: parseFloat(newTransform[transform]) }
257+
});
235258
break;
236259
case "translate":
237260
case "translate3d":
238261
values = newTransform[transform].split(",");
239262
if (values.length === 2 || values.length === 3) {
240-
animationInfo.declarations.push({ property: "translate", value: { x: parseFloat(values[0]), y: parseFloat(values[1]) } });
263+
animationInfo.declarations.push({
264+
property: "translate",
265+
value: {
266+
x: parseFloat(values[0]),
267+
y: parseFloat(values[1])
268+
}
269+
});
241270
}
242271
break;
243272
case "rotate":
@@ -250,9 +279,12 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
250279
break;
251280
case "none":
252281
animationInfo.declarations.push({ property: "scale", value: { x: 1, y: 1 } });
253-
animationInfo.declarations.push({ property: "translate", value: { x: 0, y: 0 } });
282+
animationInfo.declarations.push(
283+
{ property: "translate", value: { x: 0, y: 0 } });
254284
animationInfo.declarations.push({ property: "rotate", value: 0 });
255285
break;
286+
default:
287+
throw new Error("Unsupported transform: " + transform);
256288
}
257289
}
258290
return array;

Diff for: nativescript-angular/collection-facade.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* tslint:disable */
12
//Copied unexported functions from @angular/core/src/facade/collection
23
import {
34
isJsObject, isArray, getSymbolIterator,
@@ -18,7 +19,7 @@ export class ListWrapper {
1819
static createGrowableSize(size: number): any[] { return new Array(size); }
1920
static clone<T>(array: T[]): T[] { return array.slice(0); }
2021
static forEachWithIndex<T>(array: T[], fn: (t: T, n: number) => void) {
21-
for (var i = 0; i < array.length; i++) {
22+
for (let i = 0; i < array.length; i++) {
2223
fn(array[i], i);
2324
}
2425
}
@@ -35,24 +36,24 @@ export class ListWrapper {
3536
}
3637
static contains<T>(list: T[], el: T): boolean { return list.indexOf(el) !== -1; }
3738
static reversed<T>(array: T[]): T[] {
38-
var a = ListWrapper.clone(array);
39+
let a = ListWrapper.clone(array);
3940
return a.reverse();
4041
}
4142
static concat(a: any[], b: any[]): any[] { return a.concat(b); }
4243
static insert<T>(list: T[], index: number, value: T) { list.splice(index, 0, value); }
4344
static removeAt<T>(list: T[], index: number): T {
44-
var res = list[index];
45+
let res = list[index];
4546
list.splice(index, 1);
4647
return res;
4748
}
4849
static removeAll<T>(list: T[], items: T[]) {
49-
for (var i = 0; i < items.length; ++i) {
50-
var index = list.indexOf(items[i]);
50+
for (let i = 0; i < items.length; ++i) {
51+
let index = list.indexOf(items[i]);
5152
list.splice(index, 1);
5253
}
5354
}
5455
static remove<T>(list: T[], el: T): boolean {
55-
var index = list.indexOf(el);
56+
let index = list.indexOf(el);
5657
if (index > -1) {
5758
list.splice(index, 1);
5859
return true;
@@ -66,7 +67,7 @@ export class ListWrapper {
6667
}
6768
static equals(a: any[], b: any[]): boolean {
6869
if (a.length != b.length) return false;
69-
for (var i = 0; i < a.length; ++i) {
70+
for (let i = 0; i < a.length; ++i) {
7071
if (a[i] !== b[i]) return false;
7172
}
7273
return true;
@@ -89,14 +90,14 @@ export class ListWrapper {
8990
if (list.length == 0) {
9091
return null;
9192
}
92-
var solution: any /** TODO #???? */ = null;
93-
var maxValue = -Infinity;
94-
for (var index = 0; index < list.length; index++) {
95-
var candidate = list[index];
93+
let solution: any /** TODO #???? */ = null;
94+
let maxValue = -Infinity;
95+
for (let index = 0; index < list.length; index++) {
96+
let candidate = list[index];
9697
if (isBlank(candidate)) {
9798
continue;
9899
}
99-
var candidateValue = predicate(candidate);
100+
let candidateValue = predicate(candidate);
100101
if (candidateValue > maxValue) {
101102
solution = candidate;
102103
maxValue = candidateValue;
@@ -106,22 +107,22 @@ export class ListWrapper {
106107
}
107108

108109
static flatten<T>(list: Array<T|T[]>): T[] {
109-
var target: any[] = [];
110+
let target: any[] = [];
110111
_flattenArray(list, target);
111112
return target;
112113
}
113114

114115
static addAll<T>(list: Array<T>, source: Array<T>): void {
115-
for (var i = 0; i < source.length; i++) {
116+
for (let i = 0; i < source.length; i++) {
116117
list.push(source[i]);
117118
}
118119
}
119120
}
120121

121122
function _flattenArray(source: any[], target: any[]): any[] {
122123
if (isPresent(source)) {
123-
for (var i = 0; i < source.length; i++) {
124-
var item = source[i];
124+
for (let i = 0; i < source.length; i++) {
125+
let item = source[i];
125126
if (isArray(item)) {
126127
_flattenArray(item, target);
127128
} else {

Diff for: nativescript-angular/common/detached-loader.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
ComponentRef, ComponentFactory, ViewContainerRef,
33
Component, Type, ComponentFactoryResolver, ChangeDetectorRef
4-
} from '@angular/core';
4+
} from "@angular/core";
55
import * as trace from "trace";
66

77
export const CATEGORY = "detached-loader";
@@ -12,36 +12,43 @@ function log(message: string) {
1212

1313
/**
1414
* Wrapper component used for loading components when navigating
15-
* It uses DetachedContainer as selector so that it is containerRef is not attached to the visual tree.
15+
* It uses DetachedContainer as selector so that it is containerRef is not attached to
16+
* the visual tree.
1617
*/
1718
@Component({
18-
selector: 'DetachedContainer',
19+
selector: "DetachedContainer",
1920
template: `<Placeholder #loader></Placeholder>`
2021
})
2122
export class DetachedLoader {
22-
constructor(private resolver: ComponentFactoryResolver, private changeDetector: ChangeDetectorRef, private containerRef: ViewContainerRef) { }
23+
constructor(
24+
private resolver: ComponentFactoryResolver,
25+
private changeDetector: ChangeDetectorRef,
26+
private containerRef: ViewContainerRef
27+
) { }
2328

2429
private loadInLocation(componentType: Type<any>): Promise<ComponentRef<any>> {
25-
const factory = this.resolver.resolveComponentFactory(componentType)
30+
const factory = this.resolver.resolveComponentFactory(componentType);
2631
const componentRef = this.containerRef.createComponent(
2732
factory, this.containerRef.length, this.containerRef.parentInjector);
2833

2934
// Component is created, buit may not be checked if we are loading
3035
// inside component with OnPush CD strategy. Mark us for check to be sure CD will reach us.
31-
// We are inside a promise here so no need for setTimeout - CD should trigger after the promise.
36+
// We are inside a promise here so no need for setTimeout - CD should trigger
37+
// after the promise.
3238
log("DetachedLoader.loadInLocation component loaded -> markForCheck");
3339
this.changeDetector.markForCheck();
3440

3541
return Promise.resolve(componentRef);
3642
}
3743

38-
//TODO: change this API -- async promises not needed here anymore.
44+
// TODO: change this API -- async promises not needed here anymore.
3945
public loadComponent(componentType: Type<any>): Promise<ComponentRef<any>> {
4046
log("DetachedLoader.loadComponent");
4147
return this.loadInLocation(componentType);
4248
}
4349

4450
public loadWithFactory<T>(factory: ComponentFactory<T>): ComponentRef<T> {
45-
return this.containerRef.createComponent(factory, this.containerRef.length, this.containerRef.parentInjector, null);
51+
return this.containerRef.createComponent(factory,
52+
this.containerRef.length, this.containerRef.parentInjector, null);
4653
}
4754
}

Diff for: nativescript-angular/common/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function convertToInt(value): number {
88
if (isNumber(value)) {
99
normalizedValue = value;
1010
} else {
11-
let parsedValue = parseInt(value.toString());
11+
let parsedValue = parseInt(value.toString(), 10);
1212
normalizedValue = isNaN(parsedValue) ? 0 : parsedValue;
1313
}
1414
}

0 commit comments

Comments
 (0)