Skip to content
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

Merged
merged 4 commits into from Mar 27, 2019
Merged

refactor(rule): rework prefer-inline-decorator to accept options #794

merged 4 commits into from Mar 27, 2019

Conversation

rafaelss95
Copy link
Collaborator

  • The rule prefer-inline-decorator:
    • Doesn't report failures for non call expression decorators (Actually, the culpirit is the utility function getDecoratorName, which throws an error if you try to get a name of a decorator that isn't a call expression);
    • Doesn't report failures for getters, setters, parameters and parameters properties. To handle this (separately), options are being added. Users can disable according to their project standards.
    • Its fix is unsafe. If the 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 the hasFix option, because it would be a pain to handle all possible cases correctly.

@mgechev
Copy link
Owner

mgechev commented Mar 23, 2019

This will require more time for review. I'll try to push it sometime next week.

return super.isEnabled() && this.areOptionsValid();
}

private areOptionsValid(): boolean {
Copy link
Owner

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?

Copy link
Collaborator Author

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your opinion about it 👆 ? @wKoza @mgechev

Copy link
Owner

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.

optionKey: OptionKeys
): ReadonlyArray<string> => {
return decorators
.map(decorator => getDecoratorName(decorator))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just getDecoratorName

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@mgechev mgechev merged commit a76ebbc into mgechev:master Mar 27, 2019
@rafaelss95 rafaelss95 deleted the refactor/prefer-inline-decorator branch March 28, 2019 03:28
@rafaelss95 rafaelss95 removed the blocked label Apr 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants