mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
2f9c9eebb4
Remove unused arguments from function invocations in ESLint custom rules. PR-URL: https://github.com/nodejs/node/pull/26668 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
62 lines
1.7 KiB
JavaScript
62 lines
1.7 KiB
JavaScript
/**
|
|
* @fileoverview Check that common.skipIfInspectorDisabled is used if
|
|
* the inspector module is required.
|
|
* @author Daniel Bevenius <daniel.bevenius@gmail.com>
|
|
*/
|
|
'use strict';
|
|
|
|
const utils = require('./rules-utils.js');
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
const msg = 'Please add a skipIfInspectorDisabled() call to allow this ' +
|
|
'test to be skipped when Node is built \'--without-inspector\'.';
|
|
|
|
module.exports = function(context) {
|
|
const missingCheckNodes = [];
|
|
let commonModuleNode = null;
|
|
let hasInspectorCheck = false;
|
|
|
|
function testInspectorUsage(context, node) {
|
|
if (utils.isRequired(node, ['inspector'])) {
|
|
missingCheckNodes.push(node);
|
|
}
|
|
|
|
if (utils.isCommonModule(node)) {
|
|
commonModuleNode = node;
|
|
}
|
|
}
|
|
|
|
function checkMemberExpression(context, node) {
|
|
if (utils.usesCommonProperty(node, ['skipIfInspectorDisabled'])) {
|
|
hasInspectorCheck = true;
|
|
}
|
|
}
|
|
|
|
function reportIfMissing(context) {
|
|
if (!hasInspectorCheck) {
|
|
missingCheckNodes.forEach((node) => {
|
|
context.report({
|
|
node,
|
|
message: msg,
|
|
fix: (fixer) => {
|
|
if (commonModuleNode) {
|
|
return fixer.insertTextAfter(
|
|
commonModuleNode,
|
|
'\ncommon.skipIfInspectorDisabled();'
|
|
);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
'CallExpression': (node) => testInspectorUsage(context, node),
|
|
'MemberExpression': (node) => checkMemberExpression(context, node),
|
|
'Program:exit': () => reportIfMissing(context)
|
|
};
|
|
};
|