From 4b98f21bd25746fbfaeadae8db22e2a0acbb1d66 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 8 Jun 2017 23:33:03 +0200 Subject: [PATCH] fix: make material work with noUnusedParameters (#4946) * Recently Angular core fixed their `noUnusedParameters` warnings in https://github.com/angular/angular/issues/15532 * When using Angular with Material and the users has `noUnusedParameters` enabled the library will be checked and will throw. Fixes #4443 --- src/demo-app/dialog/dialog-demo.ts | 2 +- src/demo-app/style/style-demo.ts | 4 ++-- src/lib/autocomplete/autocomplete-trigger.ts | 2 +- src/lib/autocomplete/autocomplete.spec.ts | 2 +- src/lib/button-toggle/button-toggle.ts | 2 +- src/lib/checkbox/checkbox.spec.ts | 4 ++-- src/lib/checkbox/checkbox.ts | 2 +- src/lib/chips/chip-list.spec.ts | 9 +++------ src/lib/chips/chip.spec.ts | 15 ++++----------- src/lib/core/data-table/data-table.spec.ts | 2 +- src/lib/core/datetime/native-date-adapter.ts | 8 ++++++-- .../overlay/scroll/close-scroll-strategy.spec.ts | 3 +-- .../scroll/reposition-scroll-strategy.spec.ts | 3 +-- src/lib/core/overlay/scroll/scroll-dispatcher.ts | 2 +- src/lib/core/style/focus-origin-monitor.spec.ts | 2 +- src/lib/core/testing/jasmine-matchers.ts | 3 +-- src/lib/core/testing/type-in-element.ts | 2 +- src/lib/datepicker/datepicker-input.ts | 2 +- src/lib/grid-list/tile-styler.ts | 14 +++++++------- src/lib/icon/icon-registry.ts | 4 ++-- src/lib/radio/radio.spec.ts | 2 +- src/lib/radio/radio.ts | 2 +- src/lib/select/select.spec.ts | 8 ++++---- src/lib/select/select.ts | 2 +- src/lib/slide-toggle/slide-toggle.spec.ts | 6 ++---- src/lib/snack-bar/snack-bar-container.ts | 2 +- src/tsconfig.json | 1 + 27 files changed, 50 insertions(+), 60 deletions(-) diff --git a/src/demo-app/dialog/dialog-demo.ts b/src/demo-app/dialog/dialog-demo.ts index 5a572e2b781..06e01d2838e 100644 --- a/src/demo-app/dialog/dialog-demo.ts +++ b/src/demo-app/dialog/dialog-demo.ts @@ -38,7 +38,7 @@ export class DialogDemo { // Possible useful example for the open and closeAll events. // Adding a class to the body if a dialog opens and // removing it after all open dialogs are closed - dialog.afterOpen.subscribe((ref: MdDialogRef) => { + dialog.afterOpen.subscribe(() => { if (!doc.body.classList.contains('no-scroll')) { doc.body.classList.add('no-scroll'); } diff --git a/src/demo-app/style/style-demo.ts b/src/demo-app/style/style-demo.ts index 6d4db280823..f66c1bded23 100644 --- a/src/demo-app/style/style-demo.ts +++ b/src/demo-app/style/style-demo.ts @@ -1,4 +1,4 @@ -import {Component, Renderer2} from '@angular/core'; +import {Component} from '@angular/core'; import {FocusOriginMonitor} from '@angular/material'; @@ -9,5 +9,5 @@ import {FocusOriginMonitor} from '@angular/material'; styleUrls: ['style-demo.css'], }) export class StyleDemo { - constructor(public renderer: Renderer2, public fom: FocusOriginMonitor) {} + constructor(public fom: FocusOriginMonitor) {} } diff --git a/src/lib/autocomplete/autocomplete-trigger.ts b/src/lib/autocomplete/autocomplete-trigger.ts index 30e7ab507ec..4b379c859dd 100644 --- a/src/lib/autocomplete/autocomplete-trigger.ts +++ b/src/lib/autocomplete/autocomplete-trigger.ts @@ -92,7 +92,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy { private _manuallyFloatingPlaceholder = false; /** View -> model callback called when value changes */ - _onChange = (value: any) => {}; + _onChange: (value: any) => void = () => {}; /** View -> model callback called when autocomplete has been touched */ _onTouched = () => {}; diff --git a/src/lib/autocomplete/autocomplete.spec.ts b/src/lib/autocomplete/autocomplete.spec.ts index 17fdf917a32..f3e730346d9 100644 --- a/src/lib/autocomplete/autocomplete.spec.ts +++ b/src/lib/autocomplete/autocomplete.spec.ts @@ -72,7 +72,7 @@ describe('MdAutocomplete', () => { }}, {provide: Dir, useFactory: () => ({value: dir})}, {provide: ScrollDispatcher, useFactory: () => { - return {scrolled: (delay: number, callback: () => any) => { + return {scrolled: (_delay: number, callback: () => any) => { return scrolledSubject.asObservable().subscribe(callback); }}; }} diff --git a/src/lib/button-toggle/button-toggle.ts b/src/lib/button-toggle/button-toggle.ts index d704dec3c9e..a1f7ba503a3 100644 --- a/src/lib/button-toggle/button-toggle.ts +++ b/src/lib/button-toggle/button-toggle.ts @@ -80,7 +80,7 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor * The method to be called in order to update ngModel. * Now `ngModel` binding is not supported in multiple selection mode. */ - private _controlValueAccessorChangeFn: (value: any) => void = (value) => {}; + private _controlValueAccessorChangeFn: (value: any) => void = () => {}; /** onTouch function registered via registerOnTouch (ControlValueAccessor). */ onTouched: () => any = () => {}; diff --git a/src/lib/checkbox/checkbox.spec.ts b/src/lib/checkbox/checkbox.spec.ts index af53a375e49..110fc451473 100644 --- a/src/lib/checkbox/checkbox.spec.ts +++ b/src/lib/checkbox/checkbox.spec.ts @@ -851,8 +851,8 @@ class SingleCheckbox { checkboxColor: string = 'primary'; checkboxValue: string = 'single_checkbox'; - onCheckboxClick(event: Event) {} - onCheckboxChange(event: MdCheckboxChange) {} + onCheckboxClick: (event?: Event) => void = () => {}; + onCheckboxChange: (event?: MdCheckboxChange) => void = () => {}; } /** Simple component for testing an MdCheckbox with ngModel. */ diff --git a/src/lib/checkbox/checkbox.ts b/src/lib/checkbox/checkbox.ts index a4c764634ce..b3ad5672682 100644 --- a/src/lib/checkbox/checkbox.ts +++ b/src/lib/checkbox/checkbox.ts @@ -178,7 +178,7 @@ export class MdCheckbox extends _MdCheckboxMixinBase private _indeterminate: boolean = false; - private _controlValueAccessorChangeFn: (value: any) => void = (value) => {}; + private _controlValueAccessorChangeFn: (value: any) => void = () => {}; /** Reference to the focused state ripple. */ private _focusRipple: RippleRef; diff --git a/src/lib/chips/chip-list.spec.ts b/src/lib/chips/chip-list.spec.ts index 6664d3c88c0..4c63a461387 100644 --- a/src/lib/chips/chip-list.spec.ts +++ b/src/lib/chips/chip-list.spec.ts @@ -236,11 +236,8 @@ describe('MdChipList', () => { class StaticChipList { name: string = 'Test'; selectable: boolean = true; - remove: Number; + remove: number; - chipSelect(index: Number) { - } - - chipDeselect(index: Number) { - } + chipSelect: (index?: number) => void = () => {}; + chipDeselect: (index?: number) => void = () => {}; } diff --git a/src/lib/chips/chip.spec.ts b/src/lib/chips/chip.spec.ts index 8ed9bc736ee..de2f27dad76 100644 --- a/src/lib/chips/chip.spec.ts +++ b/src/lib/chips/chip.spec.ts @@ -135,17 +135,10 @@ class SingleChip { selected: boolean = false; shouldShow: boolean = true; - chipFocus(event: MdChipEvent) { - } - - chipDestroy(event: MdChipEvent) { - } - - chipSelect(event: MdChipEvent) { - } - - chipDeselect(event: MdChipEvent) { - } + chipFocus: (event?: MdChipEvent) => void = () => {}; + chipDestroy: (event?: MdChipEvent) => void = () => {}; + chipSelect: (event?: MdChipEvent) => void = () => {}; + chipDeselect: (event?: MdChipEvent) => void = () => {}; } @Component({ diff --git a/src/lib/core/data-table/data-table.spec.ts b/src/lib/core/data-table/data-table.spec.ts index b463faa77a0..30bc0b2d1dd 100644 --- a/src/lib/core/data-table/data-table.spec.ts +++ b/src/lib/core/data-table/data-table.spec.ts @@ -275,7 +275,7 @@ function getHeaderCells(tableElement: Element): Element[] { } const tableCustomMatchers: jasmine.CustomMatcherFactories = { - toMatchTableContent: function(util, customEqualityTesters) { + toMatchTableContent: () => { return { compare: function (tableElement: Element, expectedTableContent: any[]) { const missedExpectations = []; diff --git a/src/lib/core/datetime/native-date-adapter.ts b/src/lib/core/datetime/native-date-adapter.ts index 36c4744a045..6e67c8143a4 100644 --- a/src/lib/core/datetime/native-date-adapter.ts +++ b/src/lib/core/datetime/native-date-adapter.ts @@ -31,7 +31,11 @@ const DEFAULT_DAY_OF_WEEK_NAMES = { /** Creates an array and fills it with values. */ function range(length: number, valueFunction: (index: number) => T): T[] { - return Array.apply(null, Array(length)).map((v: undefined, i: number) => valueFunction(i)); + const valuesArray = Array(length); + for (let i = 0; i < length; i++) { + valuesArray[i] = valueFunction(i); + } + return valuesArray; } @@ -123,7 +127,7 @@ export class NativeDateAdapter extends DateAdapter { return new Date(); } - parse(value: any, parseFormat: Object): Date | null { + parse(value: any): Date | null { // We have no way using the native JS Date to set the parse format or locale, so we ignore these // parameters. let timestamp = typeof value == 'number' ? value : Date.parse(value); diff --git a/src/lib/core/overlay/scroll/close-scroll-strategy.spec.ts b/src/lib/core/overlay/scroll/close-scroll-strategy.spec.ts index 91b55eca109..d2966336c38 100644 --- a/src/lib/core/overlay/scroll/close-scroll-strategy.spec.ts +++ b/src/lib/core/overlay/scroll/close-scroll-strategy.spec.ts @@ -8,7 +8,6 @@ import { OverlayState, OverlayRef, OverlayModule, - ScrollStrategy, ScrollDispatcher, } from '../../core'; @@ -23,7 +22,7 @@ describe('CloseScrollStrategy', () => { imports: [OverlayModule, PortalModule, OverlayTestModule], providers: [ {provide: ScrollDispatcher, useFactory: () => { - return {scrolled: (delay: number, callback: () => any) => { + return {scrolled: (_delay: number, callback: () => any) => { return scrolledSubject.asObservable().subscribe(callback); }}; }} diff --git a/src/lib/core/overlay/scroll/reposition-scroll-strategy.spec.ts b/src/lib/core/overlay/scroll/reposition-scroll-strategy.spec.ts index 1f2812a7b06..d1be6efbb42 100644 --- a/src/lib/core/overlay/scroll/reposition-scroll-strategy.spec.ts +++ b/src/lib/core/overlay/scroll/reposition-scroll-strategy.spec.ts @@ -8,7 +8,6 @@ import { OverlayState, OverlayRef, OverlayModule, - ScrollStrategy, ScrollDispatcher, } from '../../core'; @@ -23,7 +22,7 @@ describe('RepositionScrollStrategy', () => { imports: [OverlayModule, PortalModule, OverlayTestModule], providers: [ {provide: ScrollDispatcher, useFactory: () => { - return {scrolled: (delay: number, callback: () => any) => { + return {scrolled: (_delay: number, callback: () => any) => { return scrolledSubject.asObservable().subscribe(callback); }}; }} diff --git a/src/lib/core/overlay/scroll/scroll-dispatcher.ts b/src/lib/core/overlay/scroll/scroll-dispatcher.ts index 60718bf02e8..eb77ffb5967 100644 --- a/src/lib/core/overlay/scroll/scroll-dispatcher.ts +++ b/src/lib/core/overlay/scroll/scroll-dispatcher.ts @@ -105,7 +105,7 @@ export class ScrollDispatcher { getScrollContainers(elementRef: ElementRef): Scrollable[] { const scrollingContainers: Scrollable[] = []; - this.scrollableReferences.forEach((subscription: Subscription, scrollable: Scrollable) => { + this.scrollableReferences.forEach((_subscription: Subscription, scrollable: Scrollable) => { if (this.scrollableContainsElement(scrollable, elementRef)) { scrollingContainers.push(scrollable); } diff --git a/src/lib/core/style/focus-origin-monitor.spec.ts b/src/lib/core/style/focus-origin-monitor.spec.ts index 3b63018e6f9..fe7726d1bce 100644 --- a/src/lib/core/style/focus-origin-monitor.spec.ts +++ b/src/lib/core/style/focus-origin-monitor.spec.ts @@ -464,7 +464,7 @@ class PlainButton { template: `` }) class ButtonWithFocusClasses { - focusChanged(origin: FocusOrigin) {} + focusChanged(_origin: FocusOrigin) {} } diff --git a/src/lib/core/testing/jasmine-matchers.ts b/src/lib/core/testing/jasmine-matchers.ts index 037cfcf7a5d..74f70de6fea 100644 --- a/src/lib/core/testing/jasmine-matchers.ts +++ b/src/lib/core/testing/jasmine-matchers.ts @@ -2,8 +2,7 @@ * Collection of useful custom jasmine matchers for tests. */ export const customMatchers: jasmine.CustomMatcherFactories = { - toBeRole: function(util: jasmine.MatchersUtil, - customEqualityTesters: jasmine.CustomEqualityTester[]) { + toBeRole: () => { return { compare: function (element: Element, expectedRole: string) { const result: jasmine.CustomMatcherResult = {pass: false}; diff --git a/src/lib/core/testing/type-in-element.ts b/src/lib/core/testing/type-in-element.ts index 326bee5a6d5..aba451157d1 100644 --- a/src/lib/core/testing/type-in-element.ts +++ b/src/lib/core/testing/type-in-element.ts @@ -6,7 +6,7 @@ import {dispatchFakeEvent} from './dispatch-events'; * @param value Value to be set on the input. * @param element Element onto which to set the value. */ -export function typeInElement(value: string, element: HTMLInputElement, autoFocus = true) { +export function typeInElement(value: string, element: HTMLInputElement) { element.focus(); element.value = value; dispatchFakeEvent(element, 'input'); diff --git a/src/lib/datepicker/datepicker-input.ts b/src/lib/datepicker/datepicker-input.ts index 9b676f27f41..ef2a0345663 100644 --- a/src/lib/datepicker/datepicker-input.ts +++ b/src/lib/datepicker/datepicker-input.ts @@ -121,7 +121,7 @@ export class MdDatepickerInput implements AfterContentInit, ControlValueAcces _onTouched = () => {}; - private _cvaOnChange = (value: any) => {}; + private _cvaOnChange: (value: any) => void = () => {}; private _validatorOnChange = () => {}; diff --git a/src/lib/grid-list/tile-styler.ts b/src/lib/grid-list/tile-styler.ts index 1fe21519f57..65a3648ff9d 100644 --- a/src/lib/grid-list/tile-styler.ts +++ b/src/lib/grid-list/tile-styler.ts @@ -6,7 +6,7 @@ import {TileCoordinator} from './tile-coordinator'; * Tile Coordinator. * @docs-private */ -export class TileStyler { +export abstract class TileStyler { _gutterSize: string; _rows: number = 0; _rowspan: number = 0; @@ -122,11 +122,12 @@ export class TileStyler { * This method will be implemented by each type of TileStyler. * @docs-private */ - setRowStyles(tile: MdGridTile, rowIndex: number, percentWidth: number, gutterWidth: number) {} + abstract setRowStyles(tile: MdGridTile, rowIndex: number, percentWidth: number, + gutterWidth: number); /** * Calculates the computed height and returns the correct style property to set. - * This method will be implemented by each type of TileStyler. + * This method can be implemented by each type of TileStyler. * @docs-private */ getComputedHeight(): [string, string] { return null; } @@ -147,8 +148,7 @@ export class FixedTileStyler extends TileStyler { this.fixedRowHeight = normalizeUnits(this.fixedRowHeight); } - setRowStyles(tile: MdGridTile, rowIndex: number, percentWidth: number, - gutterWidth: number): void { + setRowStyles(tile: MdGridTile, rowIndex: number): void { tile._setStyle('top', this.getTilePosition(this.fixedRowHeight, rowIndex)); tile._setStyle('height', calc(this.getTileSize(this.fixedRowHeight, tile.rowspan))); } @@ -215,8 +215,7 @@ export class RatioTileStyler extends TileStyler { */ export class FitTileStyler extends TileStyler { - setRowStyles(tile: MdGridTile, rowIndex: number, percentWidth: number, - gutterWidth: number): void { + setRowStyles(tile: MdGridTile, rowIndex: number): void { // Percent of the available vertical space that one row takes up. let percentHeightPerTile = 100 / this._rowspan; @@ -229,6 +228,7 @@ export class FitTileStyler extends TileStyler { tile._setStyle('top', this.getTilePosition(baseTileHeight, rowIndex)); tile._setStyle('height', calc(this.getTileSize(baseTileHeight, tile.rowspan))); } + } diff --git a/src/lib/icon/icon-registry.ts b/src/lib/icon/icon-registry.ts index 29e2c48be24..33c03be51cf 100644 --- a/src/lib/icon/icon-registry.ts +++ b/src/lib/icon/icon-registry.ts @@ -245,7 +245,7 @@ export class MdIconRegistry { .filter(iconSetConfig => !iconSetConfig.svgElement) .map(iconSetConfig => this._loadSvgIconSetFromConfig(iconSetConfig) - .catch((err: any, caught: Observable): Observable => { + .catch((err: any): Observable => { let url = this._sanitizer.sanitize(SecurityContext.RESOURCE_URL, iconSetConfig.url); @@ -263,7 +263,7 @@ export class MdIconRegistry { // Fetch all the icon set URLs. When the requests complete, every IconSet should have a // cached SVG element (unless the request failed), and we can check again for the icon. return Observable.forkJoin(iconSetFetchRequests) - .map((ignoredResults: any) => { + .map(() => { const foundIcon = this._extractIconWithNameFromAnySet(name, iconSetConfigs); if (!foundIcon) { throw getMdIconNameNotFoundError(name); diff --git a/src/lib/radio/radio.spec.ts b/src/lib/radio/radio.spec.ts index 20dec0dddcc..35101d0e1a3 100644 --- a/src/lib/radio/radio.spec.ts +++ b/src/lib/radio/radio.spec.ts @@ -143,7 +143,7 @@ describe('MdRadio', () => { expect(radioInstances[0].checked).toBe(false); let spies = radioInstances - .map((value, index) => jasmine.createSpy(`onChangeSpy ${index}`)); + .map((radio, index) => jasmine.createSpy(`onChangeSpy ${index} for ${radio.name}`)); spies.forEach((spy, index) => radioInstances[index].change.subscribe(spy)); diff --git a/src/lib/radio/radio.ts b/src/lib/radio/radio.ts index a879e05ac8c..191be67bb80 100644 --- a/src/lib/radio/radio.ts +++ b/src/lib/radio/radio.ts @@ -95,7 +95,7 @@ export class MdRadioGroup extends _MdRadioGroupMixinBase private _disabled: boolean = false; /** The method to be called in order to update ngModel */ - _controlValueAccessorChangeFn: (value: any) => void = (value) => {}; + _controlValueAccessorChangeFn: (value: any) => void = () => {}; /** * onTouch function registered via registerOnTouch (ControlValueAccessor). diff --git a/src/lib/select/select.spec.ts b/src/lib/select/select.spec.ts index e833a67c590..2b7d90e4165 100644 --- a/src/lib/select/select.spec.ts +++ b/src/lib/select/select.spec.ts @@ -79,7 +79,7 @@ describe('MdSelect', () => { }}, {provide: Dir, useFactory: () => dir = { value: 'ltr' }}, {provide: ScrollDispatcher, useFactory: () => { - return {scrolled: (delay: number, callback: () => any) => { + return {scrolled: (_delay: number, callback: () => any) => { return scrolledSubject.asObservable().subscribe(callback); }}; }} @@ -2505,9 +2505,9 @@ class SelectInitWithoutOptions { class CustomSelectAccessor implements ControlValueAccessor { @ViewChild(MdSelect) select: MdSelect; - writeValue(val: any): void {} - registerOnChange(fn: (val: any) => void): void {} - registerOnTouched(fn: Function): void {} + writeValue: (value?: any) => void = () => {}; + registerOnChange: (changeFn?: (value: any) => void) => void = () => {}; + registerOnTouched: (touchedFn?: () => void) => void = () => {}; } @Component({ diff --git a/src/lib/select/select.ts b/src/lib/select/select.ts index 3dee28b89c0..84a70f1e6a4 100644 --- a/src/lib/select/select.ts +++ b/src/lib/select/select.ts @@ -193,7 +193,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On _selectedValueWidth: number; /** View -> model callback called when value changes */ - _onChange = (value: any) => {}; + _onChange: (value: any) => void = () => {}; /** View -> model callback called when select has been touched */ _onTouched = () => {}; diff --git a/src/lib/slide-toggle/slide-toggle.spec.ts b/src/lib/slide-toggle/slide-toggle.spec.ts index a514f9b612a..8b9270c1fa8 100644 --- a/src/lib/slide-toggle/slide-toggle.spec.ts +++ b/src/lib/slide-toggle/slide-toggle.spec.ts @@ -685,10 +685,8 @@ class SlideToggleTestApp { lastEvent: MdSlideToggleChange; labelPosition: string; - onSlideClick(event: Event) {} - onSlideChange(event: MdSlideToggleChange) { - this.lastEvent = event; - } + onSlideClick: (event?: Event) => void = () => {}; + onSlideChange = (event: MdSlideToggleChange) => this.lastEvent = event; } diff --git a/src/lib/snack-bar/snack-bar-container.ts b/src/lib/snack-bar/snack-bar-container.ts index 7c31ecbb762..c34caeedaf6 100644 --- a/src/lib/snack-bar/snack-bar-container.ts +++ b/src/lib/snack-bar/snack-bar-container.ts @@ -99,7 +99,7 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy { } /** Attach a template portal as content to this snack bar container. */ - attachTemplatePortal(portal: TemplatePortal): Map { + attachTemplatePortal(): Map { throw new Error('Not yet implemented'); } diff --git a/src/tsconfig.json b/src/tsconfig.json index 864cdd42a0a..d65d9e82100 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -5,6 +5,7 @@ "experimentalDecorators": true, "module": "es2015", "moduleResolution": "node", + "noUnusedParameters": true, "outDir": "../dist/packages/all", "sourceMap": true, "inlineSources": true,