question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warn about wrong Object.defineProperty usage

See original GitHub issue

Please 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, May 5, 2018

This should also then warn about the second argument to Object.create?

0reactions
eslint-deprecated[bot]commented, Dec 11, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found