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 require-super-in-init rule to improve performance #928

Merged
merged 1 commit into from Sep 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 27 additions & 17 deletions lib/rules/require-super-in-init.js
Expand Up @@ -88,28 +88,38 @@ module.exports = {
};

return {
CallExpression(node) {
Property(node) {
if (
!ember.isEmberComponent(context, node) &&
!ember.isEmberController(context, node) &&
!ember.isEmberRoute(context, node) &&
!ember.isEmberMixin(context, node) &&
!ember.isEmberService(context, node)
!types.isIdentifier(node.key) ||
node.key.name !== 'init' ||
!types.isFunctionExpression(node.value)
) {
// Not init function.
return;
}

const initProperty = ember
.getModuleProperties(node)
.find((property) => types.isProperty(property) && property.key.name === 'init');

if (initProperty && types.isFunctionExpression(initProperty.value)) {
const initPropertyBody = initProperty.value.body.body;
const nodes = findStmtNodes(initPropertyBody);
const hasSuper = checkForSuper(nodes);
if (!hasSuper) {
report(initProperty);
}
const parentParent = node.parent.parent;
if (!types.isCallExpression(node.parent.parent)) {
// Not inside potential Ember class.
return;
}

if (
!ember.isEmberComponent(context, parentParent) &&
!ember.isEmberController(context, parentParent) &&
!ember.isEmberRoute(context, parentParent) &&
!ember.isEmberMixin(context, parentParent) &&
!ember.isEmberService(context, parentParent)
) {
// Not inside an Ember class.
return;
}

const initPropertyBody = node.value.body.body;
const nodes = findStmtNodes(initPropertyBody);
const hasSuper = checkForSuper(nodes);
if (!hasSuper) {
report(node);
}
},
};
Expand Down