-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(jsx-sort-props): enforce prop sort when reservedFirst is enabled #1340
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
fix(jsx-sort-props): enforce prop sort when reservedFirst is enabled #1340
Conversation
If reservedFirst is enabled and noSortAlphabetically is off, then alphabetical order is only enforced in the reserved props but not in the other props. * Update generateFixerFunction to accept the reservedList. * Rename alphabeticalCompare to be propNameCompare. Accept a reservedFirst and reservedList parameters in order to be able to compare prop names according to the configuration.
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.
I've just merged a PR that adds an autofixer for sort-props, can you add expected output to these three tests?
tests/lib/rules/jsx-sort-props.js
Outdated
code: '<App dangerouslySetInnerHTML={{__html: "EPR"}} key={2} b />', | ||
options: reservedFirstAsBooleanArgs, | ||
errors: [expectedReservedFirstError] | ||
errors: [expectedReservedFirstError, expectedError] |
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.
why would this suddenly start giving two errors?
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.
I think that after the changes this is triggering the expectedError
as the || (!previousIsReserved && !currentIsReserved)
check and it is true when evaluating dangerouslySetInnerHTML
and b
.
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.
We should try to avoid generating the extra error.
I updated the tests with the expected output, but I the fix is not taking into account the reserved words: Expected: I'm gonna try to see if I can add a fix for this. |
tests/lib/rules/jsx-sort-props.js
Outdated
{ | ||
code: '<App b a />', | ||
options: reservedFirstAsBooleanArgs, | ||
errors: [expectedError] |
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.
please add output: '<App a b />'
tests/lib/rules/jsx-sort-props.js
Outdated
@@ -202,9 +202,19 @@ ruleTester.run('jsx-sort-props', rule, { | |||
errors: [expectedError] | |||
}, | |||
{ | |||
code: '<App key={2} b a />', | |||
options: reservedFirstAsBooleanArgs, | |||
errors: [expectedError] |
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.
Please add output: <App key={2} a b />
(assuming that's the expected output)
Sorry I took so long to take a look at the change requests.
|
Definitely wanted, thanks :-) |
tests/lib/rules/jsx-sort-props.js
Outdated
code: '<App dangerouslySetInnerHTML={{__html: "EPR"}} key={2} b />', | ||
options: reservedFirstAsBooleanArgs, | ||
output: '<App key={2} b dangerouslySetInnerHTML={{__html: "EPR"}} />', |
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.
hmm - with reservedFirst tho, the expected output should be <App dangerouslySetInnerHTML={{__html: "EPR"}} key={2} b />
, no?
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.
I think dangerouslySetInnerHTML
is not a reserved prop name for this component. I think it is only considered reserved for DOM components and not react components. This code is deleting dangerouslySetInnerHTML
from the reserved list for the cases where the component is not a DOM component.
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.
ahhhh true! good call :-) could you add an "e" prop as well, so it's clear that it's being sorted as a regular property?
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.
Added.
Planning to merge this soon. |
Any idea on when the merge will happen @ljharb? |
If reservedFirst is enabled and noSortAlphabetically is off, then alphabetical order is only enforced in the reserved props but not in the other props. This PR fixes this.
If existing behavior is the desired, please ignore this PR.
Fixes #1320