We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
no-useless-object-entries-lookup
I found this pattern
eslint-plugin-unicorn/rules/no-unnecessary-polyfills.js
Lines 130 to 132 in e48a620
in #2582, which use Object.entry to search for a specific key and access the value, which should use a direct object property access instead.
Object.entry
// ❌ const [, value] = Object.entries(object).find(([key,]) => key === 'something'); const value = Object.entries(object).find(([key,]) => key === 'something')[1]; const value = Object.entries(object).find(([key,]) => key === 'something')?.[1]; const [, value] = Object.entries(object).find((entries) => entries[0] === 'something'); const value = Object.entries(object).find((entries) => entries[0] === 'something')[1]; const value = Object.entries(object).find((entries) => entries[0] === 'something')?.[1]; // ✅ const value = object.something;
Note 1: this rule should ensure the searching key can't be object builtin properties/methods.
Should ignore this case, since foo can be constructor or something else which is in object prototype.
foo
constructor
Object.entry(object).find(([key]) => key === foo)
Note 2: Maybe it's also hard to detect that object is a plain object.
object
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Description
I found this pattern
eslint-plugin-unicorn/rules/no-unnecessary-polyfills.js
Lines 130 to 132 in e48a620
in #2582, which use
Object.entry
to search for a specific key and access the value, which should use a direct object property access instead.Examples
Proposed rule name
no-useless-object-entries-lookup
Additional Info
Note 1: this rule should ensure the searching key can't be object builtin properties/methods.
Should ignore this case, since
foo
can beconstructor
or something else which is in object prototype.Note 2: Maybe it's also hard to detect that
object
is a plain object.The text was updated successfully, but these errors were encountered: