Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

chore: first sweep on linting the codebase #1616

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,15 @@ gulp.task('_zip-examples', function() {
// Linting

gulp.task('lint', function() {
return gulp.src(['./public/docs/_examples/style-guide/ts/**/*.ts', '!./public/docs/_examples/style-guide/ts/**/*.avoid.ts'])
return gulp.src([
'./public/docs/_examples/**/*.ts',
'!./public/docs/_examples/**/ts-snippets/*.ts',
'!./public/docs/_examples/style-guide/ts/**/*.avoid.ts',
'!./public/docs/_examples/**/node_modules/**/*',
'!./public/docs/_examples/_protractor/**/*',
'!./public/docs/_examples/**/typings/**/*',
'!./public/docs/_examples/**/typings-ng1/**/*'
])
.pipe(tslint({
rulesDirectory: ['node_modules/codelyzer'],
configuration: require('./tslint.json')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"browser-sync": "^2.9.3",
"canonical-path": "0.0.2",
"cross-spawn": "^4.0.0",
"codelyzer": "0.0.20",
"codelyzer": "0.0.22",
"del": "^2.2.0",
"dgeni": "^0.4.0",
"dgeni-packages": "^0.13.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const HEROES = [
export class BackendService {
constructor(private logger: Logger) {}

getAll(type:Type) : PromiseLike<any[]>{
getAll(type: Type): PromiseLike<any[]> {
if (type === Hero) {
// TODO get from the database
return Promise.resolve<Hero[]>(HEROES);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input} from '@angular/core';
import { Component, Input } from '@angular/core';

import { Hero } from './hero';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class SalesTaxComponent {
constructor(private salesTaxService: SalesTaxService) { }
// #enddocregion ctor

getTax(value:string | number){
getTax(value: string | number) {
return this.salesTaxService.getVAT(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// #docregion
import { Inject, Injectable } from '@angular/core';
import { Inject, Injectable } from '@angular/core';

import { TaxRateService } from './tax-rate.service';

// #docregion class
@Injectable()
export class SalesTaxService {
constructor(private rateService: TaxRateService) { }
getVAT(value:string | number){
let amount:number;
if (typeof value === "string"){
getVAT(value: string | number) {
let amount: number;
if (typeof value === 'string') {
amount = parseFloat(value);
} else {
amount = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { Injectable } from '@angular/core';
// #docregion class
@Injectable()
export class TaxRateService {
getRate(rateName:string){return 0.10;} // always 10% everywhere
getRate(rateName: string) {return 0.10; } // always 10% everywhere
}
// #enddocregion class
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ import { HighlightDirective } from './highlight.directive';

export class AppComponent { }

// #enddocregion
// #enddocregion
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import { Directive, ElementRef, Input } from '@angular/core';
export class HighlightDirective {

// #docregion ctor
private el:HTMLElement;
private el: HTMLElement;
constructor(el: ElementRef) { this.el = el.nativeElement; }
// #enddocregion ctor

// #docregion mouse-methods
onMouseEnter() { this.highlight("yellow"); }
onMouseEnter() { this.highlight('yellow'); }
onMouseLeave() { this.highlight(null); }

private highlight(color: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { Directive, ElementRef, Input } from '@angular/core';
export class HighlightDirective {
private _defaultColor = 'red';
private el: HTMLElement;

constructor(el: ElementRef) { this.el = el.nativeElement; }
// #enddocregion class-1

// #docregion defaultColor
@Input() set defaultColor(colorName:string){
@Input() set defaultColor(colorName: string){
this._defaultColor = colorName || this._defaultColor;
}
// #enddocregion defaultColor
Expand All @@ -33,7 +33,7 @@ export class HighlightDirective {
// #enddocregion mouse-enter
onMouseLeave() { this.highlight(null); }

private highlight(color:string) {
private highlight(color: string) {
this.el.style.backgroundColor = color;
}
}
Expand Down
6 changes: 3 additions & 3 deletions public/docs/_examples/cb-a1-a2-quick-reference/e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Angular 1 to 2 Quick Reference Tests', function () {

posterButton.click().then(function () {
testImagesAreDisplayed(isDisplayed);
})
});
}

function getMovieRows() {
Expand All @@ -107,7 +107,7 @@ describe('Angular 1 to 2 Quick Reference Tests', function () {
} else {
expect(favoriteHeroLabel.isDisplayed()).toBe(false);
}
})
})
});
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { StringSafeDatePipe } from './date.pipe';
// #docregion component
@Component({
selector: 'movie-list',
templateUrl:'app/movie-list.component.html',
templateUrl: 'app/movie-list.component.html',
// #enddocregion component
// #docregion style-url
styleUrls: ['app/movie-list.component.css'],
Expand Down
14 changes: 7 additions & 7 deletions public/docs/_examples/cb-component-communication/e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('Component Communication Cookbook Tests', function () {
for (let i = 0; i < _heroNames.length; i++) {
let childTitle = heroes.get(i).element(by.tagName('h3')).getText();
let childDetail = heroes.get(i).element(by.tagName('p')).getText();
expect(childTitle).toEqual(_heroNames[i] + ' says:')
expect(childDetail).toContain(_masterName)
expect(childTitle).toEqual(_heroNames[i] + ' says:');
expect(childDetail).toContain(_masterName);
}
});
// ...
Expand All @@ -38,7 +38,7 @@ describe('Component Communication Cookbook Tests', function () {
let hero = parent.all(by.tagName('name-child')).get(_nonEmptyNameIndex);

let displayName = hero.element(by.tagName('h3')).getText();
expect(displayName).toEqual(_nonEmptyName)
expect(displayName).toEqual(_nonEmptyName);
});

it('should replace empty name with default name', function () {
Expand All @@ -48,7 +48,7 @@ describe('Component Communication Cookbook Tests', function () {
let hero = parent.all(by.tagName('name-child')).get(_emptyNameIndex);

let displayName = hero.element(by.tagName('h3')).getText();
expect(displayName).toEqual(_defaultName)
expect(displayName).toEqual(_defaultName);
});
// ...
// #enddocregion parent-to-child-setter
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('Component Communication Cookbook Tests', function () {
expect(actual.label).toBe(labelAfter2Minor);
expect(actual.count).toBe(3);
expect(actual.logs.get(2).getText()).toBe(logAfter2Minor);
})
});
});
});

Expand Down Expand Up @@ -155,11 +155,11 @@ describe('Component Communication Cookbook Tests', function () {
// Can't run timer tests in protractor because
// interaction w/ zones causes all tests to freeze & timeout.
xdescribe('Parent calls child via local var', function() {
countDownTimerTests('countdown-parent-lv')
countDownTimerTests('countdown-parent-lv');
});

xdescribe('Parent calls ViewChild', function() {
countDownTimerTests('countdown-parent-vc')
countDownTimerTests('countdown-parent-vc');
});

function countDownTimerTests(parentTag: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let directives: any[] = [
// Include Countdown examples
// unless in e2e tests which they break.
if (!/e2e/.test(location.search)) {
console.log('adding countdown timer examples')
console.log('adding countdown timer examples');
directives.push(CountdownLocalVarParentComponent);
directives.push(CountdownViewChildParentComponent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ import { Subscription } from 'rxjs/Subscription';
</p>
`
})
export class AstronautComponent implements OnDestroy{
export class AstronautComponent implements OnDestroy {
@Input() astronaut: string;
mission = "<no mission announced>";
mission = '<no mission announced>';
confirmed = false;
announced = false;
subscription:Subscription;
subscription: Subscription;

constructor(private missionService: MissionService) {
this.subscription = missionService.missionAnnounced$.subscribe(
mission => {
this.mission = mission;
this.announced = true;
this.confirmed = false;
})
});
}

confirm() {
this.confirmed = true;
this.missionService.confirmMission(this.astronaut);
}

ngOnDestroy(){
ngOnDestroy() {
// prevent memory leak when component destroyed
this.subscription.unsubscribe();
}
}
// #enddocregion
// #enddocregion
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CountdownTimerComponent } from './countdown-timer.component';
//// Local variable, #timer, version
// #docregion lv
@Component({
selector:'countdown-parent-lv',
selector: 'countdown-parent-lv',
template: `
<h3>Countdown to Liftoff (via local variable)</h3>
<button (click)="timer.start()">Start</button>
Expand All @@ -28,7 +28,7 @@ export class CountdownLocalVarParentComponent { }
//// View Child version
// #docregion vc
@Component({
selector:'countdown-parent-vc',
selector: 'countdown-parent-vc',
template: `
<h3>Countdown to Liftoff (via ViewChild)</h3>
<button (click)="start()">Start</button>
Expand All @@ -42,18 +42,18 @@ export class CountdownLocalVarParentComponent { }
export class CountdownViewChildParentComponent implements AfterViewInit {

@ViewChild(CountdownTimerComponent)
private timerComponent:CountdownTimerComponent;
private timerComponent: CountdownTimerComponent;

seconds() { return 0; }

ngAfterViewInit() {
// Redefine `seconds()` to get from the `CountdownTimerComponent.seconds` ...
// but wait a tick first to avoid one-time devMode
// unidirectional-data-flow-violation error
setTimeout(() => this.seconds = () => this.timerComponent.seconds, 0)
setTimeout(() => this.seconds = () => this.timerComponent.seconds, 0);
}

start(){ this.timerComponent.start(); }
start() { this.timerComponent.start(); }
stop() { this.timerComponent.stop(); }
}
// #enddocregion vc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CountdownTimerComponent implements OnInit, OnDestroy {
message = '';
seconds = 11;

clearTimer() {clearInterval(this.intervalId);}
clearTimer() { clearInterval(this.intervalId); }

ngOnInit() { this.start(); }
ngOnDestroy() { this.clearTimer(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export const HEROES = [
{name: 'Mr. IQ'},
{name: 'Magneta'},
{name: 'Bombasto'}
];
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { bootstrap } from '@angular/platform-browser-dynamic';

import { AppComponent } from './app.component';

bootstrap(AppComponent);
bootstrap(AppComponent);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// #docregion
import { Injectable } from '@angular/core'
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';

@Injectable()
Expand All @@ -15,7 +15,7 @@ export class MissionService {

// Service message commands
announceMission(mission: string) {
this.missionAnnouncedSource.next(mission)
this.missionAnnouncedSource.next(mission);
}

confirmMission(astronaut: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { MissionService } from './mission.service';
providers: [MissionService]
})
export class MissionControlComponent {
astronauts = ['Lovell', 'Swigert', 'Haise']
astronauts = ['Lovell', 'Swigert', 'Haise'];
history: string[] = [];
missions = ['Fly to the moon!',
'Fly to mars!',
Expand All @@ -32,7 +32,7 @@ export class MissionControlComponent {
missionService.missionConfirmed$.subscribe(
astronaut => {
this.history.push(`${astronaut} confirmed the mission`);
})
});
}

announce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class VersionChildComponent implements OnChanges {
@Input() minor: number;
changeLog: string[] = [];

ngOnChanges(changes: {[propKey:string]: SimpleChange}){
ngOnChanges(changes: {[propKey: string]: SimpleChange}) {
let log: string[] = [];
for (let propName in changes) {
let changedProp = changes[propName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export class VoterComponent {
@Output() onVoted = new EventEmitter<boolean>();
voted = false;

vote(agreed:boolean){
vote(agreed: boolean) {
this.onVoted.emit(agreed);
this.voted = true;
}
}
// #enddocregion
// #enddocregion
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { VoterComponent } from './voter.component';
export class VoteTakerComponent {
agreed = 0;
disagreed = 0;
voters = ['Mr. IQ', 'Ms. Universe', 'Bombasto']
voters = ['Mr. IQ', 'Ms. Universe', 'Bombasto'];

onVoted(agreed: boolean) {
agreed ? this.agreed++ : this.disagreed++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Cookbook: component-relative paths', function () {
title: element( by.tagName( 'h1' )),
absComp: element( by.css( 'absolute-path div' ) ),
relComp: element( by.css( 'relative-path div' ) )
}
};
}

let page: Page;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #docregion
import { Component } from '@angular/core';

import { SomeAbsoluteComponent, SomeRelativeComponent} from './some.component';
import { SomeAbsoluteComponent, SomeRelativeComponent } from './some.component';

@Component({
selector: 'my-app',
Expand Down
Loading