Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(jsx-key): check for array related method calls with jsx elements/fragments#3938

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
SimonSchick wants to merge3 commits intojsx-eslint:master
base:master
Choose a base branch
Loading
fromSimonSchick:feat/jsx-key-array-push

Conversation

SimonSchick
Copy link

WIP, pending initial feedback, slightly worried this check may be overly broad.

Things to add:

  • Setting to make this behavior opt-in unless we want it to be the default.
  • Optimization of esquery usage? Seems potentially very wasteful.
  • Check methods for exhaustiveness, there (fill, toSpliced) being more exotic candidates

Fixes#3937

@ljharbljharb marked this pull request as draftJuly 9, 2025 05:47
@ljharb
Copy link
Member

I'm not sure it's a good idea to assume any method named "push" or "splice" is happening on an array, unless it's a TS codebase.

@SimonSchick
Copy link
Author

That was kinda my thinking too but I'm unsure how much better we can do without types.

I thought about trying to trace the symbol we are pushing to and see if it is a array declaration but that feels very much like a hack.

On the other hand I'd assumepush,unshift andconcat are the most commonly used methods for this anti-pattern and these are not exactly common method names in in relation to jsx usage so false positives should be extremely rare.

Question it if it is rare enough to proceed with this vague targetting strategy?

I did some rough searching viahttps://github.com/search?type=code&q=%28path%3A*.tsx+OR+path%3A*.jsx%29+%2F.%2B%5C.push%5C%28%3C.%2B%5C%29%3B%2F and found nothing that stands out, had to vary the search query a fair bit since github code search seems to limit results to 100 for some reason.

@ljharb
Copy link
Member

concat exists on a number of things, and i agree false positives will be rare, but nonzero is nonzero.

Adding this change under an option is smart if it has a nonzero risk of false positives, though.

@SimonSchick
Copy link
Author

I'll add an option then, and also fix the failing tests for legacy versions (I really wish those get pruned 😢 ).

ljharb reacted with thumbs up emojiljharb reacted with laugh emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[Bug]: react/jsx-key does not detect usage ofArray.push etc.
2 participants
@SimonSchick@ljharb

[8]ページ先頭

©2009-2025 Movatter.jp