Skip to main content

Setting Up and Using CheckStyle-IDEA Plugin

What is the CheckStyle-IDEA Plugin?

The plugin is a linter that will highlight code style violations as warnings in IntelliJ IDEA.

Why using it?

Your code will be graded on style. This plugin allows you to easily spot violations so you can avoid losing easy points on your programming homework. In addition, our style grader on Gradescope will grade based on the configurations set up in the plugin. In other words, Gradescope and this plugin will look for the same style violations.

Installing the CheckStyle-IDEA Plugin

NOTE: This guide is based on version 2021.3. The following steps may vary depending on your IntelliJ IDEA version.

  1. Open [IntelliJ IDEA → Preferences] on macOS (or [File → Settings] on Windows/Linux)
  2. Go to [Plugins tab → Marketplace → search CheckStyle-IDEA]
  3. Install the one that matches the name completely
  4. Restart IntelliJ IDEA

Setting Up the Plugin

NOTE: If you don’t want to repeat the following setup every time you open a project, first navigate to Settings for New Projects by clicking on [File → New Projects Setup → Settings/Preferences for New Projects], or [Customize → All settings…] from the welcome page. Then complete all the following setup.

Otherwise, if you want to modify the settings for a specific project, you can go to [IntelliJ IDEA → Preferences] on macOS or [File → Settings] on Windows/Linux. Note that Settings for New Projects does not affect any settings for projects you have already opened/imported, so you may need to go back and modify those on your own.

Once the plugin is installed, you will see a new tab in your Settings window (via [IntelliJ IDEA → Preferences] or [File → Settings]) labeled Checkstyle (most likely located under the Tools tab). Try searching if you did not find it.

Once you are in the Checkstyle page, you will have to make sure the following configurations are correct:

Now click on the + sign of Configuration file. In the newly popped-up window:

  1. Fill in Description as what you like. CIS 1210 is a suggested name for this.
  2. Click on the radio box labeled Use a Checkstyle file accessible via HTTP.
  3. Fill in URL: https://gist.githubusercontent.com/wangkath/34ea2b9cc7518af4145911de817e64c4/raw/c7694e47d34830b5411451147f1771402d589514/config.xml
  4. Click Next when you are done. If an error occurs, ignore and try again
  5. In the next window for the Property Name labeled filter, double click on the corresponding Value field, and fill in https://gist.github.com/superfashi/b6d24924830f45fae5786cdcee02f049/raw/520f9d293217d731e47bdc4fa0a8b2a529a4e50c/suppressions.xml
  6. Click Next when you are done. If an error occurs, click Previous and try again
  7. If you see “The rules file has been validated and is ready to add.” Click Finish to close the window

Make sure for all selectables under Configuration File, check and only check Active for your newly added configuration file. Click on OK to save your changes.

Using the Plugin

  1. Open or create a Java project
  2. On the bottom of your window you should see a new tab labeled CheckStyle
  3. Click on it and you should see a newly opened window
  4. On the left of the window you should see a few options including Check Current File (the green triangle button), as well as Check Module and Check Project, which are directly below the triangle
  5. Click on which you find needed; the result will be outputted in the window with the line number and the type of violation (i.e. incorrect indentation level, etc.)

If you want to toggle real-time checkstyle warnings within a project, navigate to [IntelliJ IDEA → Preferences] on macOS or [File → Settings] on Windows/Linux and navigate to [Editor → Inspections]. Search for Checkstyle and you should be able to toggle “Checkstyle real-time scan” on and off or make other customizations.