Skip to content

build: add custom linting for symbol names #19811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/material/checkbox/checkbox-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {MatCheckboxRequiredValidator} from './checkbox-required-validator';
exports: [MatCheckboxRequiredValidator],
declarations: [MatCheckboxRequiredValidator],
})
// tslint:disable-next-line:class-name
export class _MatCheckboxRequiredValidatorModule {
}

Expand Down
1 change: 0 additions & 1 deletion src/material/menu/menu-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER, MatMenuTrigger} from './menu-
],
providers: [MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER]
})
// tslint:disable-next-line:class-name
export class _MatMenuDirectivesModule {}

@NgModule({
Expand Down
3 changes: 0 additions & 3 deletions src/material/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ let menuPanelUid = 0;

/** Base class with all of the `MatMenu` functionality. */
@Directive()
// tslint:disable-next-line:class-name
export class _MatMenuBase implements AfterContentInit, MatMenuPanel<MatMenuItem>, OnInit,
OnDestroy {
private _keyManager: FocusKeyManager<MatMenuItem>;
Expand Down Expand Up @@ -519,9 +518,7 @@ export class MatMenu extends _MatMenuBase {}
{provide: MatMenu, useExisting: _MatMenu}
]
})
// tslint:disable-next-line:class-name
export class _MatMenu extends MatMenu {

constructor(elementRef: ElementRef<HTMLElement>, ngZone: NgZone,
@Inject(MAT_MENU_DEFAULT_OPTIONS) defaultOptions: MatMenuDefaultOptions) {
super(elementRef, ngZone, defaultOptions);
Expand Down
2 changes: 0 additions & 2 deletions src/material/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export const MAT_RADIO_GROUP =
* @docs-private
*/
@Directive()
// tslint:disable-next-line:class-name
export abstract class _MatRadioGroupBase<T extends _MatRadioButtonBase> implements AfterContentInit,
ControlValueAccessor {
/** Selected value for the radio group. */
Expand Down Expand Up @@ -354,7 +353,6 @@ const _MatRadioButtonMixinBase:
* @docs-private
*/
@Directive()
// tslint:disable-next-line:class-name
export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase implements OnInit,
AfterViewInit, OnDestroy, CanDisableRipple, HasTabIndex {

Expand Down
4 changes: 1 addition & 3 deletions src/material/slide-toggle/slide-toggle-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import {MatSlideToggleRequiredValidator} from './slide-toggle-required-validator
exports: [MatSlideToggleRequiredValidator],
declarations: [MatSlideToggleRequiredValidator],
})
// tslint:disable-next-line:class-name
export class _MatSlideToggleRequiredValidatorModule {
}
export class _MatSlideToggleRequiredValidatorModule {}

@NgModule({
imports: [
Expand Down
1 change: 0 additions & 1 deletion src/material/tabs/ink-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
* Interface for a a MatInkBar positioner method, defining the positioning and width of the ink
* bar in a set of tabs.
*/
// tslint:disable-next-line class-name Using leading underscore to denote internal interface.
export interface _MatInkBarPositioner {
(element: HTMLElement): { left: string, width: string };
}
Expand Down
1 change: 0 additions & 1 deletion src/material/tabs/tab-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export class MatTabBodyPortal extends CdkPortalOutlet implements OnInit, OnDestr
* @docs-private
*/
@Directive()
// tslint:disable-next-line:class-name
export abstract class _MatTabBodyBase implements OnInit, OnDestroy {
/** Current position of the tab-body in the tab-group. Zero means that the tab is visible. */
private _positionIndex: number;
Expand Down
1 change: 0 additions & 1 deletion src/material/tabs/tab-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ interface MatTabGroupBaseHeader {
* @docs-private
*/
@Directive()
// tslint:disable-next-line:class-name
export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements AfterContentInit,
AfterContentChecked, OnDestroy, CanColor, CanDisableRipple {

Expand Down
1 change: 0 additions & 1 deletion src/material/tabs/tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {MatPaginatedTabHeader} from './paginated-tab-header';
* @docs-private
*/
@Directive()
// tslint:disable-next-line:class-name
export abstract class _MatTabHeaderBase extends MatPaginatedTabHeader implements
AfterContentChecked, AfterContentInit, AfterViewInit, OnDestroy {

Expand Down
2 changes: 0 additions & 2 deletions src/material/tabs/tab-nav-bar/tab-nav-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {startWith, takeUntil} from 'rxjs/operators';
* @docs-private
*/
@Directive()
// tslint:disable-next-line:class-name
export abstract class _MatTabNavBase extends MatPaginatedTabHeader implements AfterContentChecked,
AfterContentInit, OnDestroy {

Expand Down Expand Up @@ -192,7 +191,6 @@ const _MatTabLinkMixinBase:

/** Base class with all of the `MatTabLink` functionality. */
@Directive()
// tslint:disable-next-line:class-name
export class _MatTabLinkBase extends _MatTabLinkMixinBase implements AfterViewInit, OnDestroy,
CanDisable, CanDisableRipple, HasTabIndex, RippleTarget, FocusableOption {

Expand Down
28 changes: 28 additions & 0 deletions tools/tslint-rules/symbolNamingRule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as ts from 'typescript';
import * as Lint from 'tslint';

/** Lint rule that checks the names of classes and interfaces against a pattern. */
export class Rule extends Lint.Rules.AbstractRule {
/** Pattern that we should validate against. */
private _pattern: RegExp;

constructor(options: Lint.IOptions) {
super(options);
this._pattern = new RegExp(options.ruleArguments[0] || '.*');
}

apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithFunction(sourceFile, checkSourceFile, this._pattern);
}
}

function checkSourceFile(context: Lint.WalkContext<RegExp>) {
context.sourceFile.forEachChild(function walk(node) {
if ((ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node) ||
ts.isTypeAliasDeclaration(node)) && node.name && !context.options.test(node.name.text)) {
context.addFailureAtNode(node.name, `Symbol name must match pattern ${context.options}`);
}

node.forEachChild(walk);
});
}
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// TSLint now shows warnings if types for properties are inferred. This rule needs to be
// disabled because all properties need to have explicit types set to work for Dgeni.
"no-inferrable-types": false,
"class-name": true,
"comment-format": [
true,
"check-space"
Expand Down Expand Up @@ -143,6 +142,7 @@
"member-naming": [true, {
"private": "^_"
}],
"symbol-naming": [true, "^_?[A-Z][a-zA-Z0-9]*$"],
"validate-decorators": [true, {
"Component": {
"argument": 0,
Expand Down