Skip to content

Commit 3f7b2d0

Browse files
committed
feat(lint): Add tslint + HUGE Refactor.
- Adds tslint plugin integration -Extends airbnb code styling Refactors all code accordingly
1 parent 29e5a6a commit 3f7b2d0

File tree

147 files changed

+1818
-1784
lines changed

Some content is hidden

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

147 files changed

+1818
-1784
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"moment": "^2.15.2",
3636
"rxjs": "5.4.0",
3737
"sw-toolbox": "3.6.0",
38+
"tslint-config-airbnb": "^5.2.1",
3839
"zone.js": "^0.8.12"
3940
},
4041
"devDependencies": {

src/app/app.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ export class MyApp {
3737
{ icon: 'camera', active: false },
3838
{ icon: 'beer', active: false },
3939
{ icon: 'power', active: false },
40-
]
40+
];
4141

4242
this.pages = [
4343
{ title: 'Home', component: 'HomePage', active: true, icon: 'home' },
44-
{ title: 'Ionic Official Components', component: 'IonicOfficialComponentsPage', active: false, icon: 'ionic' },
44+
{ title: 'Ionic Official Components',
45+
component: 'IonicOfficialComponentsPage', active: false, icon: 'ionic' },
4546
{ title: 'Ionic Native Features', component: 'IonicNativePage', active: false, icon: 'ionic' },
4647
{ title: 'Login', component: 'LoginListPage', active: false, icon: 'archive' },
4748
{ title: 'Lists', component: 'ListPage', active: false, icon: 'body' },

src/app/app.global.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
import { Injectable } from '@angular/core';
22
@Injectable()
33
export class AppState {
4-
_state = {}
5-
constructor() {
6-
}
4+
_state = {};
5+
76
// already return a clone of the current state
8-
get state() {
9-
return this._state = this._clone(this._state);
10-
}
7+
get state() {
8+
return this._state = this._clone(this._state);
9+
}
1110
// never allow mutation
12-
set state(value) {
13-
throw new Error('do not mutate the `.state` directly');
14-
}
15-
get(prop?: any) {
11+
set state(value) {
12+
throw new Error('do not mutate the `.state` directly');
13+
}
14+
get(prop?: any) {
1615
// use our state getter for the clone
17-
const state = this.state;
18-
return state.hasOwnProperty(prop) ? state[prop] : state;
19-
}
20-
set(prop: string, value: any) {
16+
const state = this.state;
17+
return state.hasOwnProperty(prop) ? state[prop] : state;
18+
}
19+
set(prop: string, value: any) {
2120
// internally mutate our state
22-
return this._state[prop] = value;
23-
}
24-
_clone(object) {
21+
return this._state[prop] = value;
22+
}
23+
_clone(object) {
2524
// simple object clone
26-
return JSON.parse(JSON.stringify(object));
27-
}
28-
}
25+
return JSON.parse(JSON.stringify(object));
26+
}
27+
}

src/app/app.imports.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,43 +40,43 @@ import { BrowserModule } from '@angular/platform-browser';
4040
import { HttpModule } from '@angular/http';
4141

4242
export const Modules = [
43-
SwingModule,
44-
BrowserModule,
45-
HttpModule,
46-
]
43+
SwingModule,
44+
BrowserModule,
45+
HttpModule,
46+
];
4747

4848
export const Pipes = [
49-
TemperaturePipe, MomentPipe, OrderByPipe, CapitalizePipe, ShortenStringPipe
50-
]
49+
TemperaturePipe, MomentPipe, OrderByPipe, CapitalizePipe, ShortenStringPipe
50+
];
5151

5252
export const Providers = [
53-
AlertService,
54-
ToastService,
55-
AppState,
56-
CameraProvider,
57-
NativeGoogleMapsProvider,
53+
AlertService,
54+
ToastService,
55+
AppState,
56+
CameraProvider,
57+
NativeGoogleMapsProvider,
5858

5959
// Ionic native specific providers
60-
BarcodeScanner,
61-
Camera,
62-
Diagnostic,
63-
Geolocation,
64-
CardIO,
65-
StatusBar,
66-
SplashScreen,
67-
GoogleMaps,
68-
]
60+
BarcodeScanner,
61+
Camera,
62+
Diagnostic,
63+
Geolocation,
64+
CardIO,
65+
StatusBar,
66+
SplashScreen,
67+
GoogleMaps,
68+
];
6969

7070
export const Components = [
71-
FlashCardComponent,
72-
TimerProgress,
73-
Timer,
74-
ExpandableHeader,
75-
Autosize
76-
]
71+
FlashCardComponent,
72+
TimerProgress,
73+
Timer,
74+
ExpandableHeader,
75+
Autosize
76+
];
7777

7878
export const Directives = [
79-
SlidingDrawer,
80-
Timer,
81-
Autosize,
82-
]
79+
SlidingDrawer,
80+
Timer,
81+
Autosize,
82+
];

src/app/shared.module.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import { NgModule } from '@angular/core';
33
import { IonicModule } from 'ionic-angular';
44

55
@NgModule({
6-
declarations: [
7-
Pipes,
8-
Directives,
9-
Components
10-
],
11-
imports: [
12-
IonicModule,
13-
],
14-
exports: [
15-
Pipes,
16-
Components
17-
]
6+
declarations: [
7+
Pipes,
8+
Directives,
9+
Components
10+
],
11+
imports: [
12+
IonicModule,
13+
],
14+
exports: [
15+
Pipes,
16+
Components
17+
]
1818
})
1919

20-
export class SharedModule { }
20+
export class SharedModule { }

src/components/autosize/autosize.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ElementRef, HostListener, Directive, OnInit} from '@angular/core';
1+
import { ElementRef, HostListener, Directive, OnInit } from '@angular/core';
22

33
@Directive({
44
selector: 'ion-textarea[autosize]'
@@ -18,9 +18,9 @@ export class Autosize implements OnInit {
1818
}
1919

2020
adjust():void {
21-
let textArea = this.element.nativeElement.getElementsByTagName('textarea')[0];
21+
const textArea = this.element.nativeElement.getElementsByTagName('textarea')[0];
2222
textArea.style.overflow = 'hidden';
2323
textArea.style.height = 'auto';
24-
textArea.style.height = textArea.scrollHeight + "px";
24+
textArea.style.height = textArea.scrollHeight + 'px';
2525
}
26-
}
26+
}
Lines changed: 64 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,84 @@
11
import { Component, Input } from '@angular/core';
22

33
export interface CountdownTimer {
4-
seconds: number;
5-
secondsRemaining: number;
6-
runTimer: boolean;
7-
hasStarted: boolean;
8-
hasFinished: boolean;
9-
displayTime: string;
4+
seconds: number;
5+
secondsRemaining: number;
6+
runTimer: boolean;
7+
hasStarted: boolean;
8+
hasFinished: boolean;
9+
displayTime: string;
1010
}
1111

1212
@Component({
13-
selector: 'timer',
14-
templateUrl: 'timer.html'
13+
selector: 'timer',
14+
templateUrl: 'timer.html'
1515
})
1616
export class Timer {
1717

18-
@Input() timeInSeconds: number;
19-
timer: CountdownTimer;
18+
@Input() timeInSeconds: number;
19+
timer: CountdownTimer;
2020

21-
constructor() { }
21+
ngOnInit() {
22+
this.initTimer();
23+
}
2224

23-
ngOnInit() {
24-
this.initTimer();
25-
}
25+
hasFinished() {
26+
return this.timer.hasFinished;
27+
}
2628

27-
hasFinished() {
28-
return this.timer.hasFinished;
29-
}
29+
initTimer() {
30+
if (!this.timeInSeconds) { this.timeInSeconds = 0; }
3031

31-
initTimer() {
32-
if (!this.timeInSeconds) { this.timeInSeconds = 0; }
32+
this.timer = <CountdownTimer>{
33+
seconds: this.timeInSeconds,
34+
runTimer: false,
35+
hasStarted: false,
36+
hasFinished: false,
37+
secondsRemaining: this.timeInSeconds
38+
};
3339

34-
this.timer = <CountdownTimer>{
35-
seconds: this.timeInSeconds,
36-
runTimer: false,
37-
hasStarted: false,
38-
hasFinished: false,
39-
secondsRemaining: this.timeInSeconds
40-
};
40+
this.timer.displayTime = this.getSecondsAsDigitalClock(this.timer.secondsRemaining);
41+
}
4142

42-
this.timer.displayTime = this.getSecondsAsDigitalClock(this.timer.secondsRemaining);
43-
}
43+
startTimer() {
44+
this.timer.hasStarted = true;
45+
this.timer.runTimer = true;
46+
this.timerTick();
47+
}
4448

45-
startTimer() {
46-
this.timer.hasStarted = true;
47-
this.timer.runTimer = true;
48-
this.timerTick();
49-
}
50-
51-
pauseTimer() {
52-
this.timer.runTimer = false;
53-
}
49+
pauseTimer() {
50+
this.timer.runTimer = false;
51+
}
5452

55-
resumeTimer() {
56-
this.startTimer();
57-
}
53+
resumeTimer() {
54+
this.startTimer();
55+
}
5856

59-
timerTick() {
60-
setTimeout(() => {
61-
if (!this.timer.runTimer) { return; }
62-
this.timer.secondsRemaining--;
63-
this.timer.displayTime = this.getSecondsAsDigitalClock(this.timer.secondsRemaining);
64-
if (this.timer.secondsRemaining > 0) {
65-
this.timerTick();
66-
}
67-
else {
68-
this.timer.hasFinished = true;
69-
}
70-
}, 1000);
71-
}
57+
timerTick() {
58+
setTimeout(() => {
59+
if (!this.timer.runTimer) { return; }
60+
this.timer.secondsRemaining--;
61+
this.timer.displayTime = this.getSecondsAsDigitalClock(this.timer.secondsRemaining);
62+
if (this.timer.secondsRemaining > 0) {
63+
this.timerTick();
64+
} else {
65+
this.timer.hasFinished = true;
66+
}
67+
}, 1000);
68+
}
7269

73-
getSecondsAsDigitalClock(inputSeconds: number) {
74-
var sec_num = parseInt(inputSeconds.toString(), 10); // don't forget the second param
75-
var hours = Math.floor(sec_num / 3600);
76-
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
77-
var seconds = sec_num - (hours * 3600) - (minutes * 60);
78-
var hoursString = '';
79-
var minutesString = '';
80-
var secondsString = '';
81-
hoursString = (hours < 10) ? "0" + hours : hours.toString();
82-
minutesString = (minutes < 10) ? "0" + minutes : minutes.toString();
83-
secondsString = (seconds < 10) ? "0" + seconds : seconds.toString();
84-
return hoursString + ':' + minutesString + ':' + secondsString;
85-
}
70+
getSecondsAsDigitalClock(inputSeconds: number) {
71+
const secNum = parseInt(inputSeconds.toString(), 10); // don't forget the second param
72+
const hours = Math.floor(secNum / 3600);
73+
const minutes = Math.floor((secNum - (hours * 3600)) / 60);
74+
const seconds = secNum - (hours * 3600) - (minutes * 60);
75+
let hoursString = '';
76+
let minutesString = '';
77+
let secondsString = '';
78+
hoursString = (hours < 10) ? '0' + hours : hours.toString();
79+
minutesString = (minutes < 10) ? '0' + minutes : minutes.toString();
80+
secondsString = (seconds < 10) ? '0' + seconds : seconds.toString();
81+
return hoursString + ':' + minutesString + ':' + secondsString;
82+
}
8683

87-
}
84+
}

0 commit comments

Comments
 (0)