Possible issue with `prefer-object-from-entries`
See original GitHub issueI just updated unicorn, and enabled prefer-object-from-entries
. It reported this code as invalid:
const categories = stores
.reduce((acc, val) => {
const category = getCategory(val);
if (acc[category])
acc[category].push(val);
else
acc[category] = [val];
return acc;
}, {});
I’m not really sure, but I don’t think I can just replace this with Object.fromEntries, can I?
If not, maybe it should try finding when we create a pair of k/v out of an object, and report only then?
Or update the error message to tell us to use fromEntries
and another Array
method (map or whatever) to make our modifications? Because here it looks like it tells me to only use fromEntries, but I don’t see how I can 😅
EDIT: I just realised here, my stores
is a Collection
(a Map on steroid, and it has a reduce method). So maybe it’s just that the rule shouldn’t apply here and I have to disable it.
Unrelated
It would be great to enable Github Discussions, as I’m not sure this is a bug, so a Discussion would have been more appropriate IMO 😄
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top GitHub Comments
You may be right on this one. I see an overlap with no-array-reduce and an impossible suggestion (because not all
reduce
s can be turned into an Object.fromEntries)Maybe the scope of the rule should be reduced.
Make sense to me, let’s remove those cases that we don’t know what’s in the callback, we have
no-array-reduce
anyway.