jsx-eslint/eslint-plugin-react

[Bug]: react/jsx-key does not detect usage of `Array.push` etc.

Open

#3,937 创建于 2025年7月8日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)JavaScript (8,630 star) (2,797 fork)batch import
enhancementhelp wanted

描述

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

Tl;dr the lint rule doesn't pick up items that are inserted into an array via push/unshift etc.

Expected Behavior

I've seen this pattern many times and I think we could reasonably assume that when the method name matches an array insertion method we can report an error.

This isn't foolproof without type information but I think this will be valuable.

Example:

const Comp = () => {
   const items = [];
   if (someCondition) {
      // this should cause an error/warning
      items.push(<span>test</span>);
   }
   if (someOtherCondition) {
      // same
      items.push(<span>test2</span>);
   }
   return <div>{items}</div>;
}

eslint-plugin-react version

7.37.5

eslint version

9.30.1

node version

24

贡献者指南

[Bug]: react/jsx-key does not detect usage of `Array.push` etc. · jsx-eslint/eslint-plugin-react#3937 | Good First Issue