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

Add new "call-super-in-init" rule #122

Merged
merged 4 commits into from
Aug 7, 2017
Merged

Conversation

kevinkucharczyk
Copy link
Contributor

As discussed in #82, I've added a new rule to make sure _super is called whenever the init lifecycle hook is being overridden.

This rule enforces calling this._super(...arguments) inside init
lifecycle hooks. This rule will fire inside Components, Routes,
Controllers and Mixins.
@@ -0,0 +1,24 @@
## Call _super in init lifecycle hooks

### Rule name: `call-super-in-init`
Copy link
Member

Choose a reason for hiding this comment

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

I'd call this rule require-super-in-init, it's common way of naming eslint rules when you require something to be present. wdyt?

docs: {
description: 'Enforces super calls in init hooks',
category: 'General',
recommended: true
Copy link
Member

Choose a reason for hiding this comment

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

Let's set this to false so that we can make a minor release and we'll bulk set those recommendations later on in one major release.

const fnExpressions = utils.findNodes(initPropertyBody, 'ExpressionStatement');

const hasSuper = fnExpressions.some((fnExpression) => {
const fnCallee = fnExpression.expression.callee;
Copy link
Member

Choose a reason for hiding this comment

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

We should actually check if fnExpression.expression is CallExpression first.
This will work, but only due to additional check inside isMemberExpression, as the fnCallee in many cases will be undefined. Anyway we should not rely on the additional check inside isMemberExpression and be sure to pass the actual CallExpression there

@kevinkucharczyk kevinkucharczyk changed the title Add new "call-super-in-init-hooks" rule Add new "call-super-in-init" rule Aug 7, 2017
Copy link
Member

@michalsnik michalsnik left a comment

Choose a reason for hiding this comment

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

Good job 👍

@michalsnik michalsnik merged commit 4c4097d into master Aug 7, 2017
@michalsnik michalsnik deleted the 82-call-super-in-init-hooks branch August 7, 2017 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants