Skip to content

Prettier extends and implements when not fitting in same line - #3689

Merged
azz merged 8 commits into
prettier:masterfrom
tvonhacht:extends_implements
Jan 13, 2018
Merged

azz merged 8 commits into
prettier:masterfrom
tvonhacht:extends_implements

Conversation

@tvonhacht

Copy link
Copy Markdown
Contributor

Please see screenshot for how it looks like:
Screen_Shot_2018_01_09_at_8_40_09_AM

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".

@azz azz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks really good!

Interface5,
Interface6,
Interface7,
Interface8 {} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a blank line at the end here.

@tvonhacht tvonhacht Jan 10, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by this?

Interface5,
Interface6,
Interface7,
Interface8*added*
{}

Interface5,
Interface6,
Interface7,
Interface8 {}
*added*

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@azz please check :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Files should have a blank line at the end of them so the snapshots look right.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done :)


(class A extends B // comment1
(class A
extends B // comment1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it should break just because there's a comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will try to figure it out :)

class Foo
extends Immutable.Record({
ipaddress: ""
}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we inline only if it is a CallExpression?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What could be a good way is to keep the previous implementation if there’s just a single extend. Otherwise use your new logic

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

React.Component<...> is not a call expression

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We do want a long identifier to break, though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Once you decided when not to break (which expression), i will continue with this :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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.

@vjeux

vjeux commented Jan 10, 2018

Copy link
Copy Markdown
Contributor

Btw this is great but is going to cause a bunch of formatting changes so we should hold it off after tomorrow’s release

Comment thread src/main/comments.js Outdated
}
const isBlock = util.isBlockComment(comment);

// Workaround for comments that are in the superClass definition ( extends ...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is this workaround ok?
Feels dirty to me but there was no other way to get the parentNode of the parentNode

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

commentPath.getParentNode(3) === "superClass"?

or maybe it’s 2.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for the quick feedback :)

@vjeux

vjeux commented Jan 12, 2018

Copy link
Copy Markdown
Contributor

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 :)

@vjeux

vjeux commented Jan 13, 2018

Copy link
Copy Markdown
Contributor

Thanks, the examples on the last commit look good on my end :)

@tvonhacht

Copy link
Copy Markdown
Contributor Author

@vjeux its now like you want it, only one extends is old behaviour :)
@azz can you check and merge? :)

@azz azz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, one comment.

Comment thread src/main/comments.js Outdated
return concat([" ", contents]);
}

// console.log("trailing comment");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you delete these comments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh man that's embarassing...
Fixed now :)

@tvonhacht

Copy link
Copy Markdown
Contributor Author

@azz fixed :) finally done? :)

@azz
azz merged commit 1a1de60 into prettier:master Jan 13, 2018
@azz

azz commented Jan 13, 2018

Copy link
Copy Markdown
Member

🎉 Thanks!

@tvonhacht
tvonhacht deleted the extends_implements branch January 13, 2018 16:32
@lock lock Bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 18, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants