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

[Fix] no-array-index-key: catch toString and String() usage #2813

Merged
merged 1 commit into from Feb 15, 2022

Conversation

RedTn
Copy link
Contributor

@RedTn RedTn commented Oct 1, 2020

Closes #2140

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but it seems like any reference to the index should be warned on, not just .toString or String(). Can we have it do that?

@RedTn
Copy link
Contributor Author

RedTn commented Oct 6, 2020

This looks good, but it seems like any reference to the index should be warned on, not just .toString or String(). Can we have it do that?

This seems a bit tricky to write if I'm trying to explicitly hard code cases to look for. Is there an existing util in the codebase to do this, or something in ESLint? Do we take some sort of recursive algo approach in checking all the nodes arguments and callee's?

@ljharb
Copy link
Member

ljharb commented Oct 6, 2020

I don't have a specific suggestion. I'd say that any identifier inside a jsx attribute that matches the index should be flagged?

@ljharb ljharb marked this pull request as draft October 15, 2020 17:50
@ljharb ljharb marked this pull request as ready for review February 15, 2022 07:04
@ljharb ljharb force-pushed the 2140-no-array-index-toString branch from cb92bd2 to 492b5f1 Compare February 15, 2022 07:04
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go ahead and land this, and hopefully there will be further improvements in the future.

@codecov-commenter
Copy link

codecov-commenter commented Feb 15, 2022

Codecov Report

Merging #2813 (492b5f1) into master (1b307d3) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2813      +/-   ##
==========================================
+ Coverage   97.64%   97.67%   +0.02%     
==========================================
  Files         121      121              
  Lines        8440     8459      +19     
  Branches     3033     3048      +15     
==========================================
+ Hits         8241     8262      +21     
+ Misses        199      197       -2     
Impacted Files Coverage Δ
lib/rules/no-array-index-key.js 92.68% <100.00%> (+3.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b307d3...492b5f1. Read the comment docs.

@ljharb ljharb closed this in 492b5f1 Feb 15, 2022
@ljharb ljharb merged commit 492b5f1 into jsx-eslint:master Feb 15, 2022
@RedTn
Copy link
Contributor Author

RedTn commented Feb 15, 2022

Sorry forgot about this. If we open another issue I can take a look again once I have some time. But happy to let others take it if they want to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

no-array-index-key can be bypassed with toString
3 participants