Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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).
  • Loading branch information
danbev committed Aug 23, 2017
commit 11dc3d09cc6b7dab6b2cb28f9c21e33f2c55a2e0
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 <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)
};
};