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

Don't reformat 'javadoc' comments that appear before package/imports, to avoid mangling license headers #235

Open
pettermahlen opened this issue Dec 8, 2017 · 7 comments

Comments

@pettermahlen
Copy link

The use case is license headers added by, for instance, maven license plugins. These headers are not by default formatted in the way that google-java-format requires, and since neither (for good reasons - neither code styles nor licenses should be changed lightly) are very configurable, conflicts are hard to avoid. (The mycila license plugin allows configuration, and with a bit of effort, you can make it create license headers that don't get reformatted - I haven't succeeded to do that with the Codehaus plugin).

Creating this issue as a different one than #139, which is about javadoc comments.

@cushon
Copy link
Collaborator

cushon commented Dec 8, 2017

Do you have an example of a license header with >100 column lines that get wrapped by the formatter?

@pettermahlen
Copy link
Author

pettermahlen commented Dec 11, 2017

I have an example with <100 line columns that gets reformatted: https://github.com/pettermahlen/format-example.

I wasn't able to reproduce it easily this morning, but I also ran into a situation where lines < 100 columns got reformatted, at the same time introducing <p> tags where there were empty lines. This was also with the exact same Apache license data, and the reformatting involved meant the lines were made longer, closer to 100 columns, I would expect, though I didn't verify that.

@cushon
Copy link
Collaborator

cushon commented Dec 11, 2017

In that example it's removing trailing whitespace from the lines before and after the line containing http://www.apache.org/licenses/LICENSE-2.0.

The other behaviour you describe (adding <p> tags and reflowing lines) would only happen if the license header was a javadoc comment, not a block comment.

@pettermahlen
Copy link
Author

pettermahlen commented Dec 11, 2017

Ah, yes, that makes sense. The mycila plugin uses javadoc formatting for license headers by default so it would have happened when I was experimenting with that.

@pettermahlen
Copy link
Author

And the reason for trying the mycila plugin out was because it doesn't add trailing whitespace, btw.

@kevinb9n
Copy link
Contributor

Would it be a good change if google-java-format refused to reformat any block comment that comes before the package/import statements?

@pettermahlen
Copy link
Author

That sounds pragmatic to me.

@cushon cushon changed the title Allow block comment formatting to be skipped. Don't reformat 'javadoc' comments that appear before package/imports, to avoid mangling license headers Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants