-
Notifications
You must be signed in to change notification settings - Fork 2
Checkstyle setup
Wiki > The GUI > Eclipse > Check Style setup
Check style is set up by:
You may need to install an older version to be compatible with our checkstyle config in case our dependencies are not up to date.
- Help --> Install New Software
- Add new site (Name: Checkstyle, Location: https://checkstyle.org/eclipse-cs-update-site)
- Uncheck "Show only latest versions of available software"
- Uncheck "Hide Items that are already installed"
- Install the correct version of "Eclipse Checkstyle Plug-in"(at the moment this is v
10.0.0
). If you see another version in the list that is already installed, you need to uninstall it first: Go toHelp > About Eclipse IDE > Installation Details
, search for "checkstyle" in the list of installed software and clickUninstall
- In Eclipse open checkstyle settings via
Window
>Preferences
>Checkstyle
- If you have an existing "IBEX Checks" entry using an internal configuration, remove it. If it complains about the configuration currently being used in projects, you may have to remove and re-import all projects before you remove this config.
- Add a new check configuration by clicking
New...
next to the table - Set the following
- File: External configuration file
- Name: IBEX Checks
- Location:
C:\Instrument\Dev\ibex_gui\base\uk.ac.stfc.isis.ibex.client.tycho.parent\checkstyle.xml
-
Additional Properties
button-
Add...
button - Set:
- Name: checkstyle.suppressions.file
- Value: C:\Instrument\Dev\ibex_gui\base\uk.ac.stfc.isis.ibex.client.tycho.parent\suppressions.xml
-
- Apply and close: you should now be setup
- If you have issues with the highlight colour on a dark theme you can go to: Window -> Preferences, General -> Editors -> Text Editors -> Annotations to change it.
-
Suppose you run build.bat and there are checkstyle violations.
-
Open the file checkstyle-result.xml in the particular project you have issues, it will show you the error, for example: <error line="29" column="9" severity="warning" message="Missing a Javadoc comment." source=
"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck"/>
-
In the example above the error is generated by the checker
JavadocVariableCheck which implies that the variable defined in line#29 doesn't have a javadoc
. -
It is possible that for this variable javadoc isn't necessary. For examples it is a file with lots of constants identifying magic numbers and strings. It is impractical to provide javadoc for all of them.
-
In such case we might want to suppress the checkstyle inspection for this file. There are two ways of doing it:
5.1 - Locate the suppressions.xml file and mention the file name or pattern to skip processing. This is useful when you have a class of files you wish to skip, for examples test files. Different patterns can be separated by '|' as it is a regular expression.
5.2 It may be more relevant to only suppress for a specific file or method or variable. In this case we can use the annotation @SuppressWarnings("checkstyle:"). Recall the example above where the error was from the checker
JavadocVariableCheck
. The tag to use in this case isjavadocvariable
- take the checker class name, remove the word Check at the end and replace all capital letters by small hand letters. -
Run the build again, the checkstyle violations will be suppressed.