Skip to content

Commit 425db8a

Browse files
joshwiensjelbourn
authored andcommitted
build(linting): execute tslint in travis
execute tslint in travis ci build - uses npm script until ng lint task is stable - lints only the typescript in the src directory - executes in before_script section of travis.yml to fail fast chore(tslint): update no-unused-variable tslint rule modify the no-unused-variable tslint rule to ignore - ddescribe - iit style(button): resolves basic tslint errors resolve the following tslint violations - max-line-length - whitespace style(card): resolves basic tslint errors resolve the following tslint violations - max-line-length style(progress-circle): resolves basic tslint errors resolve the following tslint violations - max-line-length - whitespace - eofline - semicolon style(sidenav): resolves basic tslint errors resolve the following tslint violations - no-inferrable-types - max-line-length - whitespace - eofline - semicolon style(annotations): resolves basic tslint errors resolve the following tslint violations - semicolon style(demo-app): resolves basic tslint errors resolve the following tslint violations - eofline style(directives): resolves basic tslint errors resolve the following tslint violations - quotemark style(sidenav): resolves unused variable tslint errors remove the following unused imports - Predicate - PromiseWrapper - TimerWrapper remove the following unused variable - let openPromise: Promise<void> ignore rule no-unused-variable on the following functions - closeModalSidenav_() - isShowingBackdrop_() - getMarginLeft_() - getMarginRight_() - getPositionLeft_() - getPositionRight_() style(progress-circle): resolves unused variable tslint errors remove the following unused imports - Attribute - ElementRef - ViewEncapsulation style(button): resolves unused variable tslint errors remove the following unused imports - ComponentFixture - beforeEachProviders - provide - DebugElement - AsyncTestFn ignore rule no-unused-variable on the following function - testAsync() style(one-of): resolves variable-name tslint errors rename OneOf to oneOf (camelCase) in following files - progress_circle.ts - sidenav.ts - one-of.ts - dir.ts style(test_injector): resolves variable tslint errors remove the following unused import - ExceptionHandler ignore rule variable-name on the following variables - _testInjector - _providers - _injector - _instantiated style(main): resolves variable tslint errors remove the following unused imports - HashLocationStrategy - LocationStrategy - provide build(linting): update tslint version Update to 3.5.0 to make user of ignore patterns style(sidenav): remove individual tslint rule ignore statements - remove all individual ignore statements for no-unused-variable on private class members - add regex to no-unused-variable ignore-pattern style(sidenav.spec): modify line break - break after toEqual to improve readability style(test_injector): resolves variable tslint errors rename var to let remove all individual ignore statements for variable-name move _ to end of private var name rename testInjector to testInjectorCache - resolves no-shadowed-variable error in setBaseTestProviders() - resolves no-shadowed-variable error in resetBaseTestProviders() style(button.spec): remove unused testAsync function - remove unused testAsync function - remove now unused module imports style(karma-test-shim): increase jasmine default timeout increase jasmine.DEFAULT_TIMEOUT_INTERVAL from 2000 to 4000ms. - Temporary resolution of Async callback timeouts in tests style(button): fix whitespace resolve whitespace issue in setClassList() style(one-of): modified case of OneOf - Fixed case for OneOf dec. factory - Modified export in one-of.ts Closes #134
1 parent 10c9aed commit 425db8a

File tree

18 files changed

+98
-109
lines changed

18 files changed

+98
-109
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ before_script:
5353
- "export DISPLAY=:99.0"
5454
- "sh -e /etc/init.d/xvfb start"
5555
- mkdir -p $LOGS_DIR
56+
- npm run tslint
5657

5758

5859
script:
@@ -62,4 +63,3 @@ cache:
6263
directories:
6364
- node_modules
6465
- $HOME/.pub-cache
65-

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dartanalyzer": "cd dist/dart && pub install && cd ../.. && ts-node scripts/ci/dart_analyzer",
1313
"demo-app": "cd src && ng serve",
1414
"test": "karma start test/karma.conf.js",
15+
"tslint" : "tslint -c tslint.json 'src/**/*.ts'",
1516
"typings": "typings install --ambient"
1617
},
1718
"version": "2.0.0-alpha.0",
@@ -53,7 +54,7 @@
5354
"symlink-or-copy": "^1.0.1",
5455
"ts-node": "^0.5.5",
5556
"ts2dart": "^0.7.27",
56-
"tslint": "^3.2.2",
57+
"tslint": "^3.5.0",
5758
"typescript": "^1.7.5",
5859
"typings": "^0.6.8",
5960
"which": "^1.2.4"

src/components/button/button.spec.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import {
22
inject,
3-
injectAsync,
4-
ComponentFixture,
5-
TestComponentBuilder,
6-
beforeEachProviders,
3+
TestComponentBuilder
74
} from 'angular2/testing';
85
import {
96
it,
@@ -13,22 +10,21 @@ import {
1310
expect,
1411
beforeEach,
1512
} from '../../core/facade/testing';
16-
import {provide, Component, DebugElement} from 'angular2/core';
13+
import {Component} from 'angular2/core';
1714
import {By} from 'angular2/platform/browser';
1815

1916
import {MdButton, MdAnchor} from './button';
20-
import {AsyncTestFn, FunctionWithParamTokens} from 'angular2/testing';
2117

2218
export function main() {
2319
describe('MdButton', () => {
2420
let builder: TestComponentBuilder;
2521

26-
beforeEach(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
22+
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
2723
builder = tcb;
2824
}));
2925

3026
// General button tests
31-
it('should apply class based on color attribute', (done:() => void) => {
27+
it('should apply class based on color attribute', (done: () => void) => {
3228
return builder.createAsync(TestApp).then((fixture) => {
3329
let testComponent = fixture.debugElement.componentInstance;
3430
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
@@ -49,7 +45,7 @@ export function main() {
4945

5046
// Regular button tests
5147
describe('button[md-button]', () => {
52-
it('should handle a click on the button', (done:() => void) => {
48+
it('should handle a click on the button', (done: () => void) => {
5349
return builder.createAsync(TestApp).then((fixture) => {
5450
let testComponent = fixture.debugElement.componentInstance;
5551
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
@@ -60,7 +56,7 @@ export function main() {
6056
});
6157
});
6258

63-
it('should not increment if disabled', (done:() => void) => {
59+
it('should not increment if disabled', (done: () => void) => {
6460
return builder.createAsync(TestApp).then((fixture) => {
6561
let testComponent = fixture.debugElement.componentInstance;
6662
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
@@ -79,7 +75,7 @@ export function main() {
7975

8076
// Anchor button tests
8177
describe('a[md-button]', () => {
82-
it('should not redirect if disabled',(done:() => void)=>{
78+
it('should not redirect if disabled', (done: () => void) => {
8379
return builder.createAsync(TestApp).then((fixture) => {
8480
let testComponent = fixture.debugElement.componentInstance;
8581
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
@@ -93,7 +89,7 @@ export function main() {
9389
});
9490
});
9591

96-
it('should remove tabindex if disabled', (done:() => void) => {
92+
it('should remove tabindex if disabled', (done: () => void) => {
9793
return builder.createAsync(TestApp).then((fixture) => {
9894
let testComponent = fixture.debugElement.componentInstance;
9995
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
@@ -106,7 +102,7 @@ export function main() {
106102
});
107103
});
108104

109-
it('should add aria-disabled attribute if disabled', (done:() => void) => {
105+
it('should add aria-disabled attribute if disabled', (done: () => void) => {
110106
return builder.createAsync(TestApp).then((fixture) => {
111107
let testComponent = fixture.debugElement.componentInstance;
112108
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
@@ -124,16 +120,12 @@ export function main() {
124120
});
125121
}
126122

127-
/** Shortcut function to use instead of `injectAsync` for less boilerplate on each `it`. */
128-
function testAsync(fn: Function): FunctionWithParamTokens {
129-
return injectAsync([], fn);
130-
}
131-
132123
/** Test component that contains an MdButton. */
133124
@Component({
134125
selector: 'test-app',
135126
template: `
136-
<button md-button type="button" (click)="increment()" [disabled]="isDisabled" [color]="buttonColor">
127+
<button md-button type="button" (click)="increment()"
128+
[disabled]="isDisabled" [color]="buttonColor">
137129
Go
138130
</button>
139131
<a href="http://www.google.com" md-button [disabled]="isDisabled" [color]="buttonColor">Link</a>
@@ -148,5 +140,3 @@ class TestApp {
148140
this.clickCount++;
149141
}
150142
}
151-
152-

src/components/button/button.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class MdButton {
3737
/** Whether a mousedown has occurred on this element in the last 100ms. */
3838
isMouseDown: boolean = false;
3939

40-
setClassList() {return `md-${this.color}`;}
40+
setClassList() { return `md-${this.color}`; }
4141

4242
setMousedown() {
4343
// We only *show* the focus style when focus has come to the button via the keyboard.
@@ -75,7 +75,7 @@ export class MdAnchor extends MdButton {
7575
disabled_: boolean = null;
7676

7777
@HostBinding('tabIndex')
78-
get tabIndex():number {
78+
get tabIndex(): number {
7979
return this.disabled ? -1 : 0;
8080
}
8181

src/components/card/card.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {CONST_EXPR} from 'angular2/src/facade/lang';
55
66
<md-card> is a basic content container component that adds the styles of a material design card.
77
8-
While you can use this component alone, it also provides a number of preset styles for common card sections, including:
8+
While you can use this component alone,
9+
it also provides a number of preset styles for common card sections, including:
910
- md-card-title
1011
- md-card-subtitle
1112
- md-card-content
@@ -29,10 +30,11 @@ While you can use this component alone, it also provides a number of preset styl
2930
export class MdCard {}
3031

3132

32-
/* The following components don't have any behavior. They simply use content projection to wrap user content
33-
for flex layout purposes in <md-card> (and thus allow a cleaner, boilerplate-free API).
33+
/* The following components don't have any behavior.
34+
They simply use content projection to wrap user content
35+
for flex layout purposes in <md-card> (and thus allow a cleaner, boilerplate-free API).
36+
3437
35-
3638
<md-card-header> is a component intended to be used within the <md-card> component.
3739
It adds styles for a preset header section (i.e. a title, subtitle, and avatar layout).
3840
@@ -70,4 +72,3 @@ TODO(kara): update link to demo site when it exists
7072
export class MdCardTitleGroup {}
7173

7274
export const MD_CARD_DIRECTIVES: any[] = CONST_EXPR([MdCard, MdCardHeader, MdCardTitleGroup]);
73-

src/components/progress-circle/progress_circle.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import {
88
beforeEach,
99
} from '../../core/facade/testing';
1010
import {Component, DebugElement} from 'angular2/core';
11-
import {By} from 'angular2/platform/browser'
11+
import {By} from 'angular2/platform/browser';
1212
import {MdProgressCircle} from './progress_circle';
1313

1414

1515
export function main() {
1616
describe('MdProgressCircular', () => {
17-
let builder:TestComponentBuilder;
17+
let builder: TestComponentBuilder;
1818

19-
beforeEach(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
19+
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
2020
builder = tcb;
2121
}));
2222

23-
it('should apply a mode of "determinate" if no mode is provided.', (done:() => void) => {
23+
it('should apply a mode of "determinate" if no mode is provided.', (done: () => void) => {
2424
builder
2525
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')
2626
.createAsync(TestApp)
@@ -32,7 +32,7 @@ export function main() {
3232
});
3333
});
3434

35-
it('should apply a mode of "determinate" if an invalid mode is provided.', (done:() => void) => {
35+
it('should apply mode of "determinate" if an invalid mode is provided.', (done: () => void) => {
3636
builder
3737
.overrideTemplate(TestApp, '<md-progress-circle mode="spinny"></md-progress-circle>')
3838
.createAsync(TestApp)
@@ -44,7 +44,7 @@ export function main() {
4444
});
4545
});
4646

47-
it('should not modify the mode if a valid mode is provided.', (done:() => void) => {
47+
it('should not modify the mode if a valid mode is provided.', (done: () => void) => {
4848
builder
4949
.overrideTemplate(TestApp, '<md-progress-circle mode="indeterminate"></md-progress-circle>')
5050
.createAsync(TestApp)
@@ -56,7 +56,7 @@ export function main() {
5656
});
5757
});
5858

59-
it('should define a default value for the value attribute', (done:() => void) => {
59+
it('should define a default value for the value attribute', (done: () => void) => {
6060
builder
6161
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')
6262
.createAsync(TestApp)
@@ -68,7 +68,7 @@ export function main() {
6868
});
6969
});
7070

71-
it('should clamp the value of the progress between 0 and 100', (done:() => void) => {
71+
it('should clamp the value of the progress between 0 and 100', (done: () => void) => {
7272
builder
7373
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')
7474
.createAsync(TestApp)
@@ -104,4 +104,4 @@ function getChildDebugElement(parent: DebugElement, selector: string): DebugElem
104104
directives: [MdProgressCircle],
105105
template: '',
106106
})
107-
class TestApp {}
107+
class TestApp {}

src/components/progress-circle/progress_circle.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import {
2-
Attribute,
32
Component,
43
ChangeDetectionStrategy,
5-
ElementRef,
64
HostBinding,
7-
Input,
8-
ViewEncapsulation,
5+
Input
96
} from 'angular2/core';
107
import {isPresent, CONST} from 'angular2/src/facade/lang';
118
import {Math} from 'angular2/src/facade/math';

src/components/sidenav/sidenav.spec.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ import {
2424
} from 'angular2/core';
2525

2626
import {By} from 'angular2/platform/browser';
27-
import {Predicate} from 'angular2/src/facade/collection';
28-
import {PromiseWrapper} from 'angular2/src/facade/promise';
29-
import {TimerWrapper} from 'angular2/src/facade/async';
3027
import {MdSidenav, MdSidenavLayout, MD_SIDENAV_DIRECTIVES} from './sidenav';
3128

3229

@@ -38,7 +35,8 @@ function fakeAsyncAdaptor(fn: () => void) {
3835
/**
3936
* Create a ComponentFixture from the builder. This takes a template and a style for sidenav.
4037
*/
41-
function createFixture(builder: TestComponentBuilder, template: string, style: string): ComponentFixture {
38+
function createFixture(builder: TestComponentBuilder,
39+
template: string, style: string): ComponentFixture {
4240
let fixture: ComponentFixture = null;
4341
// Remove the styles (which remove the animations/transitions).
4442
builder
@@ -71,10 +69,11 @@ export function main() {
7169
let builder: TestComponentBuilder;
7270

7371
/**
74-
* We need to get the template and styles for the sidenav in an Async test. FakeAsync would block indefinitely
75-
* on the XHR if we were to create the component async-ly. See https://github.com/angular/angular/issues/5601.
76-
* We do some style verification so styles have to match. But we remove the transitions so we only
77-
* set the regular `sidenav.css` styling.
72+
* We need to get the template and styles for the sidenav in an Async test.
73+
* FakeAsync would block indefinitely on the XHR if we were to create the component async-ly.
74+
* See https://github.com/angular/angular/issues/5601.
75+
* We do some style verification so styles have to match.
76+
* But we remove the transitions so we only set the regular `sidenav.css` styling.
7877
*/
7978
beforeEach(injectAsync([TestComponentBuilder, XHR], (tcb: TestComponentBuilder, xhr: XHR) => {
8079
builder = tcb;
@@ -111,7 +110,8 @@ export function main() {
111110
let sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
112111
let sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
113112
expect(getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('visible');
114-
expect(getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('visible');
113+
expect(getComputedStyle(sidenavBackdropElement.nativeElement).visibility)
114+
.toEqual('visible');
115115

116116
// Close it.
117117
let closeButtonElement = fixture.debugElement.query(By.css('.close'));
@@ -136,13 +136,14 @@ export function main() {
136136
expect(getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('hidden');
137137
}));
138138

139-
it('open() and close() return a promise that resolves after the animation ended', fakeAsyncAdaptor(() => {
139+
it('open/close() return a promise that resolves after animation end', fakeAsyncAdaptor(() => {
140140
let fixture = createFixture(builder, template, style);
141-
let sidenav: MdSidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
142-
let called: boolean = false;
141+
let sidenav: MdSidenav = fixture.debugElement
142+
.query(By.directive(MdSidenav)).componentInstance;
143+
let called = false;
143144

144145
sidenav.open().then((_: any) => {
145-
called = true
146+
called = true;
146147
});
147148

148149
expect(called).toBe(false);
@@ -152,7 +153,7 @@ export function main() {
152153

153154
called = false;
154155
sidenav.close().then((_: any) => {
155-
called = true
156+
called = true;
156157
});
157158

158159
expect(called).toBe(false);
@@ -164,7 +165,8 @@ export function main() {
164165

165166
it('open/close() twice returns the same promise', fakeAsyncAdaptor(() => {
166167
let fixture = createFixture(builder, template, style);
167-
let sidenav: MdSidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
168+
let sidenav: MdSidenav = fixture.debugElement
169+
.query(By.directive(MdSidenav)).componentInstance;
168170

169171
let promise = sidenav.open();
170172
expect(sidenav.open()).toBe(promise);
@@ -178,12 +180,13 @@ export function main() {
178180

179181
it('open() then close() cancel animations when called too fast', fakeAsyncAdaptor(() => {
180182
let fixture = createFixture(builder, template, style);
181-
let sidenav: MdSidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
183+
let sidenav: MdSidenav = fixture.debugElement
184+
.query(By.directive(MdSidenav)).componentInstance;
182185

183186
let closePromise: Promise<void>;
184-
let openCalled: boolean = false;
185-
let openCancelled: boolean = false;
186-
let closeCalled: boolean = false;
187+
let openCalled = false;
188+
let openCancelled = false;
189+
let closeCalled = false;
187190

188191
sidenav.open().then((_: any) => { openCalled = true; }, () => { openCancelled = true; });
189192

@@ -201,12 +204,12 @@ export function main() {
201204

202205
it('close() then open() cancel animations when called too fast', fakeAsyncAdaptor(() => {
203206
let fixture = createFixture(builder, template, style);
204-
let sidenav: MdSidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
207+
let sidenav: MdSidenav = fixture.debugElement
208+
.query(By.directive(MdSidenav)).componentInstance;
205209

206-
let openPromise: Promise<void>;
207-
let closeCalled: boolean = false;
208-
let closeCancelled: boolean = false;
209-
let openCalled: boolean = false;
210+
let closeCalled = false;
211+
let closeCancelled = false;
212+
let openCalled = false;
210213

211214
// First, open the sidenav completely.
212215
sidenav.open();

0 commit comments

Comments
 (0)