Skip to content

Commit

Permalink
fix: tweak autofix for require-super-in-init rule
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Sep 25, 2020
1 parent b4157c8 commit fed94c4
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 81 deletions.
13 changes: 4 additions & 9 deletions lib/rules/require-super-in-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,10 @@ module.exports = {
const replacement = isNativeClass
? `super.${lifecycleHookName}(...arguments);`
: 'this._super(...arguments);';
if (node.value.body.body.length > 0) {
// Function has at least one statement in it so just insert before that.
return fixer.insertTextBefore(node.value.body.body[0], `${replacement}\n`);
} else {
// Function is empty so insert after curly brace.
const sourceCode = context.getSourceCode();
const startOfBlockStatement = sourceCode.getFirstToken(node.value.body);
return fixer.insertTextAfter(startOfBlockStatement, replacement);
}
// Insert right after function curly brace.
const sourceCode = context.getSourceCode();
const startOfBlockStatement = sourceCode.getFirstToken(node.value.body);
return fixer.insertTextAfter(startOfBlockStatement, `\n${replacement}`);
},
});
}
Expand Down
Loading

0 comments on commit fed94c4

Please sign in to comment.