summaryrefslogtreecommitdiff
path: root/tools/eslint-rules
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2016-03-16 10:37:35 -0700
committerJames M Snell <jasnell@gmail.com>2016-03-18 17:05:18 -0700
commit9e30129fa7dd75389bcd178ae5f65482438d6978 (patch)
treeed6e5c54bb84b5d73c36161103ecc47fae820f90 /tools/eslint-rules
parent089bef0a811e3eba7a309da687e90499ec06ce63 (diff)
downloadandroid-node-v8-9e30129fa7dd75389bcd178ae5f65482438d6978.tar.gz
android-node-v8-9e30129fa7dd75389bcd178ae5f65482438d6978.tar.bz2
android-node-v8-9e30129fa7dd75389bcd178ae5f65482438d6978.zip
tools: add buffer-constructor eslint rule
Now that the Buffer.alloc, allocUnsafe, and from methods have landed, add a linting rule that requires their use within lib. Tests and benchmarks are explicitly excluded by the rule. PR-URL: https://github.com/nodejs/node/pull/5740 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'tools/eslint-rules')
-rw-r--r--tools/eslint-rules/buffer-constructor.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/eslint-rules/buffer-constructor.js b/tools/eslint-rules/buffer-constructor.js
new file mode 100644
index 0000000000..938598e8db
--- /dev/null
+++ b/tools/eslint-rules/buffer-constructor.js
@@ -0,0 +1,25 @@
+/**
+ * @fileoverview Require use of new Buffer constructor methods in lib
+ * @author James M Snell
+ */
+'use strict';
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+const msg = 'Use of the Buffer() constructor has been deprecated. ' +
+ 'Please use either Buffer.alloc(), Buffer.allocUnsafe(), ' +
+ 'or Buffer.from()';
+
+function test(context, node) {
+ if (node.callee.name === 'Buffer') {
+ context.report(node, msg);
+ }
+}
+
+module.exports = function(context) {
+ return {
+ 'NewExpression': (node) => test(context, node),
+ 'CallExpression': (node) => test(context, node)
+ };
+};