Skip to content
Permalink
Browse files
docs: note false positive Object.getOwnPropertyNames in prefer-refl…
…ect (#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>
  • Loading branch information
AnnAngela and mdjermanovic committed Sep 19, 2022
1 parent bf7bd88 commit 2c152ff0fb709b99e62c19ecd2c95689efacbe4c
Showing 1 changed file with 2 additions and 41 deletions.
@@ -11,6 +11,8 @@ related_rules:

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.

**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.

The ES6 Reflect API comes with a handful of methods which somewhat deprecate methods on old constructors:

* [`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({})

:::

### Reflect.getOwnPropertyNames

Deprecates `Object.getOwnPropertyNames()`

Examples of **incorrect** code for this rule when used without exceptions:

::: incorrect

```js
/*eslint prefer-reflect: "error"*/
Object.getOwnPropertyNames({})
```

:::

Examples of **correct** code for this rule when used without exceptions:

::: correct

```js
/*eslint prefer-reflect: "error"*/
Reflect.getOwnPropertyNames({})
```

:::

Examples of **correct** code for this rule with the `{ "exceptions": ["getOwnPropertyNames"] }` option:

::: correct

```js
/*eslint prefer-reflect: ["error", { "exceptions": ["getOwnPropertyNames"] }]*/
Object.getOwnPropertyNames({})
Reflect.getOwnPropertyNames({})
```

:::

### Reflect.preventExtensions

Deprecates `Object.preventExtensions()`

0 comments on commit 2c152ff

Please sign in to comment.