Skip to content

Commit

Permalink
tools: add eslint rule for inspector checking
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
danbev authored and MylesBorins committed Sep 10, 2017
1 parent b41ee10 commit 25fd563
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ rules:
prefer-assert-methods: error
prefer-common-mustnotcall: error
crypto-check: error
inspector-check: error
## common module is mandatory in tests
required-modules: [error, common]
43 changes: 43 additions & 0 deletions tools/eslint-rules/inspector-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @fileoverview Check that common.skipIfInspectorDisabled is used if
* the inspector module is required.
* @author Daniel Bevenius <[email protected]>
*/
'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)
};
};

0 comments on commit 25fd563

Please sign in to comment.