Skip to content

IntelliJ Plugin - Formatting non-Java files #363

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

Closed
seadub opened this issue Apr 11, 2019 · 8 comments
Closed

IntelliJ Plugin - Formatting non-Java files #363

seadub opened this issue Apr 11, 2019 · 8 comments

Comments

@seadub
Copy link

seadub commented Apr 11, 2019

IntelliJ Version 2018.3
google-java-format IntelliJ Plugin version 1.7.0.1

Trying to isolate code formatting changes to Java classes. The indentation seems to impact all files, including XML, YAML, and more.

Can we isolate this configuration to only Java files?

@plumpy
Copy link
Collaborator

plumpy commented Apr 11, 2019

google-java-format doesn't have any idea how to format XML, YAML, or any other files, so there's no way it could be doing that. You must be using IntelliJ's built-in code formatter for those. Can you better describe what you're doing and what's happening that you don't expect?

@seadub
Copy link
Author

seadub commented Apr 11, 2019

The built-in formatter is being used, this may be more of an issue with using the recommended configuration file for import ordering found on the readme:

https://raw.githubusercontent.com/google/styleguide/gh-pages/intellij-java-google-style.xml

I've reviewed the impacted file type configurations, and can isolate this to the following after comparing manually with IntelliJ's "Default" IDE settings:
JavaScript
JSON
TypeScript
XML
Other File Types

@plumpy
Copy link
Collaborator

plumpy commented Apr 11, 2019

Ah, yeah, I see what you're saying. The important thing is to modify your Settings→Editor→Code Style→Java→Import Layout to look like this:
https://ibb.co/Q84XFdG

The rest of that file unimportant, and telling people to import the entire thing is definitely not ideal. I'll see if I can think of something better.

@tbroyer
Copy link
Contributor

tbroyer commented Apr 11, 2019

@plumpy Wouldn't you also want to set the threshold for star imports to a high enough value that it won't ever be reached, and possibly also empty the list of packages to always star-import? (from memory, don't have my IntelliJ at hand right now)

@jbduncan
Copy link
Contributor

jbduncan commented Apr 12, 2019

@seadub I don't think anybody has raised this yet, but the google-java-format plugin for IntelliJ is actually different to the XML file that you linked in your most recent message.

The XML file is used to configure IntelliJ's built-in formatter; by comparison the plugin delegates to google-java-format, which is a separate project that Googlers started because IntelliJ's formatter isn't quite powerful enough to allow code to be formatted according to the Google Java Style Guide - the XML file is just an approximation. :)

@plumpy
Copy link
Collaborator

plumpy commented Apr 12, 2019

@seadub was referencing the instructions, however, which do tell you to import that XML file. This is because google-java-format isn't fully capable of managing your imports. (For example, the style guide forbids wildcard imports, but since google-java-format only knows about a single file at a time, it can't resolve wildcard imports into fully-qualified imports.)

And yes, as @tbroyer mentioned, if you don't import the file, you also need to set the import counts to 999 (thanks for the reminder!):
https://ibb.co/qkhxqym

@seadub
Copy link
Author

seadub commented Apr 12, 2019

@jbduncan I did notice that distinction after @plumpy provided some feedback.
I am hoping that we can modify the linked file to adjust this configuration to base off of the default IntelliJ format profile, and only impact Java code formatting. I will spend some time reviewing this configuration and see about creating a PR if that file is managed in the project anywhere.

@seadub
Copy link
Author

seadub commented Apr 15, 2019

PR here: google/styleguide#447

@seadub seadub closed this as completed Apr 15, 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

4 participants