This is a WIP community resource, containing contribution from community members.
Checkstyle is a development tool that helps you write clean, consistent, and readable Java code by automatically checking your source code against a set of predefined coding standards.
Given below are the steps to set up a Checkstyle plugin in VS Code so that VS Code can alert you about code style problems as you write code.
checkstyle.xml
and suppressions.xml
) should be in the ./config/checkstyle
directory, as mentioned here. The files can be copied from addressbook-level3
: checkstyle.xml and suppressions.xmlExtensions
-> Search Checkstyle for Java
-> Install (the first entry).File -> Open Folder...
.Check if the ./.vscode/settings.json
file exists. If not, create a folder .vscode
in the project root directory and add a file settings.json
within the .vscode
folder. This file contains configuration settings for projects in VS Code.
Add these configuration settings to the settings.json
file. These settings ensure that the Checkstyle extension uses the correct configuration files in the ./config/checkstyle
directory.:
{
"java.checkstyle.configuration": "${workspaceFolder}/config/checkstyle/checkstyle.xml",
"java.checkstyle.properties": {
"config_loc": "${workspaceFolder}/config/checkstyle"
}
}
workspaceFolder
refers to the root folder of the project (i.e., the folder you selected when you used File → Open Folder...)
.vscode
to your .gitignore
if you haven't done so by adding these few lines to the end of gitignore
:# VS Code
/.vscode/
Problems
tab in VS Code. For example, after changing the code to add a wildcard import, you can see that the wildcard import on line 11 has been detected by the Checkstyle extension:Troubleshooting tips
Sometimes, there may be errors in your set up although the Problems tab does not display any issues.
Here are some steps you can take if you encounter this issue:
settings.json
syntax is valid (e.g., no trailing commas)If you are using macOS and it does not seem to work, it may be due to macOS permissions or sandboxing. VS Code might not have access to all folders by default. To resolve this, go to System Settings → Privacy & Security → Full Disk Access and ensure that Visual Studio Code has full disk access.
Contributors: Brendon Koh (@brein62), Gabrielle Tan (@gabriellegtw)