Skip to content

Commit 50b9fe2

Browse files
crisbetojelbourn
authored andcommitted
build: add linting for class member naming (#15812)
Currently we have a convention for prefixing private members with an underscore, however there's nothing verifying it. This comes up occasionally in PRs and there some cases that have deviated from the pattern. These changes add a tslint rule that allows us to customize the naming pattern for the various modifiers.
1 parent 70bc4d5 commit 50b9fe2

File tree

61 files changed

+446
-342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+446
-342
lines changed

src/a11y-demo/card/card-a11y.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import {MatSnackBar} from '@angular/material';
1919
export class CardAccessibilityDemo {
2020
showProgress: boolean = false;
2121

22-
constructor(private snackBar: MatSnackBar) {}
22+
constructor(private _snackBar: MatSnackBar) {}
2323

2424
openSnackbar(message: string) {
25-
this.snackBar.open(message, '', {duration: 2000});
25+
this._snackBar.open(message, '', {duration: 2000});
2626
}
2727
}

src/a11y-demo/icon/icon-a11y.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {MatSnackBar} from '@angular/material';
1616
templateUrl: 'icon-a11y.html',
1717
})
1818
export class IconAccessibilityDemo {
19-
constructor(private snackBar: MatSnackBar) {}
19+
constructor(private _snackBar: MatSnackBar) {}
2020

2121
deleteIcon() {
22-
this.snackBar.open('Item deleted', '', {duration: 2000});
22+
this._snackBar.open('Item deleted', '', {duration: 2000});
2323
}
2424
}

src/a11y-demo/slide-toggle/slide-toggle-a11y.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export class SlideToggleAccessibilityDemo {
2020
termsToggle = false;
2121
musicToggle = false;
2222

23-
constructor(private snackBar: MatSnackBar) {}
23+
constructor(private _snackBar: MatSnackBar) {}
2424

2525
onFormSubmit() {
26-
this.snackBar.open('Terms and condistions accepted!', '', {duration: 2000});
26+
this._snackBar.open('Terms and condistions accepted!', '', {duration: 2000});
2727
}
2828
}

src/a11y-demo/snack-bar/snack-bar-a11y.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import {MatSnackBar} from '@angular/material';
1616
templateUrl: 'snack-bar-a11y.html',
1717
})
1818
export class SnackBarAccessibilityDemo {
19-
constructor(private snackBar: MatSnackBar) {}
19+
constructor(private _snackBar: MatSnackBar) {}
2020

2121
openDiscoPartySnackBar() {
22-
this.snackBar.open('Disco party!', 'Dismiss', {duration: 5000});
22+
this._snackBar.open('Disco party!', 'Dismiss', {duration: 5000});
2323
}
2424

2525
openNotificationSnackBar() {
26-
this.snackBar.open('Thank you for your support!', '', {duration: 2000});
26+
this._snackBar.open('Thank you for your support!', '', {duration: 2000});
2727
}
2828
}

src/cdk-experimental/dialog/dialog.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ export class Dialog implements OnDestroy {
7272
_openDialogs: DialogRef<any>[] = [];
7373

7474
constructor(
75-
private overlay: Overlay,
76-
private injector: Injector,
77-
@Inject(DIALOG_REF) private dialogRefConstructor: Type<DialogRef<any>>,
75+
private _overlay: Overlay,
76+
private _injector: Injector,
77+
@Inject(DIALOG_REF) private _dialogRefConstructor: Type<DialogRef<any>>,
7878
// TODO(crisbeto): the `any` here can be replaced
7979
// with the proper type once we start using Ivy.
8080
@Inject(DIALOG_SCROLL_STRATEGY) scrollStrategy: any,
@@ -114,7 +114,7 @@ export class Dialog implements OnDestroy {
114114
const dialogRef = this._attachDialogContentForComponent(component, dialogContainer,
115115
overlayRef, config);
116116

117-
this.registerDialogRef(dialogRef);
117+
this._registerDialogRef(dialogRef);
118118
return dialogRef;
119119
}
120120

@@ -131,7 +131,7 @@ export class Dialog implements OnDestroy {
131131
const dialogRef = this._attachDialogContentForTemplate(template, dialogContainer,
132132
overlayRef, config);
133133

134-
this.registerDialogRef(dialogRef);
134+
this._registerDialogRef(dialogRef);
135135
return dialogRef;
136136
}
137137

@@ -143,7 +143,7 @@ export class Dialog implements OnDestroy {
143143
/**
144144
* Forwards emitting events for when dialogs are opened and all dialogs are closed.
145145
*/
146-
private registerDialogRef(dialogRef: DialogRef<any>): void {
146+
private _registerDialogRef(dialogRef: DialogRef<any>): void {
147147
this.openDialogs.push(dialogRef);
148148

149149
const dialogOpenSub = dialogRef.afterOpened().subscribe(() => {
@@ -172,7 +172,7 @@ export class Dialog implements OnDestroy {
172172
*/
173173
protected _createOverlay(config: DialogConfig): OverlayRef {
174174
const overlayConfig = new OverlayConfig({
175-
positionStrategy: this.overlay.position().global(),
175+
positionStrategy: this._overlay.position().global(),
176176
scrollStrategy: this._scrollStrategy(),
177177
panelClass: config.panelClass,
178178
hasBackdrop: config.hasBackdrop,
@@ -186,7 +186,7 @@ export class Dialog implements OnDestroy {
186186
if (config.backdropClass) {
187187
overlayConfig.backdropClass = config.backdropClass;
188188
}
189-
return this.overlay.create(overlayConfig);
189+
return this._overlay.create(overlayConfig);
190190
}
191191

192192
/**
@@ -196,9 +196,9 @@ export class Dialog implements OnDestroy {
196196
* @returns A promise resolving to a ComponentRef for the attached container.
197197
*/
198198
protected _attachDialogContainer(overlay: OverlayRef, config: DialogConfig): CdkDialogContainer {
199-
const container = config.containerComponent || this.injector.get(DIALOG_CONTAINER);
199+
const container = config.containerComponent || this._injector.get(DIALOG_CONTAINER);
200200
const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
201-
const injector = new PortalInjector(userInjector || this.injector, new WeakMap([
201+
const injector = new PortalInjector(userInjector || this._injector, new WeakMap([
202202
[DialogConfig, config]
203203
]));
204204
const containerPortal = new ComponentPortal(container, config.viewContainerRef, injector);
@@ -226,7 +226,7 @@ export class Dialog implements OnDestroy {
226226

227227
// Create a reference to the dialog we're creating in order to give the user a handle
228228
// to modify and close it.
229-
const dialogRef = new this.dialogRefConstructor(overlayRef, dialogContainer, config.id);
229+
const dialogRef = new this._dialogRefConstructor(overlayRef, dialogContainer, config.id);
230230
const injector = this._createInjector<T>(config, dialogRef, dialogContainer);
231231
const contentRef = dialogContainer.attachComponentPortal(
232232
new ComponentPortal(componentOrTemplateRef, undefined, injector));
@@ -257,7 +257,7 @@ export class Dialog implements OnDestroy {
257257

258258
// Create a reference to the dialog we're creating in order to give the user a handle
259259
// to modify and close it.
260-
const dialogRef = new this.dialogRefConstructor(overlayRef, dialogContainer, config.id);
260+
const dialogRef = new this._dialogRefConstructor(overlayRef, dialogContainer, config.id);
261261

262262
dialogContainer.attachTemplatePortal(
263263
new TemplatePortal<T>(componentOrTemplateRef, null!,
@@ -284,8 +284,8 @@ export class Dialog implements OnDestroy {
284284

285285
const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
286286
const injectionTokens = new WeakMap<any, any>([
287-
[this.injector.get(DIALOG_REF), dialogRef],
288-
[this.injector.get(DIALOG_CONTAINER), dialogContainer],
287+
[this._injector.get(DIALOG_REF), dialogRef],
288+
[this._injector.get(DIALOG_CONTAINER), dialogContainer],
289289
[DIALOG_DATA, config.data]
290290
]);
291291

@@ -297,15 +297,15 @@ export class Dialog implements OnDestroy {
297297
});
298298
}
299299

300-
return new PortalInjector(userInjector || this.injector, injectionTokens);
300+
return new PortalInjector(userInjector || this._injector, injectionTokens);
301301
}
302302

303303
/**
304304
* Expands the provided configuration object to include the default values for properties which
305305
* are undefined.
306306
*/
307307
private _applyConfigDefaults(config?: DialogConfig): DialogConfig {
308-
const dialogConfig = this.injector.get(DIALOG_CONFIG) as typeof DialogConfig;
308+
const dialogConfig = this._injector.get(DIALOG_CONFIG) as typeof DialogConfig;
309309
return {...new dialogConfig(), ...config};
310310
}
311311
}

src/cdk/layout/breakpoints-observer.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,29 @@ export class FakeMediaQueryList {
193193
@Injectable()
194194
export class FakeMediaMatcher {
195195
/** A map of match media queries. */
196-
private queries = new Map<string, FakeMediaQueryList>();
196+
private _queries = new Map<string, FakeMediaQueryList>();
197197

198198
/** The number of distinct queries created in the media matcher during a test. */
199199
get queryCount(): number {
200-
return this.queries.size;
200+
return this._queries.size;
201201
}
202202

203203
/** Fakes the match media response to be controlled in tests. */
204204
matchMedia(query: string): FakeMediaQueryList {
205205
const mql = new FakeMediaQueryList(true, query);
206-
this.queries.set(query, mql);
206+
this._queries.set(query, mql);
207207
return mql;
208208
}
209209

210210
/** Clears all queries from the map of queries. */
211211
clear() {
212-
this.queries.clear();
212+
this._queries.clear();
213213
}
214214

215215
/** Toggles the matching state of the provided query. */
216216
setMatchesQuery(query: string, matches: boolean) {
217-
if (this.queries.has(query)) {
218-
this.queries.get(query)!.setMatches(matches);
217+
if (this._queries.has(query)) {
218+
this._queries.get(query)!.setMatches(matches);
219219
} else {
220220
throw Error('This query is not being observed.');
221221
}

src/cdk/layout/breakpoints-observer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class BreakpointObserver implements OnDestroy {
4747
/** A subject for all other observables to takeUntil based on. */
4848
private _destroySubject = new Subject<void>();
4949

50-
constructor(private mediaMatcher: MediaMatcher, private zone: NgZone) {}
50+
constructor(private _mediaMatcher: MediaMatcher, private _zone: NgZone) {}
5151

5252
/** Completes the active subject, signalling to all other observables to complete. */
5353
ngOnDestroy() {
@@ -97,7 +97,7 @@ export class BreakpointObserver implements OnDestroy {
9797
return this._queries.get(query)!;
9898
}
9999

100-
const mql: MediaQueryList = this.mediaMatcher.matchMedia(query);
100+
const mql: MediaQueryList = this._mediaMatcher.matchMedia(query);
101101

102102
// Create callback for match changes and add it is as a listener.
103103
const queryObservable = new Observable<MediaQueryList>((observer: Observer<MediaQueryList>) => {
@@ -106,7 +106,7 @@ export class BreakpointObserver implements OnDestroy {
106106
// webapis-media-query.js file alongside the zone.js file. Additionally, some browsers do not
107107
// have MediaQueryList inherit from EventTarget, which causes inconsistencies in how Zone.js
108108
// patches it.
109-
const handler = (e: any) => this.zone.run(() => observer.next(e));
109+
const handler = (e: any) => this._zone.run(() => observer.next(e));
110110
mql.addListener(handler);
111111

112112
return () => {

src/cdk/layout/media-matcher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export class MediaMatcher {
2020
/** The internal matchMedia method to return back a MediaQueryList like object. */
2121
private _matchMedia: (query: string) => MediaQueryList;
2222

23-
constructor(private platform: Platform) {
24-
this._matchMedia = this.platform.isBrowser && window.matchMedia ?
23+
constructor(private _platform: Platform) {
24+
this._matchMedia = this._platform.isBrowser && window.matchMedia ?
2525
// matchMedia is bound to the window scope intentionally as it is an illegal invocation to
2626
// call it from a different scope.
2727
window.matchMedia.bind(window) :
@@ -35,7 +35,7 @@ export class MediaMatcher {
3535
* MediaQueryList for the query provided.
3636
*/
3737
matchMedia(query: string): MediaQueryList {
38-
if (this.platform.WEBKIT) {
38+
if (this._platform.WEBKIT) {
3939
createEmptyStyleRule(query);
4040
}
4141
return this._matchMedia(query);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
7777
private _viewportMargin = 0;
7878

7979
/** The Scrollable containers used to check scrollable view properties on position change. */
80-
private scrollables: CdkScrollable[] = [];
80+
private _scrollables: CdkScrollable[] = [];
8181

8282
/** Ordered list of preferred positions, from most to least desirable. */
8383
_preferredPositions: ConnectionPositionPair[] = [];
@@ -366,7 +366,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
366366
* Scrollable must be an ancestor element of the strategy's origin element.
367367
*/
368368
withScrollableContainers(scrollables: CdkScrollable[]): this {
369-
this.scrollables = scrollables;
369+
this._scrollables = scrollables;
370370
return this;
371371
}
372372

@@ -994,7 +994,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
994994
// TODO(jelbourn): instead of needing all of the client rects for these scrolling containers
995995
// every time, we should be able to use the scrollTop of the containers if the size of those
996996
// containers hasn't changed.
997-
const scrollContainerBounds = this.scrollables.map(scrollable => {
997+
const scrollContainerBounds = this._scrollables.map(scrollable => {
998998
return scrollable.getElementRef().nativeElement.getBoundingClientRect();
999999
});
10001000

src/cdk/table/sticky-styler.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ export const STICKY_DIRECTIONS: StickyDirection[] = ['top', 'bottom', 'left', 'r
2626
*/
2727
export class StickyStyler {
2828
/**
29-
* @param isNativeHtmlTable Whether the sticky logic should be based on a table
29+
* @param _isNativeHtmlTable Whether the sticky logic should be based on a table
3030
* that uses the native `<table>` element.
31-
* @param stickCellCss The CSS class that will be applied to every row/cell that has
31+
* @param _stickCellCss The CSS class that will be applied to every row/cell that has
3232
* sticky positioning applied.
3333
* @param direction The directionality context of the table (ltr/rtl); affects column positioning
3434
* by reversing left/right positions.
3535
* @param _isBrowser Whether the table is currently being rendered on the server or the client.
3636
*/
37-
constructor(private isNativeHtmlTable: boolean,
38-
private stickCellCss: string,
37+
constructor(private _isNativeHtmlTable: boolean,
38+
private _stickCellCss: string,
3939
public direction: Direction,
4040
private _isBrowser = true) { }
4141

@@ -129,7 +129,7 @@ export class StickyStyler {
129129
}
130130

131131
const row = rows[rowIndex];
132-
if (this.isNativeHtmlTable) {
132+
if (this._isNativeHtmlTable) {
133133
for (let j = 0; j < row.children.length; j++) {
134134
const cell = row.children[j] as HTMLElement;
135135
this._addStickyStyle(cell, position, stickyHeight);
@@ -155,7 +155,7 @@ export class StickyStyler {
155155
* the tfoot element.
156156
*/
157157
updateStickyFooterContainer(tableElement: Element, stickyStates: boolean[]) {
158-
if (!this.isNativeHtmlTable) {
158+
if (!this._isNativeHtmlTable) {
159159
return;
160160
}
161161

@@ -183,7 +183,7 @@ export class StickyStyler {
183183
const hasDirection = STICKY_DIRECTIONS.some(dir => !!element.style[dir]);
184184
if (!hasDirection) {
185185
element.style.position = '';
186-
element.classList.remove(this.stickCellCss);
186+
element.classList.remove(this._stickCellCss);
187187
}
188188
}
189189

@@ -193,7 +193,7 @@ export class StickyStyler {
193193
* direction and value.
194194
*/
195195
_addStickyStyle(element: HTMLElement, dir: StickyDirection, dirValue: number) {
196-
element.classList.add(this.stickCellCss);
196+
element.classList.add(this._stickCellCss);
197197
element.style[dir] = `${dirValue}px`;
198198
element.style.cssText += 'position: -webkit-sticky; position: sticky; ';
199199
element.style.zIndex = this._getCalculatedZIndex(element);

0 commit comments

Comments
 (0)