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

  1. Open IntelliJ IDEA
  2. Open Preferences
  3. Open PlugIns
  4. Search by CheckStyle and select "CheckStyle-IDEA"
  5. Click the install button
  6. Restart IntelliJ IDEA
  7. Checkstyle items are added to Preferences

image

スクリーンショット 2018-06-23 13.00.15.png

CheckStyle-Use checkstyle.xml definition for IDEA

  1. Open Checkstyle in Preferences
  2. Click the + button in the Configration File item
  3. Select the checkstyle.xml created above, also enter a name
  4. 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

スクリーンショット 2018-06-23 13.01.33.jpg

Code check screen by Checkstyle

スクリーンショット 2018-06-23 13.04.13.png

Reflect the contents of checkstyle.xml in the code formatter of IntelliJ IDEA

  1. Preferences-> Editor-> Open Java
  2. Click the gear mark in the Scheme item
  3. Click Import Scheme-> CheckStyle Configuration
  4. Select the checkstyle.xml created above
  5. The contents of the formatter will be those of checkstyle.xml
  6. 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

スクリーンショット 2018-06-23 13.06.22.png

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.

Recommended Posts

Java --Introduce CheckStyle plugin to IntelliJ IDEA and reflect it in formatter
Optimize Java import declarations in IntelliJ IDEA
Java to C and C to Java in Android Studio
About Stream Debugger in IntelliJ IDEA plugin
Creating a project (and GitHub repository) using Java and Gradle in IntelliJ IDEA
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
Deploy Java application developed in IntelliJ IDEA environment to Alibaba Cloud ECS instance
Settings to display Japanese Javadoc in IntelliJ IDEA
Until you create a Spring Boot project in Intellij and push it to Github
How to use java non-standard library on IntelliJ IDEA
Write a class in Kotlin and call it in Java
How to convert A to a and a to A using AND and OR in Java
Gzip-compress byte array in Java and output to file
How to write comments in the schema definition file in GraphQL Java and reflect them in GraphQL and GraphQL Playground
[Java] A technique for writing constructors, getters, and setters in one shot with IntelliJ IDEA.
Assign a Java8 lambda expression to a variable and reuse it
[Java] Change language and locale to English in JVM options
Failed to launch checking at Kotlin Koans in IntelliJ IDEA
Implement Java Interface in JRuby class and call it from Java
What happened in "Java 8 to Java 11" and how to build an environment
How to call and use API in Java (Spring Boot)
Reasons to use Servlet and JSP separately in Java development
How to develop and register a Sota app in Java
Differences in how to handle strings between Java and Perl
Write Processing in IntelliJ IDEA
Install the memcached plugin on MySQL and access it from Java
How to try Java preview features (such as Java 15 Record) in IntelliJ
Unable to get resources when using modules in Gradle and IntelliJ
How to create a new Gradle + Java + Jar project in Intellij 2016.03
AtCoder ARC 081 C hash to solve in Ruby, Perl and Java
[Android] Convert Map to JSON using GSON in Kotlin and Java
Sample to read and write LibreOffice Calc fods file in Java 2021
Steps to install Maven on Mac and use it in Eclipse
Introduce R v3.4.1 and various packages to CentOS 6.4 in offline environment
How to encrypt and decrypt with RSA public key in Java
Conveniences I've been using since migrating from Eclipse to IntelliJ IDEA (in terms of search and Git)