Repository navigation
Prettier extends and implements when not fitting in same line - #3689
Conversation
| Interface5, | ||
| Interface6, | ||
| Interface7, | ||
| Interface8 {} No newline at end of file |
There was a problem hiding this comment.
Could you add a blank line at the end here.
There was a problem hiding this comment.
What do you mean by this?
Interface5,
Interface6,
Interface7,
Interface8*added*
{}
Interface5,
Interface6,
Interface7,
Interface8 {}
*added*
There was a problem hiding this comment.
Files should have a blank line at the end of them so the snapshots look right.
|
|
||
| (class A extends B // comment1 | ||
| (class A | ||
| extends B // comment1 |
There was a problem hiding this comment.
I don't think it should break just because there's a comment.
There was a problem hiding this comment.
I will try to figure it out :)
| class Foo | ||
| extends Immutable.Record({ | ||
| ipaddress: "" | ||
| }) { |
There was a problem hiding this comment.
Fwiw, we had the behavior you are changing it to in the early days of prettier but I changed to what we have now for this example and extending React component with types. It looks better in one line.
Now, this causes a bunch of problematic things (like all the rest that’s being fixed by this pr) so it may not be a bad idea to follow through. I just wanted to give some context
There was a problem hiding this comment.
Could we inline only if it is a CallExpression?
There was a problem hiding this comment.
What could be a good way is to keep the previous implementation if there’s just a single extend. Otherwise use your new logic
There was a problem hiding this comment.
React.Component<...> is not a call expression
There was a problem hiding this comment.
We do want a long identifier to break, though.
There was a problem hiding this comment.
Once you decided when not to break (which expression), i will continue with this :)
There was a problem hiding this comment.
@azz @vjeux @j-f1
Any update on this?
I mean if its a long statement it should def brake, and it makes it def more readable like this.
If we limit it to only break when there is a single extends
something like this
class AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA extends AAAAAAAAAAAAAA
would still look shitty.
|
Btw this is great but is going to cause a bunch of formatting changes so we should hold it off after tomorrow’s release |
| } | ||
| const isBlock = util.isBlockComment(comment); | ||
|
|
||
| // Workaround for comments that are in the superClass definition ( extends ...) |
There was a problem hiding this comment.
Is this workaround ok?
Feels dirty to me but there was no other way to get the parentNode of the parentNode
There was a problem hiding this comment.
commentPath.getParentNode(3) === "superClass"?
or maybe it’s 2.
There was a problem hiding this comment.
i fixed it, its a little bit longer but better understandable and maintainable :)
We should definitely work on some kind of documentation :) There are cool features build in, but its hard for people who are new to find them :)
There was a problem hiding this comment.
thanks for the quick feedback :)
|
My ask is that if there's only a single extend then use the previous behavior. If there are more than one, feel free to change it however you like :) |
|
Thanks, the examples on the last commit look good on my end :) |
| return concat([" ", contents]); | ||
| } | ||
|
|
||
| // console.log("trailing comment"); |
There was a problem hiding this comment.
oh man that's embarassing...
Fixed now :)
|
@azz fixed :) finally done? :) |
|
🎉 Thanks! |
Please see screenshot for how it looks like:

This PR was requested by @j-f1 in the prettier-java project, after changes there. See discussion here: jhipster/prettier-java#13
Had to update some unrelated tests, by adding some generic fake parameters.
Please take a close look if the comment logic (changed test) makes still sense to you, for me it even makes it more clear what part of the line the comment is regarding too.
This change will make it nearly impossible to break at "typescript_as".