diff options
author | Daniel Bevenius <daniel.bevenius@gmail.com> | 2017-06-20 08:30:47 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2017-08-30 18:03:51 -0300 |
commit | c7dda4925d2441b4f1d7158a6b63aa271eeb40c4 (patch) | |
tree | 4becd48b67712e8369dbe1eb0cc30290bc8979ad /tools/eslint-rules | |
parent | 50ebac112429c4a8cf9438dac9d832530465d2bb (diff) | |
download | android-node-v8-c7dda4925d2441b4f1d7158a6b63aa271eeb40c4.tar.gz android-node-v8-c7dda4925d2441b4f1d7158a6b63aa271eeb40c4.tar.bz2 android-node-v8-c7dda4925d2441b4f1d7158a6b63aa271eeb40c4.zip |
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: https://github.com/nodejs/node/pull/13813
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Diffstat (limited to 'tools/eslint-rules')
-rw-r--r-- | tools/eslint-rules/inspector-check.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/eslint-rules/inspector-check.js b/tools/eslint-rules/inspector-check.js new file mode 100644 index 0000000000..f225b34cb6 --- /dev/null +++ b/tools/eslint-rules/inspector-check.js @@ -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) + }; +}; |