Warn about wrong Object.defineProperty usage
See original GitHub issuePlease describe what the rule should do:
The rule should warn about faulty uses of Object.defineProperty
and Object.defineProperties
. It is not possible to combine a value
property with a getter or setter or to combine the writable
property with a getter or setter.
What category of rule is this? (place an “X” next to just one item)
[ ] Enforces code style [x] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
'use strict';
const obj = {};
Object.defineProperty(obj, 'foo', {
writable: true,
get() {}
});
Object.defineProperty(obj, 'foo', {
value: 'foo',
get() {}
});
Why should this rule be included in ESLint (instead of a plugin)?
It provides an early feedback for a mistake. Especially if code has no tests, this might cause issues in some applications where an error is thrown at runtime.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Object.defineProperty(obj, "prop", desc) behaving strangely
The error isn't coming from dataDesc.writable = true; , it's coming from Object.defineProperty(o, "name", dataDesc); ...which is correct, ...
Read more >Object.defineProperty() - JavaScript - MDN Web Docs
A TypeError is thrown when attempts are made to change non-configurable property attributes (except value and writable , if permitted), except ...
Read more >Property flags and descriptors - The Modern JavaScript Tutorial
To change the flags, we can use Object.defineProperty. The syntax is: Object.defineProperty(obj, propertyName, descriptor).
Read more >JavaScript Object Define Properties Method - Dot Net Tutorials
This method will use their default values. That means Properties created using the method Object.defineProperties() have an enumerable flag set to false by ......
Read more >TypeError: "x" is read-only
What went wrong? ... defineProperty() or Object.freeze() . 'use strict'; var obj = Object.freeze({name: 'Elsa', score: 157}); obj.score = 0; ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This should also then warn about the second argument to Object.create?
Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.
Thanks for contributing to ESLint and we appreciate your understanding.