Skip to content

Commit 28ede30

Browse files
devversionjelbourn
authored andcommitted
build: stricter unused variable checking (#6633)
Currently only variables that don't start with an underscore will be checked by TSLint. This doesn't make sense, because variables get prefixed with an underscore to indicate that they are not part of the public API, but still need to be public in favor of AOT compilation for example. This means that those properties are having the public modifier set (explicitly or automatically) and therefore won't be treated as unused anyway. **TL;DR**: With this change, prefixed variables will be checked by the `no-unused-variable` TSLint rule and those which are marked as `private` and are unused will be catched by TSLint.
1 parent 454781d commit 28ede30

File tree

13 files changed

+24
-28
lines changed

13 files changed

+24
-28
lines changed

src/cdk/overlay/position/connected-position-strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ export class ConnectedPositionStrategy implements PositionStrategy {
7272
}
7373

7474
constructor(
75+
originPos: OriginConnectionPosition,
76+
overlayPos: OverlayConnectionPosition,
7577
private _connectedTo: ElementRef,
76-
private _originPos: OriginConnectionPosition,
77-
private _overlayPos: OverlayConnectionPosition,
7878
private _viewportRuler: ViewportRuler) {
7979
this._origin = this._connectedTo.nativeElement;
80-
this.withFallbackPosition(_originPos, _overlayPos);
80+
this.withFallbackPosition(originPos, overlayPos);
8181
}
8282

8383
/** Ordered list of preferred positions, from most to least desirable. */

src/cdk/overlay/position/overlay-position-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ export class OverlayPositionBuilder {
3636
elementRef: ElementRef,
3737
originPos: OriginConnectionPosition,
3838
overlayPos: OverlayConnectionPosition): ConnectedPositionStrategy {
39-
return new ConnectedPositionStrategy(elementRef, originPos, overlayPos, this._viewportRuler);
39+
return new ConnectedPositionStrategy(originPos, overlayPos, elementRef, this._viewportRuler);
4040
}
4141
}

src/cdk/rxjs/rx-operators.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export interface StrictRxChain<T> {
7676
result(): Observable<T>;
7777
}
7878

79-
79+
/* tslint:disable:no-unused-variable */
8080
export class FinallyBrand { private _; }
8181
export class CatchBrand { private _; }
8282
export class DoBrand { private _; }
@@ -89,6 +89,7 @@ export class StartWithBrand { private _; }
8989
export class DebounceTimeBrand { private _; }
9090
export class AuditTimeBrand { private _; }
9191
export class TakeUntilBrand { private _; }
92+
/* tslint:enable:no-unused-variable */
9293

9394

9495
export type finallyOperatorType<T> = typeof _finallyOperator & FinallyBrand;

src/lib/dialog/dialog-container.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
EmbeddedViewRef,
1414
EventEmitter,
1515
Inject,
16-
NgZone,
1716
Optional,
1817
ChangeDetectorRef,
1918
ViewChild,
@@ -100,7 +99,6 @@ export class MdDialogContainer extends BasePortalHost {
10099
_isAnimating = false;
101100

102101
constructor(
103-
private _ngZone: NgZone,
104102
private _elementRef: ElementRef,
105103
private _focusTrapFactory: FocusTrapFactory,
106104
private _changeDetectorRef: ChangeDetectorRef,

src/lib/dialog/dialog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ export class MdDialog {
9696
constructor(
9797
private _overlay: Overlay,
9898
private _injector: Injector,
99+
@Optional() location: Location,
99100
@Inject(MD_DIALOG_SCROLL_STRATEGY) private _scrollStrategy,
100-
@Optional() private _location: Location,
101101
@Optional() @SkipSelf() private _parentDialog: MdDialog) {
102102

103103
// Close all of the dialogs when the user goes forwards/backwards in history or when the
104104
// location hash changes. Note that this usually doesn't include clicking on links (unless
105105
// the user is using the `HashLocationStrategy`).
106-
if (!_parentDialog && _location) {
107-
_location.subscribe(() => this.closeAll());
106+
if (!_parentDialog && location) {
107+
location.subscribe(() => this.closeAll());
108108
}
109109
}
110110

src/lib/expansion/expansion-panel-header.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export class MdExpansionPanelHeader implements OnDestroy {
9090
private _parentChangeSubscription = Subscription.EMPTY;
9191

9292
constructor(
93+
renderer: Renderer2,
9394
@Host() public panel: MdExpansionPanel,
94-
private _renderer: Renderer2,
9595
private _element: ElementRef,
9696
private _focusOriginMonitor: FocusOriginMonitor,
9797
private _changeDetectorRef: ChangeDetectorRef) {
@@ -105,7 +105,7 @@ export class MdExpansionPanelHeader implements OnDestroy {
105105
)
106106
.subscribe(() => this._changeDetectorRef.markForCheck());
107107

108-
_focusOriginMonitor.monitor(_element.nativeElement, _renderer, false);
108+
_focusOriginMonitor.monitor(_element.nativeElement, renderer, false);
109109
}
110110

111111
/** Height of the header while the panel is expanded. */

src/lib/paginator/paginator.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {async, ComponentFixture, TestBed, inject} from '@angular/core/testing';
22
import {MdPaginatorModule} from './index';
33
import {MdPaginator, PageEvent} from './paginator';
4-
import {Component, ElementRef, ViewChild} from '@angular/core';
4+
import {Component, ViewChild} from '@angular/core';
55
import {MdPaginatorIntl} from './paginator-intl';
66
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
77
import {dispatchMouseEvent} from '@angular/cdk/testing';
@@ -281,8 +281,6 @@ class MdPaginatorApp {
281281

282282
@ViewChild(MdPaginator) mdPaginator: MdPaginator;
283283

284-
constructor(private _elementRef: ElementRef) { }
285-
286284
goToLastPage() {
287285
this.pageIndex = Math.ceil(this.length / this.pageSize);
288286
}

src/lib/select/select.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
428428
constructor(
429429
private _viewportRuler: ViewportRuler,
430430
private _changeDetectorRef: ChangeDetectorRef,
431-
private _overlay: Overlay,
432431
private _platform: Platform,
433432
renderer: Renderer2,
434433
elementRef: ElementRef,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ class SlideToggleRenderer {
301301
/** Whether the thumb is currently being dragged. */
302302
dragging: boolean = false;
303303

304-
constructor(private _elementRef: ElementRef, platform: Platform) {
304+
constructor(elementRef: ElementRef, platform: Platform) {
305305
// We only need to interact with these elements when we're on the browser, so only grab
306306
// the reference in that case.
307307
if (platform.isBrowser) {
308-
this._thumbEl = _elementRef.nativeElement.querySelector('.mat-slide-toggle-thumb-container');
309-
this._thumbBarEl = _elementRef.nativeElement.querySelector('.mat-slide-toggle-bar');
308+
this._thumbEl = elementRef.nativeElement.querySelector('.mat-slide-toggle-thumb-container');
309+
this._thumbBarEl = elementRef.nativeElement.querySelector('.mat-slide-toggle-bar');
310310
}
311311
}
312312

src/lib/tabs/tab-header.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
async, ComponentFixture, TestBed, fakeAsync, tick, discardPeriodicTasks
33
} from '@angular/core/testing';
4-
import {Component, ViewChild, ViewContainerRef} from '@angular/core';
4+
import {Component, ViewChild} from '@angular/core';
55
import {CommonModule} from '@angular/common';
66
import {By} from '@angular/platform-browser';
77
import {ENTER, LEFT_ARROW, RIGHT_ARROW, SPACE} from '@angular/cdk/keycodes';
@@ -328,7 +328,7 @@ class SimpleTabHeaderApp {
328328

329329
@ViewChild(MdTabHeader) mdTabHeader: MdTabHeader;
330330

331-
constructor(private _viewContainerRef: ViewContainerRef) {
331+
constructor() {
332332
this.tabs[this.disabledTabIndex].disabled = true;
333333
}
334334

src/lib/tooltip/tooltip.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ export class MdTooltip implements OnDestroy {
197197
private _leaveListener: Function;
198198

199199
constructor(
200+
renderer: Renderer2,
200201
private _overlay: Overlay,
201202
private _elementRef: ElementRef,
202203
private _scrollDispatcher: ScrollDispatcher,
203204
private _viewContainerRef: ViewContainerRef,
204205
private _ngZone: NgZone,
205-
private _renderer: Renderer2,
206206
private _platform: Platform,
207207
@Inject(MD_TOOLTIP_SCROLL_STRATEGY) private _scrollStrategy,
208208
@Optional() private _dir: Directionality) {
@@ -211,9 +211,9 @@ export class MdTooltip implements OnDestroy {
211211
// they can prevent the first tap from firing its click event.
212212
if (!_platform.IOS) {
213213
this._enterListener =
214-
_renderer.listen(_elementRef.nativeElement, 'mouseenter', () => this.show());
214+
renderer.listen(_elementRef.nativeElement, 'mouseenter', () => this.show());
215215
this._leaveListener =
216-
_renderer.listen(_elementRef.nativeElement, 'mouseleave', () => this.hide());
216+
renderer.listen(_elementRef.nativeElement, 'mouseleave', () => this.hide());
217217
}
218218
}
219219

tools/screenshot-test/src/app/viewer/viewer.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export class ViewerComponent {
3838
}
3939

4040
constructor(private _service: FirebaseService,
41-
private _route: ActivatedRoute,
42-
public snackBar: MdSnackBar) {
43-
_route.params.subscribe(p => {
41+
public snackBar: MdSnackBar,
42+
activatedRoute: ActivatedRoute) {
43+
activatedRoute.params.subscribe(p => {
4444
this._service.prNumber = p['id'];
4545
});
4646
}

tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"no-var-keyword": true,
3030
"member-access": [true, "no-public"],
3131
"no-debugger": true,
32-
"no-unused-variable": [true, {"ignore-pattern": "^_"}],
32+
"no-unused-variable": true,
3333
"one-line": [
3434
true,
3535
"check-catch",

0 commit comments

Comments
 (0)