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.

Bug: The `Reflect.getOwnPropertyNames` still doesn't exist

See original GitHub issue

Environment

Node version: v16.17.0 npm version: v8.18.0 Local ESLint version: v8.23.0 (Currently used) Global ESLint version: v8.23.0 Operating System: linux 5.4.0-1089-azure

What parser are you using?

Default (Espree)

What did you do?

Configuration
{
    "env": {
        "browser": true,
        "jquery": true,
        "es6": true,
        "es2020": true,
        "es2021": true
    },
    "parserOptions": {
        "ecmaVersion": "latest"
    },
    "extends": "eslint:recommended",
    "rules": {
        "prefer-reflect": "error"
    }
}

Code:

        function getOwnPropertyNamesLength(obj) {
            return Object.getOwnPropertyNames(obj).length;
        }

What did you expect to happen?

Due to the function Reflect.getOwnPropertyNames still doesn’t exist (I can’t even find it in caniuse.com), the rule prefer-reflect should not consider about it, so does the document.

What actually happened?

The rule complain that “Avoid using Object.getOwnPropertyNames, instead use Reflect.getOwnPropertyNames.”

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

I knew that #7075 is about it and closed, but I met the problem again, that’s why I submit this issue.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Sep 15, 2022

that’s a fair point, but it’s just Reflect.ownKeys(x).filter(x => typeof x === 'string') ¯_(ツ)_/¯

That would work, but this rule wasn’t intended to suggest replacements of such complexity, so I think it’s fine to add a note in the docs that Object.getOwnPropertyNames was added by mistake.

0reactions
AnnAngelacommented, Sep 16, 2022

@mdjermanovic OK, I will make a PR to change the documents only.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docs: Reflect.getOwnPropertyNames does not exist · Issue #7075 ...
In the documentation and source code for the prefer-reflect rule, the user is instructed to use Reflect. ... getOwnPropertyNames doesn't actually exist.
Read more >
Object.getOwnPropertyNames() - JavaScript - MDN Web Docs
The Object.getOwnPropertyNames() method returns an array of all properties (including non-enumerable properties except for those which use Symbol) found ...
Read more >
Metaprogramming in ES6: Part 2 - Reflect - Keith Cirkel
Symbols are all about Reflection within implementation - you sprinkle them on your existing classes and objects to change the behaviour.
Read more >
Proxy and Reflect - The Modern JavaScript Tutorial
Proxy is a special “exotic object”. It doesn't have own properties. With an empty handler it transparently forwards operations to target . To ......
Read more >
How did I leverage Proxies to make JavaScript errors pleasant ...
keys or Object.getOwnPropertyNames to obtain the list of all available own keys, yet still, no dice, the result was not quite something you...
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