diff --git a/.changeset/upset-cobras-cross.md b/.changeset/upset-cobras-cross.md
new file mode 100644
index 00000000..9015f418
--- /dev/null
+++ b/.changeset/upset-cobras-cross.md
@@ -0,0 +1,5 @@
+---
+'eslint-plugin-primer-react': minor
+---
+
+Add spread-props-first rule to ensure spread props come before other props
diff --git a/docs/rules/spread-props-first.md b/docs/rules/spread-props-first.md
new file mode 100644
index 00000000..c549ada4
--- /dev/null
+++ b/docs/rules/spread-props-first.md
@@ -0,0 +1,66 @@
+# Ensure spread props come before other props (spread-props-first)
+
+Spread props should come before other named props to avoid unintentionally overriding props. When spread props are placed after named props, they can override the named props, which is often unintended and can lead to UI bugs.
+
+## Rule details
+
+This rule enforces that all spread props (`{...rest}`, `{...props}`, etc.) come before any named props in JSX elements.
+
+👎 Examples of **incorrect** code for this rule:
+
+```jsx
+/* eslint primer-react/spread-props-first: "error" */
+
+// ❌ Spread after named prop
+
+
+// ❌ Spread in the middle
+
+
+// ❌ Multiple spreads after named props
+
+```
+
+👍 Examples of **correct** code for this rule:
+
+```jsx
+/* eslint primer-react/spread-props-first: "error" */
+
+// ✅ Spread before named props
+
+
+// ✅ Multiple spreads before named props
+
+
+// ✅ Only spread props
+
+
+// ✅ Only named props
+
+```
+
+## Why this matters
+
+Placing spread props after named props can cause unexpected behavior:
+
+```jsx
+// ❌ Bad: className might get overridden by rest
+
+
+// If rest = { className: "other-class" }
+// Result: className="other-class" (custom-class is lost!)
+
+// ✅ Good: className will override any className in rest
+
+
+// If rest = { className: "other-class" }
+// Result: className="custom-class" (as intended)
+```
+
+## Options
+
+This rule has no configuration options.
+
+## When to use autofix
+
+This rule includes an autofix that will automatically reorder your props to place all spread props first. The autofix is safe to use as it preserves the order of spreads relative to each other and the order of named props relative to each other.
diff --git a/src/index.js b/src/index.js
index 1dc3315e..89b99bf3 100644
--- a/src/index.js
+++ b/src/index.js
@@ -20,6 +20,7 @@ module.exports = {
'enforce-css-module-identifier-casing': require('./rules/enforce-css-module-identifier-casing'),
'enforce-css-module-default-import': require('./rules/enforce-css-module-default-import'),
'use-styled-react-import': require('./rules/use-styled-react-import'),
+ 'spread-props-first': require('./rules/spread-props-first'),
},
configs: {
recommended: require('./configs/recommended'),
diff --git a/src/rules/__tests__/spread-props-first.test.js b/src/rules/__tests__/spread-props-first.test.js
new file mode 100644
index 00000000..3650924e
--- /dev/null
+++ b/src/rules/__tests__/spread-props-first.test.js
@@ -0,0 +1,123 @@
+const rule = require('../spread-props-first')
+const {RuleTester} = require('eslint')
+
+const ruleTester = new RuleTester({
+ languageOptions: {
+ ecmaVersion: 'latest',
+ sourceType: 'module',
+ parserOptions: {
+ ecmaFeatures: {
+ jsx: true,
+ },
+ },
+ },
+})
+
+ruleTester.run('spread-props-first', rule, {
+ valid: [
+ // Spread props before named props
+ ``,
+ // Multiple spreads before named props
+ ``,
+ // Only spread props
+ ``,
+ // Only named props
+ ``,
+ // Empty element
+ ``,
+ // Spread first, then named props
+ ``,
+ // Multiple spreads at the beginning
+ ``,
+ ],
+ invalid: [
+ // Named prop before spread
+ {
+ code: ``,
+ output: ``,
+ errors: [
+ {
+ messageId: 'spreadPropsFirst',
+ data: {spreadProp: '{...rest}', namedProp: 'className'},
+ },
+ ],
+ },
+ // Multiple named props before spread
+ {
+ code: ``,
+ output: ``,
+ errors: [
+ {
+ messageId: 'spreadPropsFirst',
+ data: {spreadProp: '{...rest}', namedProp: 'id'},
+ },
+ ],
+ },
+ // Named prop with expression before spread
+ {
+ code: ``,
+ output: ``,
+ errors: [
+ {
+ messageId: 'spreadPropsFirst',
+ data: {spreadProp: '{...rest}', namedProp: 'onClick'},
+ },
+ ],
+ },
+ // Mixed order with multiple spreads
+ {
+ code: ``,
+ output: ``,
+ errors: [
+ {
+ messageId: 'spreadPropsFirst',
+ data: {spreadProp: '{...rest}', namedProp: 'id'},
+ },
+ ],
+ },
+ // Named prop before multiple spreads
+ {
+ code: ``,
+ output: ``,
+ errors: [
+ {
+ messageId: 'spreadPropsFirst',
+ data: {spreadProp: '{...rest}', namedProp: 'className'},
+ },
+ ],
+ },
+ // Complex example with many props
+ {
+ code: ``,
+ output: ``,
+ errors: [
+ {
+ messageId: 'spreadPropsFirst',
+ data: {spreadProp: '{...rest}', namedProp: 'disabled'},
+ },
+ ],
+ },
+ // Boolean prop before spread
+ {
+ code: ``,
+ output: ``,
+ errors: [
+ {
+ messageId: 'spreadPropsFirst',
+ data: {spreadProp: '{...rest}', namedProp: 'disabled'},
+ },
+ ],
+ },
+ // Spread in the middle
+ {
+ code: ``,
+ output: ``,
+ errors: [
+ {
+ messageId: 'spreadPropsFirst',
+ data: {spreadProp: '{...rest}', namedProp: 'id'},
+ },
+ ],
+ },
+ ],
+})
diff --git a/src/rules/spread-props-first.js b/src/rules/spread-props-first.js
new file mode 100644
index 00000000..4184b9ba
--- /dev/null
+++ b/src/rules/spread-props-first.js
@@ -0,0 +1,81 @@
+module.exports = {
+ meta: {
+ type: 'problem',
+ fixable: 'code',
+ schema: [],
+ messages: {
+ spreadPropsFirst:
+ 'Spread props should come before other props to avoid unintentional overrides. Move {{spreadProp}} before {{namedProp}}.',
+ },
+ },
+ create(context) {
+ return {
+ JSXOpeningElement(node) {
+ const attributes = node.attributes
+
+ // Track if we've seen a named prop before a spread
+ let lastNamedPropIndex = -1
+ let firstSpreadAfterNamedPropIndex = -1
+
+ for (let i = 0; i < attributes.length; i++) {
+ const attr = attributes[i]
+
+ if (attr.type === 'JSXAttribute') {
+ // This is a named prop
+ lastNamedPropIndex = i
+ } else if (attr.type === 'JSXSpreadAttribute' && lastNamedPropIndex !== -1) {
+ // This is a spread prop that comes after a named prop
+ if (firstSpreadAfterNamedPropIndex === -1) {
+ firstSpreadAfterNamedPropIndex = i
+ }
+ }
+ }
+
+ // If we found a spread after a named prop, report it
+ if (firstSpreadAfterNamedPropIndex !== -1) {
+ const sourceCode = context.sourceCode
+ const spreadAttr = attributes[firstSpreadAfterNamedPropIndex]
+ const namedAttr = attributes[lastNamedPropIndex]
+
+ context.report({
+ node: spreadAttr,
+ messageId: 'spreadPropsFirst',
+ data: {
+ spreadProp: sourceCode.getText(spreadAttr),
+ namedProp: namedAttr.name.name,
+ },
+ fix(fixer) {
+ // Collect all spreads and named props
+ const spreads = []
+ const namedProps = []
+
+ for (const attr of attributes) {
+ if (attr.type === 'JSXSpreadAttribute') {
+ spreads.push(attr)
+ } else if (attr.type === 'JSXAttribute') {
+ namedProps.push(attr)
+ }
+ }
+
+ // Generate the reordered attributes text
+ const reorderedAttrs = [...spreads, ...namedProps]
+ const fixes = []
+
+ // Replace each attribute with its new position
+ for (let i = 0; i < attributes.length; i++) {
+ const newAttr = reorderedAttrs[i]
+ const oldAttr = attributes[i]
+
+ if (newAttr !== oldAttr) {
+ fixes.push(fixer.replaceText(oldAttr, sourceCode.getText(newAttr)))
+ }
+ }
+
+ return fixes
+ },
+ })
+ }
+ },
+ }
+ },
+}