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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] jsx-sort-props: sorted attributes now respect comments #3358

Merged
merged 1 commit into from
Aug 24, 2022

Conversation

ROSSROSALES
Copy link
Contributor

Fixes #2366

Previously comments were not sorted with rule.
With fix, comments are included during sort.

Special Attribute Conditions:

  • if comment found between two attributes, attributes and comment are sorted to end (to be manually sorted if necessary)
  • above condition also applies to block comments
  • single-line comments on same attribute-line are sorted

@codecov
Copy link

codecov bot commented Aug 16, 2022

Codecov Report

Merging #3358 (e1a6f56) into master (1656707) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head e1a6f56 differs from pull request most recent head c14e209. Consider uploading reports for the commit c14e209 to get more accurate results

@@            Coverage Diff             @@
##           master    #3358      +/-   ##
==========================================
+ Coverage   97.54%   97.55%   +0.01%     
==========================================
  Files         123      123              
  Lines        8873     8918      +45     
  Branches     3244     3255      +11     
==========================================
+ Hits         8655     8700      +45     
  Misses        218      218              
Impacted Files Coverage Δ
lib/rules/jsx-sort-props.js 98.76% <100.00%> (+0.28%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@ljharb ljharb force-pushed the Issue#2366-respects-comment branch from 5c690e0 to 8e5e945 Compare August 18, 2022 05:37
@ljharb
Copy link
Member

ljharb commented Aug 18, 2022

Looks like there's older eslint versions where sourceCode.getCommentsAfter doesn't exist, so we'll need to handle that both in the rule, and in the test cases

Copy link
Contributor Author

@ROSSROSALES ROSSROSALES left a comment

Choose a reason for hiding this comment

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

Thank you for the review!
I really appreciate your time. I have learned many of my own faults with redundant code, naming variables, and conditional statements. I hope in the future to improve and reduce these nuances.

@ROSSROSALES
Copy link
Contributor Author

Looks like there's older eslint versions where sourceCode.getCommentsAfter doesn't exist, so we'll need to handle that both in the rule, and in the test cases

For this change:
Would we need to modify the code to identify which ESLint version is being used?
Then create another function using older deprecated methods of ESLint?

I am unsure other ways of handling errors for older ESLint versions.

@ROSSROSALES
Copy link
Contributor Author

@ljharb
I decided to go with latter of "work with newer ESLint versions". Other useful methods have been deprecated as well and would throw same previous error.

After changes,
I am getting a new error:
AssertionError: Did not specify errors for an invalid test of jsx-sort-props

I tried to search issue online and through other rule using older ESLint, but I had no luck.
How is this error handled?

@ljharb
Copy link
Member

ljharb commented Aug 21, 2022

The invalid list needs to be changed from an array, to a [].concat() call.

I'm thinking about whether or not we need an option for this, or whether it should be the default behavior. Either way, there aren't any tests for the commentbetween option - so, let's either add those, or remove the code handling that option?

@ljharb ljharb marked this pull request as draft August 22, 2022 23:00
@ROSSROSALES
Copy link
Contributor Author

The invalid list needs to be changed from an array, to a [].concat() call.

I'm thinking about whether or not we need an option for this, or whether it should be the default behavior. Either way, there aren't any tests for the commentbetween option - so, let's either add those, or remove the code handling that option?

I created the commentbetween as an option defaulted to true because of how I initially understood sort((a, b) => contextCompare(a, b, options))) . I agree with you that it should be the default behaviour of the rule. I will make sure to edit and remove the option so that the default behaviour reflects it. Please let me know in the next pull request if I made appropriate changes.

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.

adding some lint fixes

lib/rules/jsx-sort-props.js Outdated Show resolved Hide resolved
lib/rules/jsx-sort-props.js Outdated Show resolved Hide resolved
lib/rules/jsx-sort-props.js Outdated Show resolved Hide resolved
lib/rules/jsx-sort-props.js Outdated Show resolved Hide resolved
@ljharb ljharb force-pushed the Issue#2366-respects-comment branch 2 times, most recently from c30e26f to 48d721f Compare August 24, 2022 06:50
@ljharb ljharb marked this pull request as ready for review August 24, 2022 06:50
@ljharb ljharb changed the title [Fix] jsx-sort-props: sorted attributes now respect comments [Fix] jsx-sort-props: sorted attributes now respect comments Aug 24, 2022
@ljharb ljharb force-pushed the Issue#2366-respects-comment branch from 48d721f to c14e209 Compare August 24, 2022 06:51
@ROSSROSALES
Copy link
Contributor Author

Thank you for reviewing the changes! @ljharb

@ljharb ljharb merged commit c14e209 into jsx-eslint:master Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

autofix for jsx-sort-props doesn't respect comments
2 participants