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

fix(rule): fix bugs in no-life-cycle-call rule #575

Merged
merged 2 commits into from Apr 25, 2018

Conversation

kevinbuhmann
Copy link
Contributor

@kevinbuhmann kevinbuhmann commented Apr 24, 2018

Changes

  • fix(rule): allow super lifecycle calls (f862454)

See #573. super.ngOnInit(), etc. should be allowed by the no-life-cycle-call rule.

  • fix(rule): prevent error when parent class node does not exist (3e355c4)

The no-life-cycle-call rule would error with a "cannot read name of undefined" error when the life cycle call was not in a class. In my case, there was test code calling fixture.componentInstance.ngOnChanges() and the rule would crash.

(Original commits: e9f4d23...dd63e7f)

@mgechev
Copy link
Owner

mgechev commented Apr 25, 2018

@kevinphelps thanks for the fix of #454.

There seems to be a failure in Travis.

@rafaelss95
Copy link
Collaborator

rafaelss95 commented Apr 25, 2018

I think you should only fix the no-life-cycle-call on this PR and make a separate one for build changes.

@kevinbuhmann
Copy link
Contributor Author

I'm going to remove build change to see if it fixes the Travis build. It's in this PR simply because I needed for local development and I pushed it along with my fixes.

@@ -14,7 +14,8 @@ export class Rule extends Lint.Rules.AbstractRule {
typescriptOnly: true,
};

static FAILURE_STRING: string = 'Avoid explicitly calls to lifecycle hooks in class "%s"';
static FAILURE_STRING_FOR_CLASS: string = 'Avoid explicit calls to lifecycle hooks in class "%s".';
static FAILURE_STRING: string = 'Avoid explicit calls to lifecycle hooks.';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can only have one FAILURE_STRING (and let's remove the unnecessary :string):

static FAILURE_STRING = 'Avoid explicit calls to lifecycle hooks.';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can have more than one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't mention that it's impossible. I'm suggesting that you remove and keep only one failure. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove the type annotation. I kept it because it was already there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I misread. But I wanted to keep the class name when it's available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated this.

@@ -49,19 +50,35 @@ export class ExpressionCallMetadataWalker extends NgWalker {
}

private validateCallExpression(node: ts.CallExpression): void {
const name = (node.expression as any).name;
const name = ts.isPropertyAccessExpression(node.expression) ? node.expression.name : undefined;
const expression = ts.isPropertyAccessExpression(node.expression) ? node.expression.expression : undefined;

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: extra new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally separated these variable declarations for readability. Source node info vs. rule logic checks.

return;
}

let currentNode = node as any;
let failureString = Rule.FAILURE_STRING;

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: extra new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally separated the if block with blank lines for readability.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't mark the if block, but the block between let and const variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove if it violates the project's code conventions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nah, it's just a nit. :)

@kevinbuhmann kevinbuhmann force-pushed the lifecycle-call-super branch 3 times, most recently from 624f55e to f3d0f31 Compare April 25, 2018 02:41
Copy link
Owner

@mgechev mgechev left a comment

Choose a reason for hiding this comment

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

LGTM! Sorry for the delayed merge.

@mgechev mgechev merged commit 4415cc2 into mgechev:master Apr 25, 2018
@kevinbuhmann kevinbuhmann deleted the lifecycle-call-super branch April 25, 2018 20:38
@kevinbuhmann
Copy link
Contributor Author

Thanks!

@mgechev
Copy link
Owner

mgechev commented Apr 25, 2018

Would you look into the failing build? Looks prettier related.

@kevinbuhmann
Copy link
Contributor Author

kevinbuhmann commented Apr 25, 2018

Yeah, I can in a bit. Just need to reformat my changes since the prettier PR was merged first.

@kevinbuhmann
Copy link
Contributor Author

@mgechev: See #578.

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

3 participants