Skip to content

build: enable coercion-types rule and fix leftover cases #17609

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
Nov 4, 2019
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
2 changes: 2 additions & 0 deletions src/dev-app/example/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ export class Example implements OnInit {
this._elementRef.nativeElement.appendChild(new exampleElementCtor(this._injector));
this.title = EXAMPLE_COMPONENTS[this.id] ? EXAMPLE_COMPONENTS[this.id].title : '';
}

static ngAcceptInputType_showLabel: boolean | string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ export class CustomStepper extends CdkStepper {
onClick(index: number): void {
this.selectedIndex = index;
}

// These properties are required so that the Ivy template type checker in strict mode knows
// what kind of values are accepted by the `linear` and `selectedIndex` inputs which
// are inherited from `CdkStepper`.
static ngAcceptInputType_linear: boolean | string;
static ngAcceptInputType_selectedIndex: number | string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h2 class="example-h2">Result</h2>
[min]="min"
[step]="step"
[thumbLabel]="thumbLabel"
[tickInterval]="tickInterval"
[tickInterval]="getSliderTickInterval()"
[(ngModel)]="value"
[vertical]="vertical">
</mat-slider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {coerceNumberProperty} from '@angular/cdk/coercion';
import {Component} from '@angular/core';

/**
Expand All @@ -20,12 +19,9 @@ export class SliderConfigurableExample {
thumbLabel = false;
value = 0;
vertical = false;
tickInterval = 1;

get tickInterval(): number | 'auto' {
return this.showTicks ? (this.autoTicks ? 'auto' : this._tickInterval) : 0;
getSliderTickInterval(): number | 'auto' {
return this.showTicks ? (this.autoTicks ? 'auto' : this.tickInterval) : 0;
}
set tickInterval(value) {
this._tickInterval = coerceNumberProperty(value);
}
private _tickInterval = 1;
}
1 change: 0 additions & 1 deletion src/material/paginator/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,4 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
static ngAcceptInputType_hidePageSize: boolean | string;
static ngAcceptInputType_showFirstLastButtons: boolean | string;
static ngAcceptInputType_disabled: boolean | string;

}
10 changes: 7 additions & 3 deletions tools/tslint-rules/coercionTypesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ class Walker extends Lint.RuleWalker {
return prop.name && ts.isIdentifier(prop.name) && prop.name.text === 'selector';
}) : null;

return !!selector && ts.isPropertyAssignment(selector) && ts.isIdentifier(selector.name) &&
!selector.name.text.startsWith('do-not-use-abstract-');
return !!selector && ts.isPropertyAssignment(selector) &&
(ts.isStringLiteral(selector.initializer) ||
ts.isNoSubstitutionTemplateLiteral(selector.initializer)) &&
!selector.initializer.text.startsWith('do-not-use-abstract-');
}

return false;
Expand Down Expand Up @@ -180,7 +182,9 @@ function usesCoercion(setter: ts.SetAccessorDeclaration, coercionFunctions: Set<
coercionWasUsed = true;
}

if (!coercionWasUsed) {
// Don't check callback functions since coercion used
// inside them most-likely won't need to be declared.
if (!coercionWasUsed && !ts.isArrowFunction(node) && !ts.isFunctionExpression(node)) {
node.forEachChild(walk);
}
});
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"rxjs-imports": true,
"require-breaking-change-version": true,
"class-list-signatures": true,
"coercion-types": [false, // Disabled until #17528 gets in.
"coercion-types": [true,
["coerceBooleanProperty", "coerceCssPixelValue", "coerceNumberProperty"],
{
"CanDisable": ["disabled"],
Expand Down