Skip to content

Java: Ensure Java formatting when editing on VS Code / IntelliJ#1396

Closed
brunoborges wants to merge 14 commits intomicrosoft:experimental-javafrom
brunoborges:java-format-vscode
Closed

Java: Ensure Java formatting when editing on VS Code / IntelliJ#1396
brunoborges wants to merge 14 commits intomicrosoft:experimental-javafrom
brunoborges:java-format-vscode

Conversation

@brunoborges
Copy link
Member

This PR enables a Run On Save on VS Code that will format the modified Java code according to the project settings (Google Format with AOSP style).

@brunoborges brunoborges changed the base branch from main to experimental-java June 9, 2023 18:48
It uses the Google Java Format command line tool to quickly perform the formatting on save
@adrianwyatt adrianwyatt added the java Issue or PR regarding Java code label Jun 9, 2023
@shawncal shawncal changed the title Ensure Java formatting when editing on VS Code Java: Ensure Java formatting when editing on VS Code Jun 12, 2023
@johnoliver
Copy link
Member

Is the only way to get formatting on vs code to have a jar checked in to the repo?

@d3r3kk
Copy link
Contributor

d3r3kk commented Jun 14, 2023

Is the only way to get formatting on vs code to have a jar checked in to the repo?

Not likely. The plugin/extensions for VSCode likely pull in whatever dependencies you need instead. I'd take a look at .vscode/extensions.json for dictating the recommended extensions for this project.

@brunoborges
Copy link
Member Author

This was the only true cross-platform way to get Google Java Format with AOSP style to work on VS Code.

@brunoborges
Copy link
Member Author

Commit 47cf4d0 moves the formatting plugin to the general profile of the Maven project.

This way, no matter when/how the Maven project is built (command-line, terminal, etc), the code will be formatted.

But the VS Code setting is still required as it ensures new code comes with the right formatting, and solves the problem of when a developer adds a Java class without running a build (unlikely, but still...)

@brunoborges brunoborges changed the title Java: Ensure Java formatting when editing on VS Code Java: Ensure Java formatting when editing on VS Code / IntelliJ Jun 14, 2023
@brunoborges
Copy link
Member Author

We have decided to fix the /spotless PR helper command, and then simply fail the build if the formatting is wrong, and give the PR author and other maintainers to fix formatting with said command.

Meanwhile, IDEs may be configured manually by the developer with the AOSP Google Format style, but that setting doesn't have to be in the repository. We may change the style later, to something that both IntelliJ and VS Code can share certainly (not the case for AOSP).

For now, PR authors should definitely build the project with -Pbug-check before pushing changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Issue or PR regarding Java code

Projects

No open projects
Status: Sprint: Done

Development

Successfully merging this pull request may close these issues.

5 participants