Java --Introduce CheckStyle plugin to IntelliJ IDEA and reflect it in formatter
Don't write code with the CheckStyle definition in mind, and let the Intelli IDEA formatter do most of the work.
Create checkstyle.xml
Create something to use in the project.
Introduction of IntelliJ IDEA plug-in "CheckStyle-IDEA"
procedure
- Open IntelliJ IDEA
- Open Preferences
- Open PlugIns
- Search by CheckStyle and select "CheckStyle-IDEA"
- Click the install button
- Restart IntelliJ IDEA
- Checkstyle items are added to Preferences
image
CheckStyle-Use checkstyle.xml definition for IDEA
- Open Checkstyle in Preferences
- Click the + button in the Configration File item
- Select the checkstyle.xml created above, also enter a name
- The added definition will be added to the Configuration File. Click the checkbox to enable it.
With the above work, you can now check the code with CheckStyle on IntelliJ IDEA.
image
Checkstyle settings
Code check screen by Checkstyle
Reflect the contents of checkstyle.xml in the code formatter of IntelliJ IDEA
- Preferences-> Editor-> Open Java
- Click the gear mark in the Scheme item
- Click Import Scheme-> CheckStyle Configuration
- Select the checkstyle.xml created above
- The contents of the formatter will be those of checkstyle.xml
- When you execute the format on the editor, it will be formatted with the set contents.
If you arrange it with a formatter, you will hardly get angry with CheckStyle. The contents of JavaDoc, such as no trailing period, are not formatted by the formatter, so not all are resolved.
image
Summary
If you loosely unify the code format, you don't need that much, but if you try to play at the error level at build time, the coding work itself will become tight. If the code format is incorrect in the team, it will be a cost for the confirmation side, so I would like to automate it as much as possible and reduce the part that can be managed by the mind.
Also, many open source projects these days seem to be based on Google Java Style. When you publish something, it seems to be easy for other programmers if you follow them.