Skip to content

Commit 87e44d8

Browse files
danbevMylesBorins
authored andcommitted
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: #13813 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Teddy Katz <[email protected]>
1 parent 1d97ff4 commit 87e44d8

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

test/.eslintrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ rules:
1111
prefer-assert-methods: error
1212
prefer-common-mustnotcall: error
1313
crypto-check: error
14+
inspector-check: error
1415
## common module is mandatory in tests
1516
required-modules: [error, common]

tools/eslint-rules/inspector-check.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @fileoverview Check that common.skipIfInspectorDisabled is used if
3+
* the inspector module is required.
4+
* @author Daniel Bevenius <[email protected]>
5+
*/
6+
'use strict';
7+
8+
const utils = require('./rules-utils.js');
9+
10+
//------------------------------------------------------------------------------
11+
// Rule Definition
12+
//------------------------------------------------------------------------------
13+
const msg = 'Please add a skipIfInspectorDisabled() call to allow this ' +
14+
'test to be skippped when Node is built \'--without-inspector\'.';
15+
16+
module.exports = function(context) {
17+
var usesInspector = false;
18+
var hasInspectorCheck = false;
19+
20+
function testInspectorUsage(context, node) {
21+
if (utils.isRequired(node, ['inspector'])) {
22+
usesInspector = true;
23+
}
24+
}
25+
26+
function checkMemberExpression(context, node) {
27+
if (utils.usesCommonProperty(node, ['skipIfInspectorDisabled'])) {
28+
hasInspectorCheck = true;
29+
}
30+
}
31+
32+
function reportIfMissing(context, node) {
33+
if (usesInspector && !hasInspectorCheck) {
34+
context.report(node, msg);
35+
}
36+
}
37+
38+
return {
39+
'CallExpression': (node) => testInspectorUsage(context, node),
40+
'MemberExpression': (node) => checkMemberExpression(context, node),
41+
'Program:exit': (node) => reportIfMissing(context, node)
42+
};
43+
};

0 commit comments

Comments
 (0)