Skip to content

Commit 2c152ff

Browse files
docs: note false positive Object.getOwnPropertyNames in prefer-reflect (#16317)
* docs: Add note to disclose inappropriate behavior Due to #16305 (comment) the falsely suggestion should be disclose to users to avoid further confusion See #16305 * docs(prefer-reflect): Remove the section about `getOwnPropertyNames` Make the document clean * docs: Apply suggestions from code review Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * docs: Mark the value as string Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * docs: remove duplicated consecutive blank line Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update docs/src/rules/prefer-reflect.md Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent bf7bd88 commit 2c152ff

1 file changed

Lines changed: 2 additions & 41 deletions

File tree

docs/src/rules/prefer-reflect.md

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ related_rules:
1111

1212
This rule was **deprecated** in ESLint v3.9.0 and will not be replaced. The original intent of this rule now seems misguided as we have come to understand that `Reflect` methods are not actually intended to replace the `Object` counterparts the rule suggests, but rather exist as low-level primitives to be used with proxies in order to replicate the default behavior of various previously existing functionality.
1313

14+
**Please note**: This rule contains an incorrect behavior - it will suggest you to use `Reflect.getOwnPropertyNames` rather than `Object.getOwnPropertyNames`, but the former one doesn't exist in the [specification](https://www.ecma-international.org/ecma-262/6.0/index.html#sec-reflection). We suggest using the `exceptions` option with `"getOwnPropertyNames"` to avoid this false suggestion.
15+
1416
The ES6 Reflect API comes with a handful of methods which somewhat deprecate methods on old constructors:
1517

1618
* [`Reflect.apply`](https://www.ecma-international.org/ecma-262/6.0/index.html#sec-reflect.apply) effectively deprecates [`Function.prototype.apply`](https://www.ecma-international.org/ecma-262/6.0/index.html#sec-function.prototype.apply) and [`Function.prototype.call`](https://www.ecma-international.org/ecma-262/6.0/index.html#sec-function.prototype.call)
@@ -320,47 +322,6 @@ Reflect.isExtensible({})
320322

321323
:::
322324

323-
### Reflect.getOwnPropertyNames
324-
325-
Deprecates `Object.getOwnPropertyNames()`
326-
327-
Examples of **incorrect** code for this rule when used without exceptions:
328-
329-
::: incorrect
330-
331-
```js
332-
/*eslint prefer-reflect: "error"*/
333-
334-
Object.getOwnPropertyNames({})
335-
```
336-
337-
:::
338-
339-
Examples of **correct** code for this rule when used without exceptions:
340-
341-
::: correct
342-
343-
```js
344-
/*eslint prefer-reflect: "error"*/
345-
346-
Reflect.getOwnPropertyNames({})
347-
```
348-
349-
:::
350-
351-
Examples of **correct** code for this rule with the `{ "exceptions": ["getOwnPropertyNames"] }` option:
352-
353-
::: correct
354-
355-
```js
356-
/*eslint prefer-reflect: ["error", { "exceptions": ["getOwnPropertyNames"] }]*/
357-
358-
Object.getOwnPropertyNames({})
359-
Reflect.getOwnPropertyNames({})
360-
```
361-
362-
:::
363-
364325
### Reflect.preventExtensions
365326

366327
Deprecates `Object.preventExtensions()`

0 commit comments

Comments
 (0)