Skip to content

Commit 18c6689

Browse files
crisbetommalerba
authored andcommitted
build: disallow usage of HostBinding and HostListener (#6307)
Adds the `HostBinding` and `HostListener` decorators to the banned symbols list for consistency's sake. Refactors the handful of places that were using them. Relates to #6304.
1 parent faa7601 commit 18c6689

File tree

5 files changed

+25
-33
lines changed

5 files changed

+25
-33
lines changed

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
ElementRef,
1414
Renderer2,
1515
EventEmitter,
16-
HostBinding,
1716
Input,
1817
OnInit,
1918
OnDestroy,
@@ -264,7 +263,10 @@ export class MdButtonToggleGroupMultiple extends _MdButtonToggleGroupMixinBase
264263
changeDetection: ChangeDetectionStrategy.OnPush,
265264
host: {
266265
'[class.mat-button-toggle-standalone]': '!buttonToggleGroup && !buttonToggleGroupMultiple',
267-
'class': 'mat-button-toggle'
266+
'[class.mat-button-toggle-checked]': 'checked',
267+
'[class.mat-button-toggle-disabled]': 'disabled',
268+
'class': 'mat-button-toggle',
269+
'[attr.id]': 'id',
268270
}
269271
})
270272
export class MdButtonToggle implements OnInit, OnDestroy {
@@ -311,21 +313,14 @@ export class MdButtonToggle implements OnInit, OnDestroy {
311313
}
312314

313315
/** The unique ID for this button toggle. */
314-
@HostBinding()
315-
@Input()
316-
id: string;
316+
@Input() id: string;
317317

318318
/** HTML's 'name' attribute used to group radios for unique selection. */
319-
@Input()
320-
name: string;
319+
@Input() name: string;
321320

322321
/** Whether the button is checked. */
323-
@HostBinding('class.mat-button-toggle-checked')
324322
@Input()
325-
get checked(): boolean {
326-
return this._checked;
327-
}
328-
323+
get checked(): boolean { return this._checked; }
329324
set checked(newCheckedState: boolean) {
330325
if (this._isSingleSelector && newCheckedState) {
331326
// Notify all button toggles with the same name (in the same group) to un-check.
@@ -356,7 +351,6 @@ export class MdButtonToggle implements OnInit, OnDestroy {
356351
}
357352

358353
/** Whether the button is disabled. */
359-
@HostBinding('class.mat-button-toggle-disabled')
360354
@Input()
361355
get disabled(): boolean {
362356
return this._disabled || (this.buttonToggleGroup != null && this.buttonToggleGroup.disabled) ||

src/lib/progress-bar/progress-bar.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {
10-
Component,
11-
ChangeDetectionStrategy,
12-
HostBinding,
13-
Input,
14-
} from '@angular/core';
9+
import {Component, ChangeDetectionStrategy, Input} from '@angular/core';
1510

1611
// TODO(josephperrott): Benchpress tests.
1712
// TODO(josephperrott): Add ARIA attributes for progressbar "for".
@@ -27,6 +22,8 @@ import {
2722
'role': 'progressbar',
2823
'aria-valuemin': '0',
2924
'aria-valuemax': '100',
25+
'[attr.aria-valuenow]': 'value',
26+
'[attr.mode]': 'mode',
3027
'[class.mat-primary]': 'color == "primary"',
3128
'[class.mat-accent]': 'color == "accent"',
3229
'[class.mat-warn]': 'color == "warn"',
@@ -44,7 +41,6 @@ export class MdProgressBar {
4441

4542
/** Value of the progressbar. Defaults to zero. Mirrored to aria-valuenow. */
4643
@Input()
47-
@HostBinding('attr.aria-valuenow')
4844
get value() { return this._value; }
4945
set value(v: number) { this._value = clamp(v || 0); }
5046

@@ -62,9 +58,7 @@ export class MdProgressBar {
6258
* 'determinate'.
6359
* Mirrored to mode attribute.
6460
*/
65-
@Input()
66-
@HostBinding('attr.mode')
67-
mode: 'determinate' | 'indeterminate' | 'buffer' | 'query' = 'determinate';
61+
@Input() mode: 'determinate' | 'indeterminate' | 'buffer' | 'query' = 'determinate';
6862

6963
/** Gets the current transform value for the progress bar's primary indicator. */
7064
_primaryTransform() {

src/lib/progress-spinner/progress-spinner.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import {
1010
Component,
11-
HostBinding,
1211
ChangeDetectionStrategy,
1312
OnDestroy,
1413
Input,
@@ -72,7 +71,9 @@ export const _MdProgressSpinnerMixinBase = mixinColor(MdProgressSpinnerBase, 'pr
7271
host: {
7372
'role': 'progressbar',
7473
'[attr.aria-valuemin]': '_ariaValueMin',
75-
'[attr.aria-valuemax]': '_ariaValueMax'
74+
'[attr.aria-valuemax]': '_ariaValueMax',
75+
'[attr.aria-valuenow]': 'value',
76+
'[attr.mode]': 'mode',
7677
},
7778
inputs: ['color'],
7879
templateUrl: 'progress-spinner.html',
@@ -132,7 +133,6 @@ export class MdProgressSpinner extends _MdProgressSpinnerMixinBase
132133

133134
/** Value of the progress circle. It is bound to the host as the attribute aria-valuenow. */
134135
@Input()
135-
@HostBinding('attr.aria-valuenow')
136136
get value() {
137137
if (this.mode == 'determinate') {
138138
return this._value;
@@ -154,11 +154,8 @@ export class MdProgressSpinner extends _MdProgressSpinnerMixinBase
154154
* Input must be one of the values from ProgressMode, defaults to 'determinate'.
155155
* mode is bound to the host as the attribute host.
156156
*/
157-
@HostBinding('attr.mode')
158157
@Input()
159-
get mode() {
160-
return this._mode;
161-
}
158+
get mode() { return this._mode; }
162159
set mode(mode: ProgressSpinnerMode) {
163160
if (mode !== this._mode) {
164161
if (mode === 'indeterminate') {

src/lib/tabs/tab-nav-bar/tab-nav-bar.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
Component,
1212
Directive,
1313
ElementRef,
14-
HostBinding,
1514
Inject,
1615
Input,
1716
NgZone,
@@ -153,6 +152,7 @@ export const _MdTabLinkMixinBase = mixinDisabled(MdTabLinkBase);
153152
host: {
154153
'class': 'mat-tab-link',
155154
'[attr.aria-disabled]': 'disabled.toString()',
155+
'[attr.tabindex]': 'tabIndex',
156156
'[class.mat-tab-disabled]': 'disabled'
157157
}
158158
})
@@ -174,7 +174,6 @@ export class MdTabLink extends _MdTabLinkMixinBase implements OnDestroy, CanDisa
174174
}
175175

176176
/** @docs-private */
177-
@HostBinding('tabIndex')
178177
get tabIndex(): number {
179178
return this.disabled ? -1 : 0;
180179
}

tslint.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@
8080
"check-preblock"
8181
],
8282
// Bans jasmine helper functions that will prevent the CI from properly running tests.
83-
"ban": [true, ["fit"], ["fdescribe"], ["xit"], ["xdescribe"]],
83+
"ban": [
84+
true,
85+
["fit"],
86+
["fdescribe"],
87+
["xit"],
88+
["xdescribe"],
89+
{ "name": "HostBinding", "message": "Use `host` in the component definition instead." },
90+
{ "name": "HostListener", "message": "Use `host` in the component definition instead." }
91+
],
8492
// Disallows importing the whole RxJS library. Submodules can be still imported.
8593
"import-blacklist": [true, "rxjs"],
8694
// Avoids inconsistent linebreak styles in source files. Forces developers to use LF linebreaks.

0 commit comments

Comments
 (0)