Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: note false positive Object.getOwnPropertyNames in prefer-reflect #16317

Merged
merged 6 commits into from Sep 19, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 3 additions & 41 deletions docs/src/rules/prefer-reflect.md
Expand Up @@ -11,6 +11,9 @@ 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 `exceptions` option with `getOwnPropertyNames` to avoid this false suggestion.
AnnAngela marked this conversation as resolved.
Show resolved Hide resolved


AnnAngela marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down Expand Up @@ -320,47 +323,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()`
Expand Down