2017-06-20 08:30:47 +02:00
|
|
|
/**
|
|
|
|
* @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 ' +
|
2018-04-27 21:57:52 +02:00
|
|
|
'test to be skipped when Node is built \'--without-inspector\'.';
|
2017-06-20 08:30:47 +02:00
|
|
|
|
2021-10-10 03:20:06 +02:00
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
fixable: 'code',
|
|
|
|
},
|
|
|
|
create(context) {
|
|
|
|
const missingCheckNodes = [];
|
|
|
|
let commonModuleNode = null;
|
|
|
|
let hasInspectorCheck = false;
|
2017-06-20 08:30:47 +02:00
|
|
|
|
2021-10-10 03:20:06 +02:00
|
|
|
function testInspectorUsage(context, node) {
|
|
|
|
if (utils.isRequired(node, ['inspector'])) {
|
|
|
|
missingCheckNodes.push(node);
|
|
|
|
}
|
2017-10-31 22:52:31 +01:00
|
|
|
|
2021-10-10 03:20:06 +02:00
|
|
|
if (utils.isCommonModule(node)) {
|
|
|
|
commonModuleNode = node;
|
|
|
|
}
|
2017-10-31 22:52:31 +01:00
|
|
|
}
|
2017-06-20 08:30:47 +02:00
|
|
|
|
2021-10-10 03:20:06 +02:00
|
|
|
function checkMemberExpression(context, node) {
|
|
|
|
if (utils.usesCommonProperty(node, ['skipIfInspectorDisabled'])) {
|
|
|
|
hasInspectorCheck = true;
|
|
|
|
}
|
2017-06-20 08:30:47 +02:00
|
|
|
}
|
|
|
|
|
2021-10-10 03:20:06 +02:00
|
|
|
function reportIfMissing(context) {
|
|
|
|
if (!hasInspectorCheck) {
|
|
|
|
missingCheckNodes.forEach((node) => {
|
|
|
|
context.report({
|
|
|
|
node,
|
|
|
|
message: msg,
|
|
|
|
fix: (fixer) => {
|
|
|
|
if (commonModuleNode) {
|
|
|
|
return fixer.insertTextAfter(
|
|
|
|
commonModuleNode,
|
2022-12-18 17:39:39 +01:00
|
|
|
'\ncommon.skipIfInspectorDisabled();',
|
2021-10-10 03:20:06 +02:00
|
|
|
);
|
|
|
|
}
|
2022-12-18 17:39:39 +01:00
|
|
|
},
|
2021-10-10 03:20:06 +02:00
|
|
|
});
|
2017-10-31 22:52:31 +01:00
|
|
|
});
|
2021-10-10 03:20:06 +02:00
|
|
|
}
|
2017-06-20 08:30:47 +02:00
|
|
|
}
|
|
|
|
|
2021-10-10 03:20:06 +02:00
|
|
|
return {
|
|
|
|
'CallExpression': (node) => testInspectorUsage(context, node),
|
|
|
|
'MemberExpression': (node) => checkMemberExpression(context, node),
|
2022-12-18 17:39:39 +01:00
|
|
|
'Program:exit': () => reportIfMissing(context),
|
2021-10-10 03:20:06 +02:00
|
|
|
};
|
2022-12-18 17:39:39 +01:00
|
|
|
},
|
2020-08-01 20:22:51 +02:00
|
|
|
};
|