tools: add eslint rule for inspector checking
The motivation for this commit is to pick up early on missing checks for inspector support (when Node is built --without-inspector). PR-URL: https://github.com/nodejs/node/pull/13813 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
This commit is contained in:
parent
50ebac1124
commit
c7dda4925d
@ -11,5 +11,6 @@ rules:
|
|||||||
prefer-assert-methods: error
|
prefer-assert-methods: error
|
||||||
prefer-common-mustnotcall: error
|
prefer-common-mustnotcall: error
|
||||||
crypto-check: error
|
crypto-check: error
|
||||||
|
inspector-check: error
|
||||||
## common module is mandatory in tests
|
## common module is mandatory in tests
|
||||||
required-modules: [error, common]
|
required-modules: [error, common]
|
||||||
|
43
tools/eslint-rules/inspector-check.js
Normal file
43
tools/eslint-rules/inspector-check.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* @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 skippped when Node is built \'--without-inspector\'.';
|
||||||
|
|
||||||
|
module.exports = function(context) {
|
||||||
|
var usesInspector = false;
|
||||||
|
var hasInspectorCheck = false;
|
||||||
|
|
||||||
|
function testInspectorUsage(context, node) {
|
||||||
|
if (utils.isRequired(node, ['inspector'])) {
|
||||||
|
usesInspector = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkMemberExpression(context, node) {
|
||||||
|
if (utils.usesCommonProperty(node, ['skipIfInspectorDisabled'])) {
|
||||||
|
hasInspectorCheck = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportIfMissing(context, node) {
|
||||||
|
if (usesInspector && !hasInspectorCheck) {
|
||||||
|
context.report(node, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
'CallExpression': (node) => testInspectorUsage(context, node),
|
||||||
|
'MemberExpression': (node) => checkMemberExpression(context, node),
|
||||||
|
'Program:exit': (node) => reportIfMissing(context, node)
|
||||||
|
};
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user