- Notifications
You must be signed in to change notification settings - Fork156
CheckStyle plug-in for IntelliJ IDEA
License
jshiell/checkstyle-idea
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
© Copyright CheckStyle-IDEA Contributors
Hosted onGitHub
A plug-in for JetBrains' IntelliJ IDEA 2023 and 2024 which provides real-time feedback against a givenCheckStyle 9-10 profile by way of an inspection.
Please note this is not an official part of Checkstyle - they neither endorsenor bear responsibility for this plugin. The logo is sourced from theCheckstyle resourcesrepositoryand used under theCC BY 4.0 licence.
Released under a BSD-style licence - please see the LICENCE file for details.
Once installed, a new inspection will be available in the group 'CheckStyle'. The 'Inspections' item in the preferencespanel will allow you to turn this on and to configure it.
Project exceptions are treated a little oddly. Because CheckStyle demands these to be on the current classpath, errorswill appear if these have not as yet been compiled. Further, because we cache the real-time checkers for performancereasons, real-time scans may continue to show the errors after a compilation. A static scan will force a reload of theChecker and should resolve this.
Configuration is available under theSettings dialogue, underTools ->Checkstyle. This controls configuration for both the inspection and staticscanning.
The main configuration option is that of the CheckStyle file. Multiple CheckStyle file may be added, and swapped betweenby using the checkbox. Files may be added using the 'Add' button, or you can use the versions of the standard Sun andGoogle configuration that are bundled with the selected version of Checkstyle.
If you need to pass authentication information for rules file accessed via HTTP then you can use thehttps://user:pass@host/
form to do so.
TheScan Test Classes checkbox will enable scanning of Java files under test source roots. If disabled, these fileswill be ignored.
If a custom file is being used and properties are available for definition then these will accessible using the 'EditProperties' button.
The following variables will be available if you have not otherwise overridden their values:
- basedir - mapped to the location of the current module file, or the project directory as a fallback.
- project_loc,workspace_loc - mapped to the project directory.
- config_loc,samedir - mapped to the directory the rules file is in, or the project directory for remote rulesfiles (e.g. HTTP).
This tab allows you to specify any third-party checks which your configuration file makes use of. All selecteddirectories/JAR files will be added to CheckStyle's classpath.
The option "Copy libraries from project directory" will tell Checkstyle-IDEA to do the following when creating customclassloaders:
- scan a module's classpath and select those library entries which reside somewhere below the project directory
- copy those libraries to a separate temporary directory (normally under
.idea
, if there is no.idea
directory,the system temp directory is used)
The internal classloaders will then use those copied libraries, thus preventing them from getting locked in the filesystem. Since this is mainly a problem on Windows, this feature is activated by default on Windows. If you know thatall your libraries reside outside of the project (as is often the case when build tools such as Maven or Gradle areused), then you can disable this feature. Since it slows down checker creation, you might want to keep it disableduntil necessary. After changing this option, it may be necessary to restart IDEA to see the effects.
Where you have a shared distribution it may be useful to add additional pre-bundled configurations. This can be doneby placing a JAR into thelib
directory of the plugin. The JAR should contain:
- A class that implements the
org.infernus.idea.checkstyle.csapi.BundledConfigProvider
interface - A text file
META-INF/service/org.infernus.idea.checkstyle.csapi.BundledConfigProvider
that contains the fully qualified classname of theBundledConfigProvider
- The Checkstyle rules XML file
At present theBundledConfigProvider
interface isn't available separately; hence you'll need the plugin JAR to compile.
If an error occurs during the check an exception will be thrown, which IDEA will then catch and display in the standardexceptions dialogue. If you're unsure as to why things are awry this would be your best bet - chances are it's a missingproperty or classpath pre-requisite.
sevntu.checkstyle offers a number of useful checks written by students of the Sevastopol National Technical University(SevNTU). They're also kind enough to offer instructions on setting them up with this plugin.
Checkstyle Addons offers additional Checkstyle checks not found in other Checkstyle extensions, and it's easy toset up in Checkstyle-IDEA.
Note that the plugin has been entirely developed on OS X - while it should be fine on Linux, I've no idea what resultyou'd get with Windows. YMMV.
The pre-requisites for the plugin are fairly light - you'll need Git and JDK 11. Make sure yourJAVA_HOME
environment variable is set correctly before invoking Gradle.
git clone https://github.com/jshiell/checkstyle-idea.git checkstyle-ideacd checkstyle-idea
You can then easily build via Gradle:
./gradlew clean build
To run it in a sandboxed IDEA, run:
./gradlew runIde
To debug the plugin, import the plugin into IDEA as a Gradle project, and then use therunIdea
Gradle target in debugmode.
If you're on OS X, use IDEA with the bundled JVM. Otherwise, please ensure IDEA is running using Java 11 or later.Jetbrains offer a support document on thissubject.
CheckStyle is unable to retrieve information on exceptions in your project until you have built it. Build your projectin IDEA and then rescan.
- If you import Gradle project withsCreate separate module per source set active in IDEA 2016 or above then themodule source paths are truncated. This means relative paths (e.g. suppressions on
src/test/.+
) may not work asexpected. - The plugin will throw exceptions if used with class files targeted at a later version than that of the JDK used byIDEA. Please run IDEA on the latest available JVM, ideally the bundled version from JetBrains where available.
- If you change the configuration options the real-time scan will not be updated until the file is either changed orreopened.
- We do not check if a property definition is required for a given file. Hence you can exit configuration withoutsetting required properties. Given, however, that CheckStyle files can change without the plug-in being aware this issomething we'll always have to live with to some degree.
- CheckStyle errors and warnings from the inspection are both shown at a single level, as IDEA will only allow onewarning level for an inspection.
Any comments or bug reports are most welcome - please visitthe project website onGitHub.
The debug logging of the plugin is arcane and not particularly well done, for which I can only thank myself. However, ifsuch context is needed then it can be seen by using IDEA'sHelp ->Debug Log Settings... and adding:
#org.infernus.idea.checkstyle
This plug-in owes its existence to both the style-overlords at work mandating compliance with a CheckStyleconfiguration, and theEclipse-CS authors for making me jealous of the real-timescan support available for Eclipse.
Thanks to those who have contributed work and effort directly to this project:
- J. G. Christopher
- jicken
- Jonas Bergvall
- Edward Campbell
- LightGuard.JP
- Gerhard Radatz
- Benjy W
- Yuri
- Kristin Young
- Simon Billingsley
- Miel Donkers
- Dmitrij (zherebjatjew)
- Thomas Jensen
- Rustam Vishnyakov (@dyadix)
- Thomas Harning (@harningt)
- František Hartman (@frant-hartm)
- Victor Alenkov (@BorzdeG)
- Baron Roberts (@baron1405)
- George Kankava (@georgekankava)
- Thomas Jensen (@tsjensen)
- Klaus Tannenberg (@KTannenberg)
- Nikolay Bespalov (@nikolaybespalov)
- @zentol
- Joey Lee (@yeoji)
- Tim van der Lippe (@TimvdLippe)
- @tduehr
- Mark Brown (@embee1981)
- Marshall Walker (@marshallwalker)
- Alexander Schwartz (@ahus1)
- Mustapha Zorgati (@mustaphazorgati)
- Roman Karpenko (@neomoto)
- Akash Mondal (@AkMo3)
- Bruno Masetto (@bmasetto)
- Robert Kruszewski (@robert3005)
- Hyeonmin Park (@kennysoft)
- Barnesly (@andrewflbarnes)
- Jan Köper (@JanK411)
- Jeremy Ziegler (@Uschi003)
- Ali Ustek (@austek)
- Richard (@rhierlmeier)
And also thanks are due to the authors and contributors of:
- Eclipse-CS, for inspiration and solutions to coding problems.
- JetStyle, for filling the area of static scanning and also giving me inspirations on coding solutions.
- CheckStyle, for without them we'd have merely void and chaos.
- JetBrains, for an IDE which is worth every penny and then some.
And a big thank-you to everyone who's sent me feedback or bug reports - both are much appreciated!
This code is released under a BSD licence, as specified in the accompanying LICENCE file.
Please seethe changelog.
About
CheckStyle plug-in for IntelliJ IDEA