Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 8 additions & 3 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,14 @@ assert.equal(util.inspect(value), '{ a: [Circular] }');

// Array with dynamic properties
value = [1, 2, 3];
value.__defineGetter__('growingLength', function() {
this.push(true); return this.length;
});
Object.defineProperty(
value,
'growingLength',
{
enumerable: true,
get: () => { this.push(true); return this.length; }
}
);
assert.equal(util.inspect(value), '[ 1, 2, 3, growingLength: [Getter] ]');

// Function with properties
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!node.computed... so obj['__defineGetter__'] = getter is the escape hatch? =)

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.`);
}
}
}
};
}
};