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.

prefer-reflect: Reflect.deleteProperty considered harmful

See original GitHub issue

The rule tells that:

Reflect.deleteProperty effectively deprecates delete keyword

Putting conciseness of delete and “Map should be used instead” points aside, given strict mode enabled and considering only property references, Reflect.deleteProperty returns result of [[Delete]] call (boolean), but does not throw on false, unlike delete operator does.

Throwing if deletion fails (non-configurable property, Proxy trap) is what modern JavaScript does. Not throwing causes confusion.

Quoting @nzakas on prefer-reflect:

This rule should warn only for direct replacements.

I think Reflect.deleteProperty should be removed from the rule.

EDIT: same goes for preventExtensions and setPrototypeOf.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

4reactions
nzakascommented, Oct 18, 2016

A little bit more background:

I think we may have moved too fast in creating this rule, and I take responsibility for that. I don’t think any of us fully understood the purpose of Reflect and why those methods exist as separate from their Object equivalents. Now that I do understand, I feel like this entire rule is misguided, as the Reflect methods are not actually intended to replace the Object counterparts, but rather as low-level primitives to be used with proxies in order to replicate the default behavior of various previously existing functionality.

So, while I’m not opposed to updating the documentation, I’m more of the mind that this rule is does more harm than good by implying a relationship between Reflect and Object that doesn’t necessarily exist.

3reactions
nzakascommented, Sep 27, 2016

That’s why I’m saying maybe the whole rule should be removed. I don’t think it makes sense to just remove a subset.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reflect.deleteProperty() - JavaScript - MDN Web Docs
It returns a Boolean indicating whether or not the property was successfully deleted. It is almost identical to the non-strict delete operator.
Read more >
Metaprogramming in ES6: Part 2 - Reflect - Keith Cirkel
Reflect is all about Reflection through introspection - used to discover very low level information about your code.
Read more >
Metaprogramming in ES6: Part 2 - Reflect | PHPnews.io
Reflect is all about Reflection through introspection - used to discover very low ... deleteProperty will, surprise surprise, delete a property off of...
Read more >
What is Reflect.deleteProperty() in JavaScript? - Educative.io
The Reflect.deleteProperty() is used to delete the property of an object. Syntax. Reflect.deleteProperty(targetObj, propertyName). Arguments.
Read more >
ESLint v3.9.0 - Qiita
prefer-reflect ... GOOD let a = /this is a long regular expression/ //✘ BAD let b = "this is a long ... deleteProperty...
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