-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Conversation
This rule enforces calling this._super(...arguments) inside init lifecycle hooks. This rule will fire inside Components, Routes, Controllers and Mixins.
docs/rules/call-super-in-init.md
Outdated
@@ -0,0 +1,24 @@ | |||
## Call _super in init lifecycle hooks | |||
|
|||
### Rule name: `call-super-in-init` |
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.
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?
lib/rules/call-super-in-init.js
Outdated
docs: { | ||
description: 'Enforces super calls in init hooks', | ||
category: 'General', | ||
recommended: true |
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.
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.
lib/rules/call-super-in-init.js
Outdated
const fnExpressions = utils.findNodes(initPropertyBody, 'ExpressionStatement'); | ||
|
||
const hasSuper = fnExpressions.some((fnExpression) => { | ||
const fnCallee = fnExpression.expression.callee; |
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.
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
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 job 👍
As discussed in #82, I've added a new rule to make sure
_super
is called whenever theinit
lifecycle hook is being overridden.