-
-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linter/react-perf): handle new objects and arrays in prop assign…
…ment patterns (#4396) # What This PR Does Massively improves all `react-perf` rules - feat: handle new objects/etc assigned to variables ```tsx const Foo = () => { const x = { foo: 'bar' } // <- now reports this new object return <Bar x={x} /> } ``` - feat: handle new objects/etc in binding patterns ```tsx const Foo = ({ x = [] }) => { // ^^^^^^ now reports this new array return <Bar x={x} /> } ``` -feat: nice and descriptive labels for new objects/etc assigned to intermediate variables ``` ⚠ eslint-plugin-react-perf(jsx-no-new-object-as-prop): JSX attribute values should not contain objects created in the same scope. ╭─[jsx_no_new_object_as_prop.tsx:1:27] 1 │ const Foo = () => { const x = {}; return <Bar x={x} /> } · ┬ ─┬ ┬ · │ │ ╰── And used here · │ ╰── And assigned a new value here · ╰── The prop was declared here ╰──── help: simplify props or memoize props in the parent component (https://react.dev/reference/react/memo#my-component-rerenders-when-a-prop-is-an-object-or-array). ``` - feat: consider `Object.assign()` and `Object.create()` as a new object - feat: consider `arr.[map, filter, concat]` as a new array - refactor: move shared implementation code to `ReactPerfRule` in `oxc_linter::utils::react_perf`
- Loading branch information
Showing
10 changed files
with
538 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.