-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <jasnell@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
- Loading branch information
1 parent
1d97ff4
commit 87e44d8
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}; | ||
}; |