Skip to content

Commit

Permalink
tools: disallow deprecated define getter/setter
Browse files Browse the repository at this point in the history
PR-URL: nodejs#6774
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Refs: nodejs#6768
  • Loading branch information
Trott committed May 20, 2016
1 parent 37a5a1c commit 21b53fe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 32 additions & 0 deletions tools/eslint-rules/no-definegetter-definesetter.js
Original file line number Diff line number Diff line change
@@ -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.`);
}
}
}
};
}
};

0 comments on commit 21b53fe

Please sign in to comment.