mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
ee0b44fd93
This commit adds the meta.fixable property to all fixable ESLint rules. This is required as of ESLint 7.6.0. PR-URL: https://github.com/nodejs/node/pull/34589 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
'use strict';
|
|
const { isCommonModule } = require('./rules-utils.js');
|
|
|
|
function isAsyncIIFE(node) {
|
|
const { callee: { type, async } } = node;
|
|
const types = ['FunctionExpression', 'ArrowFunctionExpression'];
|
|
return types.includes(type) && async;
|
|
}
|
|
|
|
const message =
|
|
'The result of an immediately-invoked async function needs to be used ' +
|
|
'(e.g. with `.then(common.mustCall())`)';
|
|
|
|
module.exports = {
|
|
meta: {
|
|
fixable: 'code'
|
|
},
|
|
create: function(context) {
|
|
let hasCommonModule = false;
|
|
return {
|
|
CallExpression: function(node) {
|
|
if (isCommonModule(node) && node.parent.type === 'VariableDeclarator') {
|
|
hasCommonModule = true;
|
|
}
|
|
|
|
if (!isAsyncIIFE(node)) return;
|
|
if (node.parent && node.parent.type === 'ExpressionStatement') {
|
|
context.report({
|
|
node,
|
|
message,
|
|
fix: (fixer) => {
|
|
if (hasCommonModule)
|
|
return fixer.insertTextAfter(node, '.then(common.mustCall())');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
}
|
|
};
|