-
Couldn't load subscription status.
- Fork 10
Add eslint rule to ensure spread props come before other props #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 6e8de23 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-authored-by: siddharthkp <1863771+siddharthkp@users.noreply.github.com>
Co-authored-by: siddharthkp <1863771+siddharthkp@users.noreply.github.com>
@copilot We only support eslint version > 9, you can remove any code that offers compatibility to older versions
Co-authored-by: siddharthkp <1863771+siddharthkp@users.noreply.github.com>
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
@copilot look at other changesets and add a changeset in the same style
Co-authored-by: siddharthkp <1863771+siddharthkp@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new ESLint rule spread-props-first that enforces spread props to appear before named props in JSX elements, preventing unintentional prop overrides. The implementation includes comprehensive test coverage and documentation.
Key changes:
- New ESLint rule with automatic fixing capability
- 15 test cases (7 valid, 8 invalid) all passing
- Complete documentation with examples
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/rules/spread-props-first.js |
Core rule implementation with detection and autofix logic |
src/rules/__tests__/spread-props-first.test.js |
Comprehensive test suite covering valid and invalid cases |
src/index.js |
Export of the new rule |
docs/rules/spread-props-first.md |
User-facing documentation with examples |
.changeset/upset-cobras-cross.md |
Release changeset tracking the new feature |
Copilot
AI
Oct 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using sourceCode.getText() to display the spread prop in the error message could be misleading if the spread expression is complex or multiline. Consider extracting just the spread identifier name (e.g., rest from {...rest}) using spreadAttr.argument.name for clearer error messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks genuinely good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great 🥳 Am very interested to try it out.
One question, would it be possible to have the rule (or a follow up rule?) that helps people understand when something may not be merged correctly. For example:
-<Example {...rest} className="..." /> +<Example {...rest} className={clsx(className, '...')} /> -<Example {...rest} onClick={() => {}} /> +<Example {...rest} onClick={compose(onClick, () => {})} />
It would be helpful to know in these situations that we have not merged rest correctly. My guess is that it would be too hard in eslint world to know what rest is but figured I'd ask
Ooh! yeah that's a good one. If rest is coming from the same file, it should be possible with reading the types 🤔
Will try it out (or make copilot try it 🤭) in a new issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for reviewer: I have intentionally left this out from recommended config, not sure if everyone wants it or not.
Uh oh!
There was an error while loading. Please reload this page.
Note
👋 Hello from human co-author. I've reviewed the code and it genuinely looks good.
Implementation Complete: spread-props-first ESLint Rule ✅
This PR successfully implements a new ESLint rule that ensures spread props come before other props in JSX elements to prevent unintentional prop overrides.
Implementation Status
src/rules/spread-props-first.jssrc/rules/__tests__/spread-props-first.test.jssrc/index.jsdocs/rules/spread-props-first.mdWhat Was Implemented
Rule Behavior:
{...rest},{...props}, etc.) appear after named propsTest Coverage:
Documentation:
Files Changed
src/rules/spread-props-first.js(81 lines) - Rule implementationsrc/rules/__tests__/spread-props-first.test.js(123 lines) - Comprehensive testssrc/index.js(1 line) - Rule exportdocs/rules/spread-props-first.md(66 lines) - Documentation.changeset/upset-cobras-cross.md- Changeset for release trackingValidation Results
✅ All 334 tests pass (including 15 new tests)
✅ ESLint passes
✅ Markdown linting passes
✅ Prettier formatting passes
✅ CodeQL security scan passes (0 alerts)
✅ Manual testing confirms correct behavior
Security Summary
No vulnerabilities detected by CodeQL analysis.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.