mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build: fix custom lint rule throwing errors in IDE on invalid files (#13488)
Fixes errors being thrown by the decorator validation rule when run in an IDE. The errors can happen, because the rule is run for each key stroke and the user might not be done typing out the definition yet. The two cases where it was throwing were when a decorator is added without being called (e.g. `@Component class Something`) and when defining a new property that doesn't have an initializer yet (e.g. `@Component({selector})`).
This commit is contained in:
committed by
Andrew Seguin
parent
e0856645e0
commit
c4a422abad
@@ -58,8 +58,11 @@ class Walker extends Lint.RuleWalker {
|
||||
visitClassDeclaration(node: ts.ClassDeclaration) {
|
||||
if (this._enabled && node.decorators) {
|
||||
node.decorators
|
||||
.map(decorator => decorator.expression as any)
|
||||
.filter(expression => expression.arguments.length && expression.arguments[0].properties)
|
||||
.map(decorator => decorator.expression as ts.CallExpression)
|
||||
.filter(expression => {
|
||||
const args = expression.arguments;
|
||||
return args && args.length && (args[0] as ts.ObjectLiteralExpression).properties;
|
||||
})
|
||||
.forEach(expression => this._validatedDecorator(expression));
|
||||
}
|
||||
|
||||
@@ -80,11 +83,13 @@ class Walker extends Lint.RuleWalker {
|
||||
}
|
||||
|
||||
// Extract the property names and values.
|
||||
const props = decorator.arguments[0].properties.map((node: ts.PropertyAssignment) => ({
|
||||
name: node.name.getText(),
|
||||
value: node.initializer.getText(),
|
||||
node
|
||||
}));
|
||||
const props = decorator.arguments[0].properties
|
||||
.filter((node: ts.PropertyAssignment) => node.name && node.initializer)
|
||||
.map((node: ts.PropertyAssignment) => ({
|
||||
name: node.name.getText(),
|
||||
value: node.initializer.getText(),
|
||||
node
|
||||
}));
|
||||
|
||||
// Find all of the required rule properties that are missing from the decorator.
|
||||
const missing = Object.keys(rules.required)
|
||||
|
||||
Reference in New Issue
Block a user