From 4a9e6831761b38ca2590c4eb27a1c03b3ab4b019 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 10 Oct 2024 11:10:25 -0400 Subject: [PATCH] eslint: Enable `react/jsx-key` rule (#39709) This rule requires a `key` prop be specified on elements that it thinks probably need one, namely elements inside arrays or returned from iterators for `.map()` and the like. In practice most of the cases fixed here are probably pointless, since the arrays are never going to be sorted or modified at runtime. But it's easier to add a key than to write a comment justifing ignoring it in each case. --- .../changelog/add-eslint-react-jsx-key | 5 +++++ .../button/stories/index.stories.tsx | 18 +++++++++--------- .../theme-provider/stories/index.stories.tsx | 9 +++++++-- .../changelog/add-eslint-react-jsx-key | 5 +++++ .../components/disconnect-survey/index.jsx | 1 + .../changelog/add-eslint-react-jsx-key | 5 +++++ .../components/social-previews/instagram.js | 5 ++++- .../changelog/add-eslint-react-jsx-key | 4 ++++ .../social-logos/src/react/example.tsx | 1 + .../forms/changelog/add-eslint-react-jsx-key | 5 +++++ .../components/jetpack-field-controls.js | 5 ++++- .../components/my-jetpack-screen/index.jsx | 4 +++- .../components/product-detail-table/index.jsx | 1 + .../jetpack-ai/product-page.jsx | 2 +- .../changelog/add-eslint-react-jsx-key | 5 +++++ .../search/changelog/add-eslint-react-jsx-key | 4 ++++ .../components/search-result-minimal.jsx | 4 ++-- .../jetpack/_inc/client/at-a-glance/scan.jsx | 6 ++++-- .../components/connection-banner/index.jsx | 2 +- .../jetpack/changelog/add-eslint-react-jsx-key | 5 +++++ .../blocks/donations/deprecated/v1/index.js | 6 +++--- .../blocks/opentable/deprecated/v1/index.js | 5 ++++- .../blocks/opentable/deprecated/v2/index.js | 5 ++++- .../shared/components/block-nudge/index.jsx | 1 + .../protect/changelog/add-eslint-react-jsx-key | 5 +++++ .../protect/src/js/routes/firewall/index.jsx | 1 + tools/js-tools/eslintrc/react.js | 3 --- 27 files changed, 94 insertions(+), 28 deletions(-) create mode 100644 projects/js-packages/components/changelog/add-eslint-react-jsx-key create mode 100644 projects/js-packages/connection/changelog/add-eslint-react-jsx-key create mode 100644 projects/js-packages/publicize-components/changelog/add-eslint-react-jsx-key create mode 100644 projects/js-packages/social-logos/changelog/add-eslint-react-jsx-key create mode 100644 projects/packages/forms/changelog/add-eslint-react-jsx-key create mode 100644 projects/packages/my-jetpack/changelog/add-eslint-react-jsx-key create mode 100644 projects/packages/search/changelog/add-eslint-react-jsx-key create mode 100644 projects/plugins/jetpack/changelog/add-eslint-react-jsx-key create mode 100644 projects/plugins/protect/changelog/add-eslint-react-jsx-key diff --git a/projects/js-packages/components/changelog/add-eslint-react-jsx-key b/projects/js-packages/components/changelog/add-eslint-react-jsx-key new file mode 100644 index 0000000000000..6bb34ab09749d --- /dev/null +++ b/projects/js-packages/components/changelog/add-eslint-react-jsx-key @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: Add `key` to React components in some stories. Should be no change to functionality. + + diff --git a/projects/js-packages/components/components/button/stories/index.stories.tsx b/projects/js-packages/components/components/button/stories/index.stories.tsx index 6b0dffab52719..390b6c1caf71f 100644 --- a/projects/js-packages/components/components/button/stories/index.stories.tsx +++ b/projects/js-packages/components/components/button/stories/index.stories.tsx @@ -313,7 +313,7 @@ export const VariantsAndProps = () => { no props { variants.map( variant => ( - + , ] diff --git a/projects/packages/my-jetpack/changelog/add-eslint-react-jsx-key b/projects/packages/my-jetpack/changelog/add-eslint-react-jsx-key new file mode 100644 index 0000000000000..9c48272a94f90 --- /dev/null +++ b/projects/packages/my-jetpack/changelog/add-eslint-react-jsx-key @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: Add `key` to some React `actions` props. Should be no change to functionality. + + diff --git a/projects/packages/search/changelog/add-eslint-react-jsx-key b/projects/packages/search/changelog/add-eslint-react-jsx-key new file mode 100644 index 0000000000000..c52e5a775fa9a --- /dev/null +++ b/projects/packages/search/changelog/add-eslint-react-jsx-key @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Add `key` to tag and cat lists in `SearchResultMinimal` to improve behavior if lists change at runtime. diff --git a/projects/packages/search/src/instant-search/components/search-result-minimal.jsx b/projects/packages/search/src/instant-search/components/search-result-minimal.jsx index 46739b9af523b..1e2a59c45efff 100644 --- a/projects/packages/search/src/instant-search/components/search-result-minimal.jsx +++ b/projects/packages/search/src/instant-search/components/search-result-minimal.jsx @@ -55,7 +55,7 @@ class SearchResultMinimal extends Component { { tags.length !== 0 && (