jsx-eslint / eslint-plugin-react

React-specific linting rules for ESLint
MIT License
9.01k stars 2.77k forks source link

no-array-index-key does not support ImmutableJS #1065

Closed arnarthor closed 2 years ago

arnarthor commented 7 years ago

This rule seems really useful, but at the same time it can be frustrating with ImmutableJS.

It seems that the rule is only checking for .map with 2 arguments and assuming the latter one is the index here.

The counter example for that is here

Immutable.Map({foo: 'bar'}).map((value, key) => <div key={key} />)

This causes an error in this rule wrongfully since key does not have the same behaviour as an array index.

lencioni commented 7 years ago

Thanks for the report!

Unfortunately, I'm not sure there is any way to reasonably detect if .map is called on an Immutable.js object or something else. Any ideas on how we might solve this?

If we can't come up with anything, I think the best we can do is add a note to the documentation about this.

arnarthor commented 7 years ago

Yup definitely. I didn't expect this to get fixed since it's a really hard problem to solve. But adding something to the docs would be beneficial.

Also regarding if #1049 gets through to make sure it's expressed as part of the recommended setup.

Otherwise awesome stuff, hadn't thought about this one when assigning my keys 👍

ljharb commented 2 years ago

Happy to review a PR to the docs; I agree that it's not really possible to know when .map is called on immutableJS specifically.