Skip to content

Commit f177345

Browse files
committed
fix: make material work with noUnusedParameters
* Recently Angular core fixed their `noUnusedParameters` warnings in angular/angular#15532 * When using Angular with Material and the users has `noUnusedParameters` enabled the library will be checked and will throw. Fixes angular#4443
1 parent 536add3 commit f177345

27 files changed

+50
-60
lines changed

src/demo-app/dialog/dialog-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class DialogDemo {
3838
// Possible useful example for the open and closeAll events.
3939
// Adding a class to the body if a dialog opens and
4040
// removing it after all open dialogs are closed
41-
dialog.afterOpen.subscribe((ref: MdDialogRef<any>) => {
41+
dialog.afterOpen.subscribe(() => {
4242
if (!doc.body.classList.contains('no-scroll')) {
4343
doc.body.classList.add('no-scroll');
4444
}

src/demo-app/style/style-demo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, Renderer2} from '@angular/core';
1+
import {Component} from '@angular/core';
22
import {FocusOriginMonitor} from '@angular/material';
33

44

@@ -9,5 +9,5 @@ import {FocusOriginMonitor} from '@angular/material';
99
styleUrls: ['style-demo.css'],
1010
})
1111
export class StyleDemo {
12-
constructor(public renderer: Renderer2, public fom: FocusOriginMonitor) {}
12+
constructor(public fom: FocusOriginMonitor) {}
1313
}

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
9292
private _manuallyFloatingPlaceholder = false;
9393

9494
/** View -> model callback called when value changes */
95-
_onChange = (value: any) => {};
95+
_onChange: (value: any) => void = () => {};
9696

9797
/** View -> model callback called when autocomplete has been touched */
9898
_onTouched = () => {};

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('MdAutocomplete', () => {
7272
}},
7373
{provide: Dir, useFactory: () => ({value: dir})},
7474
{provide: ScrollDispatcher, useFactory: () => {
75-
return {scrolled: (delay: number, callback: () => any) => {
75+
return {scrolled: (_delay: number, callback: () => any) => {
7676
return scrolledSubject.asObservable().subscribe(callback);
7777
}};
7878
}}

src/lib/button-toggle/button-toggle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor
8080
* The method to be called in order to update ngModel.
8181
* Now `ngModel` binding is not supported in multiple selection mode.
8282
*/
83-
private _controlValueAccessorChangeFn: (value: any) => void = (value) => {};
83+
private _controlValueAccessorChangeFn: (value: any) => void = () => {};
8484

8585
/** onTouch function registered via registerOnTouch (ControlValueAccessor). */
8686
onTouched: () => any = () => {};

src/lib/checkbox/checkbox.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,8 @@ class SingleCheckbox {
814814
checkboxColor: string = 'primary';
815815
checkboxValue: string = 'single_checkbox';
816816

817-
onCheckboxClick(event: Event) {}
818-
onCheckboxChange(event: MdCheckboxChange) {}
817+
onCheckboxClick: (event?: Event) => void = () => {};
818+
onCheckboxChange: (event?: MdCheckboxChange) => void = () => {};
819819
}
820820

821821
/** Simple component for testing an MdCheckbox with ngModel. */

src/lib/checkbox/checkbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class MdCheckbox extends _MdCheckboxMixinBase
186186

187187
private _indeterminate: boolean = false;
188188

189-
private _controlValueAccessorChangeFn: (value: any) => void = (value) => {};
189+
private _controlValueAccessorChangeFn: (value: any) => void = () => {};
190190

191191
/** Reference to the focused state ripple. */
192192
private _focusRipple: RippleRef;

src/lib/chips/chip-list.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,8 @@ describe('MdChipList', () => {
236236
class StaticChipList {
237237
name: string = 'Test';
238238
selectable: boolean = true;
239-
remove: Number;
239+
remove: number;
240240

241-
chipSelect(index: Number) {
242-
}
243-
244-
chipDeselect(index: Number) {
245-
}
241+
chipSelect: (index?: number) => void = () => {};
242+
chipDeselect: (index?: number) => void = () => {};
246243
}

src/lib/chips/chip.spec.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,10 @@ class SingleChip {
135135
selected: boolean = false;
136136
shouldShow: boolean = true;
137137

138-
chipFocus(event: MdChipEvent) {
139-
}
140-
141-
chipDestroy(event: MdChipEvent) {
142-
}
143-
144-
chipSelect(event: MdChipEvent) {
145-
}
146-
147-
chipDeselect(event: MdChipEvent) {
148-
}
138+
chipFocus: (event?: MdChipEvent) => void = () => {};
139+
chipDestroy: (event?: MdChipEvent) => void = () => {};
140+
chipSelect: (event?: MdChipEvent) => void = () => {};
141+
chipDeselect: (event?: MdChipEvent) => void = () => {};
149142
}
150143

151144
@Component({

src/lib/core/data-table/data-table.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ function getHeaderCells(tableElement: Element): Element[] {
275275
}
276276

277277
const tableCustomMatchers: jasmine.CustomMatcherFactories = {
278-
toMatchTableContent: function(util, customEqualityTesters) {
278+
toMatchTableContent: () => {
279279
return {
280280
compare: function (tableElement: Element, expectedTableContent: any[]) {
281281
const missedExpectations = [];

src/lib/core/datetime/native-date-adapter.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ const DEFAULT_DAY_OF_WEEK_NAMES = {
3131

3232
/** Creates an array and fills it with values. */
3333
function range<T>(length: number, valueFunction: (index: number) => T): T[] {
34-
return Array.apply(null, Array(length)).map((v: undefined, i: number) => valueFunction(i));
34+
const valuesArray = Array(length);
35+
for (let i = 0; i < length; i++) {
36+
valuesArray[i] = valueFunction(i);
37+
}
38+
return valuesArray;
3539
}
3640

3741

@@ -123,7 +127,7 @@ export class NativeDateAdapter extends DateAdapter<Date> {
123127
return new Date();
124128
}
125129

126-
parse(value: any, parseFormat: Object): Date | null {
130+
parse(value: any): Date | null {
127131
// We have no way using the native JS Date to set the parse format or locale, so we ignore these
128132
// parameters.
129133
let timestamp = typeof value == 'number' ? value : Date.parse(value);

src/lib/core/overlay/scroll/close-scroll-strategy.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
OverlayState,
99
OverlayRef,
1010
OverlayModule,
11-
ScrollStrategy,
1211
ScrollDispatcher,
1312
} from '../../core';
1413

@@ -23,7 +22,7 @@ describe('CloseScrollStrategy', () => {
2322
imports: [OverlayModule, PortalModule, OverlayTestModule],
2423
providers: [
2524
{provide: ScrollDispatcher, useFactory: () => {
26-
return {scrolled: (delay: number, callback: () => any) => {
25+
return {scrolled: (_delay: number, callback: () => any) => {
2726
return scrolledSubject.asObservable().subscribe(callback);
2827
}};
2928
}}

src/lib/core/overlay/scroll/reposition-scroll-strategy.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
OverlayState,
99
OverlayRef,
1010
OverlayModule,
11-
ScrollStrategy,
1211
ScrollDispatcher,
1312
} from '../../core';
1413

@@ -23,7 +22,7 @@ describe('RepositionScrollStrategy', () => {
2322
imports: [OverlayModule, PortalModule, OverlayTestModule],
2423
providers: [
2524
{provide: ScrollDispatcher, useFactory: () => {
26-
return {scrolled: (delay: number, callback: () => any) => {
25+
return {scrolled: (_delay: number, callback: () => any) => {
2726
return scrolledSubject.asObservable().subscribe(callback);
2827
}};
2928
}}

src/lib/core/overlay/scroll/scroll-dispatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class ScrollDispatcher {
105105
getScrollContainers(elementRef: ElementRef): Scrollable[] {
106106
const scrollingContainers: Scrollable[] = [];
107107

108-
this.scrollableReferences.forEach((subscription: Subscription, scrollable: Scrollable) => {
108+
this.scrollableReferences.forEach((_subscription: Subscription, scrollable: Scrollable) => {
109109
if (this.scrollableContainsElement(scrollable, elementRef)) {
110110
scrollingContainers.push(scrollable);
111111
}

src/lib/core/style/focus-origin-monitor.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ class PlainButton {
464464
template: `<button cdkMonitorElementFocus (cdkFocusChange)="focusChanged($event)"></button>`
465465
})
466466
class ButtonWithFocusClasses {
467-
focusChanged(origin: FocusOrigin) {}
467+
focusChanged(_origin: FocusOrigin) {}
468468
}
469469

470470

src/lib/core/testing/jasmine-matchers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
* Collection of useful custom jasmine matchers for tests.
33
*/
44
export const customMatchers: jasmine.CustomMatcherFactories = {
5-
toBeRole: function(util: jasmine.MatchersUtil,
6-
customEqualityTesters: jasmine.CustomEqualityTester[]) {
5+
toBeRole: () => {
76
return {
87
compare: function (element: Element, expectedRole: string) {
98
const result: jasmine.CustomMatcherResult = {pass: false};

src/lib/core/testing/type-in-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {dispatchFakeEvent} from './dispatch-events';
66
* @param value Value to be set on the input.
77
* @param element Element onto which to set the value.
88
*/
9-
export function typeInElement(value: string, element: HTMLInputElement, autoFocus = true) {
9+
export function typeInElement(value: string, element: HTMLInputElement) {
1010
element.focus();
1111
element.value = value;
1212
dispatchFakeEvent(element, 'input');

src/lib/datepicker/datepicker-input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
121121

122122
_onTouched = () => {};
123123

124-
private _cvaOnChange = (value: any) => {};
124+
private _cvaOnChange: (value: any) => void = () => {};
125125

126126
private _validatorOnChange = () => {};
127127

src/lib/grid-list/tile-styler.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {TileCoordinator} from './tile-coordinator';
66
* Tile Coordinator.
77
* @docs-private
88
*/
9-
export class TileStyler {
9+
export abstract class TileStyler {
1010
_gutterSize: string;
1111
_rows: number = 0;
1212
_rowspan: number = 0;
@@ -122,11 +122,12 @@ export class TileStyler {
122122
* This method will be implemented by each type of TileStyler.
123123
* @docs-private
124124
*/
125-
setRowStyles(tile: MdGridTile, rowIndex: number, percentWidth: number, gutterWidth: number) {}
125+
abstract setRowStyles(tile: MdGridTile, rowIndex: number, percentWidth: number,
126+
gutterWidth: number);
126127

127128
/**
128129
* Calculates the computed height and returns the correct style property to set.
129-
* This method will be implemented by each type of TileStyler.
130+
* This method can be implemented by each type of TileStyler.
130131
* @docs-private
131132
*/
132133
getComputedHeight(): [string, string] { return null; }
@@ -147,8 +148,7 @@ export class FixedTileStyler extends TileStyler {
147148
this.fixedRowHeight = normalizeUnits(this.fixedRowHeight);
148149
}
149150

150-
setRowStyles(tile: MdGridTile, rowIndex: number, percentWidth: number,
151-
gutterWidth: number): void {
151+
setRowStyles(tile: MdGridTile, rowIndex: number): void {
152152
tile._setStyle('top', this.getTilePosition(this.fixedRowHeight, rowIndex));
153153
tile._setStyle('height', calc(this.getTileSize(this.fixedRowHeight, tile.rowspan)));
154154
}
@@ -215,8 +215,7 @@ export class RatioTileStyler extends TileStyler {
215215
*/
216216
export class FitTileStyler extends TileStyler {
217217

218-
setRowStyles(tile: MdGridTile, rowIndex: number, percentWidth: number,
219-
gutterWidth: number): void {
218+
setRowStyles(tile: MdGridTile, rowIndex: number): void {
220219
// Percent of the available vertical space that one row takes up.
221220
let percentHeightPerTile = 100 / this._rowspan;
222221

@@ -229,6 +228,7 @@ export class FitTileStyler extends TileStyler {
229228
tile._setStyle('top', this.getTilePosition(baseTileHeight, rowIndex));
230229
tile._setStyle('height', calc(this.getTileSize(baseTileHeight, tile.rowspan)));
231230
}
231+
232232
}
233233

234234

src/lib/icon/icon-registry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class MdIconRegistry {
245245
.filter(iconSetConfig => !iconSetConfig.svgElement)
246246
.map(iconSetConfig =>
247247
this._loadSvgIconSetFromConfig(iconSetConfig)
248-
.catch((err: any, caught: Observable<SVGElement>): Observable<SVGElement> => {
248+
.catch((err: any): Observable<SVGElement> => {
249249
let url =
250250
this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, iconSetConfig.url);
251251

@@ -263,7 +263,7 @@ export class MdIconRegistry {
263263
// Fetch all the icon set URLs. When the requests complete, every IconSet should have a
264264
// cached SVG element (unless the request failed), and we can check again for the icon.
265265
return Observable.forkJoin(iconSetFetchRequests)
266-
.map((ignoredResults: any) => {
266+
.map(() => {
267267
const foundIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs);
268268
if (!foundIcon) {
269269
throw getMdIconNameNotFoundError(name);

src/lib/radio/radio.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('MdRadio', () => {
143143
expect(radioInstances[0].checked).toBe(false);
144144

145145
let spies = radioInstances
146-
.map((value, index) => jasmine.createSpy(`onChangeSpy ${index}`));
146+
.map((radio, index) => jasmine.createSpy(`onChangeSpy ${index} for ${radio.name}`));
147147

148148
spies.forEach((spy, index) => radioInstances[index].change.subscribe(spy));
149149

src/lib/radio/radio.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class MdRadioGroup extends _MdRadioGroupMixinBase
9595
private _disabled: boolean = false;
9696

9797
/** The method to be called in order to update ngModel */
98-
_controlValueAccessorChangeFn: (value: any) => void = (value) => {};
98+
_controlValueAccessorChangeFn: (value: any) => void = () => {};
9999

100100
/**
101101
* onTouch function registered via registerOnTouch (ControlValueAccessor).

src/lib/select/select.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('MdSelect', () => {
7474
}},
7575
{provide: Dir, useFactory: () => dir = { value: 'ltr' }},
7676
{provide: ScrollDispatcher, useFactory: () => {
77-
return {scrolled: (delay: number, callback: () => any) => {
77+
return {scrolled: (_delay: number, callback: () => any) => {
7878
return scrolledSubject.asObservable().subscribe(callback);
7979
}};
8080
}}
@@ -2324,9 +2324,9 @@ class SelectInitWithoutOptions {
23242324
class CustomSelectAccessor implements ControlValueAccessor {
23252325
@ViewChild(MdSelect) select: MdSelect;
23262326

2327-
writeValue(val: any): void {}
2328-
registerOnChange(fn: (val: any) => void): void {}
2329-
registerOnTouched(fn: Function): void {}
2327+
writeValue: (value?: any) => void = () => {};
2328+
registerOnChange: (changeFn?: (value: any) => void) => void = () => {};
2329+
registerOnTouched: (touchedFn?: () => void) => void = () => {};
23302330
}
23312331

23322332
@Component({

src/lib/select/select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
186186
_selectedValueWidth: number;
187187

188188
/** View -> model callback called when value changes */
189-
_onChange = (value: any) => {};
189+
_onChange: (value: any) => void = () => {};
190190

191191
/** View -> model callback called when select has been touched */
192192
_onTouched = () => {};

src/lib/slide-toggle/slide-toggle.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,8 @@ class SlideToggleTestApp {
685685
lastEvent: MdSlideToggleChange;
686686
labelPosition: string;
687687

688-
onSlideClick(event: Event) {}
689-
onSlideChange(event: MdSlideToggleChange) {
690-
this.lastEvent = event;
691-
}
688+
onSlideClick: (event?: Event) => void = () => {};
689+
onSlideChange = (event: MdSlideToggleChange) => this.lastEvent = event;
692690
}
693691

694692

src/lib/snack-bar/snack-bar-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
9999
}
100100

101101
/** Attach a template portal as content to this snack bar container. */
102-
attachTemplatePortal(portal: TemplatePortal): Map<string, any> {
102+
attachTemplatePortal(): Map<string, any> {
103103
throw new Error('Not yet implemented');
104104
}
105105

src/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"experimentalDecorators": true,
66
"module": "es2015",
77
"moduleResolution": "node",
8+
"noUnusedParameters": true,
89
"outDir": "../dist/packages/all",
910
"sourceMap": true,
1011
"inlineSources": true,

0 commit comments

Comments
 (0)