Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New] jsx-sort-props: support multiline prop groups #3198

Merged

Conversation

duhamelgm
Copy link
Contributor

Hello 馃憢

This PR Adds a new multiline group for the jsx-sort-props rule. Related to the issue: #3170

The shorthand and callback rules take precedence over the multiline rule set

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than two mutually exclusive boolean props, this would be better as an enum value for "multiline" - ignore (default), first, or last, perhaps?

docs/rules/jsx-sort-props.md Outdated Show resolved Hide resolved
tests/lib/rules/jsx-sort-props.js Outdated Show resolved Hide resolved
@ljharb ljharb marked this pull request as draft February 6, 2022 04:16
lib/rules/jsx-sort-props.js Outdated Show resolved Hide resolved
Comment on lines +679 to +683
a={{
aA: 1,
}}
b
inline={1}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a limitation with the current implementation here, whenever conflicting groups are in order between themselves, but in disorder with other props, only the group with higher hierarchy will be reported.

For example here we enabled { multiline: 'last', shorthandLast: true }, but only the shorthand prop is being reported as an error, since multiline thinks that it's in order.

I feel like there's no easy way to fix this unless we change the way in which jsx-sort-props checks and order the props, so that it check props by groups instead of the direct adjacent neighbors of each prop. I wouldn't mind working on that, but I feel like that's out of the scope of this PR...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree; that sounds like a great improvement, but belongs in another PR.

@duhamelgm duhamelgm force-pushed the 3170-jsx-sort-props-new-multiline-group branch from 39b452b to c46efb8 Compare February 6, 2022 17:31
@duhamelgm
Copy link
Contributor Author

@ljharb I was able to work on the given feedback, now the property is an enum rather than two mutually exclusive props, and the tests are now expecting line numbers for each specific error. There was a little issue regarding how the shorthandFirst property gave its report so I changed that as well. Let me know what you think, and thanks for taking the time to look into this!

@duhamelgm duhamelgm marked this pull request as ready for review February 6, 2022 18:05
lib/rules/jsx-sort-props.js Outdated Show resolved Hide resolved
lib/rules/jsx-sort-props.js Show resolved Hide resolved
Comment on lines +679 to +683
a={{
aA: 1,
}}
b
inline={1}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree; that sounds like a great improvement, but belongs in another PR.

tests/lib/rules/jsx-sort-props.js Outdated Show resolved Hide resolved
tests/lib/rules/jsx-sort-props.js Outdated Show resolved Hide resolved
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done, and very thorough.

@ljharb ljharb force-pushed the 3170-jsx-sort-props-new-multiline-group branch from 85a55f0 to 446c5a3 Compare February 7, 2022 06:16
@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2022

Codecov Report

Merging #3198 (f47deef) into master (cfb4d6b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3198   +/-   ##
=======================================
  Coverage   97.62%   97.63%           
=======================================
  Files         121      121           
  Lines        8381     8416   +35     
  Branches     3011     3025   +14     
=======================================
+ Hits         8182     8217   +35     
  Misses        199      199           
Impacted Files Coverage 螖
lib/rules/jsx-sort-props.js 98.96% <100.00%> (+0.22%) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update cfb4d6b...f47deef. Read the comment docs.

@ljharb ljharb force-pushed the 3170-jsx-sort-props-new-multiline-group branch from 446c5a3 to f47deef Compare February 7, 2022 06:36
@ljharb
Copy link
Member

ljharb commented Feb 7, 2022

One more change, because node < 6 doesn't have array .includes :-)

@ljharb ljharb merged commit f47deef into jsx-eslint:master Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants