From 21b53fe0125caaf16025f2b90624a882f49375f0 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 15 May 2016 10:01:44 -0700 Subject: [PATCH] tools: disallow deprecated define getter/setter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/6774 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Johan Bergström Refs: https://github.com/nodejs/node/pull/6768 --- .eslintrc | 1 + .../no-definegetter-definesetter.js | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tools/eslint-rules/no-definegetter-definesetter.js diff --git a/.eslintrc b/.eslintrc index 7ab13d422f4753..f9b0ef3b015f77 100644 --- a/.eslintrc +++ b/.eslintrc @@ -94,6 +94,7 @@ rules: assert-fail-single-argument: 2 new-with-error: [2, "Error", "RangeError", "TypeError", "SyntaxError", "ReferenceError"] no-deepEqual: 2 + no-definegetter-definesetter: 2 # Global scoped method and vars globals: diff --git a/tools/eslint-rules/no-definegetter-definesetter.js b/tools/eslint-rules/no-definegetter-definesetter.js new file mode 100644 index 00000000000000..3de010f47f203c --- /dev/null +++ b/tools/eslint-rules/no-definegetter-definesetter.js @@ -0,0 +1,32 @@ +/** + * @fileoverview Rule to flag usage of __defineGetter__ and __defineSetter__ + * @author Rich Trott + */ + +'use strict'; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = { + create: function(context) { + const disallowed = ['__defineGetter__', '__defineSetter__']; + + return { + MemberExpression: function(node) { + var prop; + if (node.property) { + if (node.property.type === 'Identifier' && !node.computed) { + prop = node.property.name; + } else if (node.property.type === 'Literal') { + prop = node.property.value; + } + if (disallowed.includes(prop)) { + context.report(node, `The ${prop} property is deprecated.`); + } + } + } + }; + } +};