From f9aea209b8166212da0e04e5b84a7d556eae29c2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:50:12 +0000 Subject: [PATCH 1/4] Initial plan From 21f66148d57297f78a2726dbfbd174df803b3ce8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:59:44 +0000 Subject: [PATCH 2/4] Add rules for merging className and event handlers with spread props Co-authored-by: siddharthkp <1863771+siddharthkp@users.noreply.github.com> --- docs/rules/merge-spread-props-classname.md | 75 ++++++++ .../merge-spread-props-event-handlers.md | 91 ++++++++++ src/index.js | 2 + .../merge-spread-props-classname.test.js | 107 +++++++++++ .../merge-spread-props-event-handlers.test.js | 140 +++++++++++++++ src/rules/merge-spread-props-classname.js | 95 ++++++++++ .../merge-spread-props-event-handlers.js | 166 ++++++++++++++++++ 7 files changed, 676 insertions(+) create mode 100644 docs/rules/merge-spread-props-classname.md create mode 100644 docs/rules/merge-spread-props-event-handlers.md create mode 100644 src/rules/__tests__/merge-spread-props-classname.test.js create mode 100644 src/rules/__tests__/merge-spread-props-event-handlers.test.js create mode 100644 src/rules/merge-spread-props-classname.js create mode 100644 src/rules/merge-spread-props-event-handlers.js diff --git a/docs/rules/merge-spread-props-classname.md b/docs/rules/merge-spread-props-classname.md new file mode 100644 index 0000000..bc19284 --- /dev/null +++ b/docs/rules/merge-spread-props-classname.md @@ -0,0 +1,75 @@ +# Ensure className is merged with spread props (merge-spread-props-classname) + +When using spread props (`{...rest}`, `{...props}`, etc.) before a `className` prop, the className should be merged using a utility like `clsx` to avoid unintentionally overriding the className from the spread props. + +## Rule details + +This rule enforces that when a JSX element has both spread props and a `className` prop, and the spread props come before the `className`, the className should use `clsx` or a similar utility to merge both class names. + +👎 Examples of **incorrect** code for this rule: + +```jsx +/* eslint primer-react/merge-spread-props-classname: "error" */ + +// ❌ className after spread - not merged + + +// ❌ className expression after spread - not merged + + +// ❌ Multiple spreads with className - not merged + +``` + +👍 Examples of **correct** code for this rule: + +```jsx +/* eslint primer-react/merge-spread-props-classname: "error" */ + +// ✅ className merged with clsx + + +// ✅ className merged with classnames + + +// ✅ className before spread (spread will override, which is expected) + + +// ✅ Only spread props + + +// ✅ Only className + +``` + +## Why this matters + +When you have spread props before a className, the className from the spread props can be overridden if you don't merge them properly: + +```jsx +// ❌ Bad: className from rest gets overridden +function MyComponent({className, ...rest}) { + return