prefer-reflect: Reflect.deleteProperty considered harmful
See original GitHub issueThe rule tells that:
Reflect.deleteProperty
effectively deprecatesdelete
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:
- Created 7 years ago
- Reactions:1
- Comments:20 (20 by maintainers)
Top 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 >
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 Free
Top 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
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 theirObject
equivalents. Now that I do understand, I feel like this entire rule is misguided, as theReflect
methods are not actually intended to replace theObject
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
andObject
that doesn’t necessarily exist.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.