-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
autofix for jsx-sort-props doesn't respect comments #2366
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
Comments
Comment attachment is a very hard problem; some people put comments above, and some below, and many don’t comment at all. We may be able to handle something here, but we’d be constrained by how Babel implemented comment attachment. |
Yeah, I agree. About Babel AST:
For this example Babel will keep comment in ast for a prop as trailing comment and for b same comment as leading. I think we can configure it via options. Something like But maybe we can implement option just for disabling autofix? |
It seems prudent to disable autofixes entirely for props that have a leading or a trailing comment, no option needed. |
Maybe we should disable it entirely for component's that contains props with comments? Otherwise result of autofix will be confusing. For example group of props before comment sorted in alphabetical order and after comment too. But it doesn't make sense, because it's still not valid. <input
a
b
c
// fofof
f
a
b
c
/> If so, I can submit PR |
In that example I’d expect everything to be sorted except the ones surrounding the comment, and the dev being forced to manually fix those. |
So, something like this? Ok, I will take a look <input
a
a
b
b
c
c
// fofof
f
/> |
Have you had a look yet, @7rulnik ? No pressure; I'm just evaluating whether to have a go at this myself, and I'd like to hear if you're stuck at some bump which I'm also likely to hit. |
And by the way, in your example: Has the |
@Vages if the original was: <input
m
n // this is n
o
c // this is c
// fofof
f // this is f
a
b
c
/> it should autocorrect to: <input
a
b
c
m
n // this is n
o
c // this is c
// fofof
f // this is f
/> In other words, any line touching a standalone comment on either side should be left alone / sorted last, as a single group. |
I think there are two distinct issues here: |
@jsphstls i agree that a same-line comment should be moved along with it, and should not interfere with sorting. |
For single-line props: <input f e d /* comment */ c b a /> should autocorrect to: <input a b d /* comment */ c e f /> or <input a b e f d /* comment */ c /> as long as the d+comment+c group was kept atomic. |
@ljharb I am having trouble with my approach to the problem and wanted to clarify if it is appropriate. Question: Any advice or guidance would be greatly appreciated! |
@ROSSROSALES I think the comments will be attached as a property on an adjacent node of another kind. |
Autofix for jsx-sort-props doesn't respect comments.
For example:
will be fixed like this:
But I think it should be like this:
The text was updated successfully, but these errors were encountered: