diff options
author | James M Snell <jasnell@gmail.com> | 2016-03-16 10:37:35 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-03-18 17:05:18 -0700 |
commit | 9e30129fa7dd75389bcd178ae5f65482438d6978 (patch) | |
tree | ed6e5c54bb84b5d73c36161103ecc47fae820f90 /tools | |
parent | 089bef0a811e3eba7a309da687e90499ec06ce63 (diff) | |
download | node-new-9e30129fa7dd75389bcd178ae5f65482438d6978.tar.gz |
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')
-rw-r--r-- | tools/eslint-rules/buffer-constructor.js | 25 |
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) + }; +}; |