summaryrefslogtreecommitdiff
path: root/tools/eslint-rules
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2017-03-24 12:37:59 -0700
committerJames M Snell <jasnell@gmail.com>2017-03-26 12:47:21 -0700
commit20b18236de3dff8a14ef8af8eed2c763f2d46f86 (patch)
treef69d4c0c06b16e314cde91b19db3939baec8c808 /tools/eslint-rules
parent4f2e372716714ed030cb5ba6e67107b913f15343 (diff)
downloadandroid-node-v8-20b18236de3dff8a14ef8af8eed2c763f2d46f86.tar.gz
android-node-v8-20b18236de3dff8a14ef8af8eed2c763f2d46f86.tar.bz2
android-node-v8-20b18236de3dff8a14ef8af8eed2c763f2d46f86.zip
tools: add rule prefering common.mustNotCall()
Prefer using `common.mustNotCall()` over `common.mustCall(fn, 0)` PR-URL: https://github.com/nodejs/node/pull/12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Diffstat (limited to 'tools/eslint-rules')
-rw-r--r--tools/eslint-rules/prefer-common-mustnotcall.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/eslint-rules/prefer-common-mustnotcall.js b/tools/eslint-rules/prefer-common-mustnotcall.js
new file mode 100644
index 0000000000..6bc428ed59
--- /dev/null
+++ b/tools/eslint-rules/prefer-common-mustnotcall.js
@@ -0,0 +1,39 @@
+/**
+ * @fileoverview Prefer common.mustNotCall(msg) over common.mustCall(fn, 0)
+ * @author James M Snell <jasnell@gmail.com>
+ */
+'use strict';
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+const msg = 'Please use common.mustNotCall(msg) instead of ' +
+ 'common.mustCall(fn, 0) or common.mustCall(0).';
+
+function isCommonMustCall(node) {
+ return node &&
+ node.callee &&
+ node.callee.object &&
+ node.callee.object.name === 'common' &&
+ node.callee.property &&
+ node.callee.property.name === 'mustCall';
+}
+
+function isArgZero(argument) {
+ return argument &&
+ typeof argument.value === 'number' &&
+ argument.value === 0;
+}
+
+module.exports = function(context) {
+ return {
+ CallExpression(node) {
+ if (isCommonMustCall(node) &&
+ (isArgZero(node.arguments[0]) || // catch common.mustCall(0)
+ isArgZero(node.arguments[1]))) { // catch common.mustCall(fn, 0)
+ context.report(node, msg);
+ }
+ }
+ };
+};