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).
  • Loading branch information
danbev committed Aug 23, 2017
1 parent b4924a3 commit 11dc3d0
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 11dc3d0

Please sign in to comment.