-
Notifications
You must be signed in to change notification settings - Fork 235
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
refactor(rule): rework prefer-inline-decorator to accept options #794
refactor(rule): rework prefer-inline-decorator to accept options #794
Conversation
This will require more time for review. I'll try to push it sometime next week. |
return super.isEnabled() && this.areOptionsValid(); | ||
} | ||
|
||
private areOptionsValid(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the options are not valid, we should probably throw an error. Wondering why we're unable to validate directly with the schema? Doesn't tslint do this already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... this is something that I was about to propose to you: use a lib (something like https://github.com/epoberezkin/ajv) to validate JSON schemas.
AFAIK, there's no in-built validation for tslint. All the checks are "hard-coded" in the isEnabled
method from https://github.com/palantir/tslint/blob/4b8bbf66b7fe7f49122debdeb02164e045b3a691/src/language/rule/abstractRule.ts#L49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON schema validation would be great. We do this in the CLI for builders' arguments.
src/preferInlineDecoratorRule.ts
Outdated
optionKey: OptionKeys | ||
): ReadonlyArray<string> => { | ||
return decorators | ||
.map(decorator => getDecoratorName(decorator)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just getDecoratorName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
prefer-inline-decorator
:getDecoratorName
, which throws an error if you try to get a name of adecorator
that isn't a call expression);fix
is applied to a property/method with multiple decorators, it just keeps the first decorator (from top) and aligns the property/method with this remaining decorator. I've opted to remove thehasFix
option, because it would be a pain to handle all possible cases correctly.