Wayback Machine
83 captures
16 Apr 2020 - 27 May 2025
May AUG Sep
Previous capture 03 Next capture
2021 2022 2023
success
fail
About this capture
COLLECTED BY
Collection: Save Page Now
TIMESTAMPS
loading
The Wayback Machine - https://web.archive.org/web/20220803181603/https://code.visualstudio.com/docs/java/java-linting
Skip to content  Visual Studio Code
  • Docs
  • Updates
  • Blog
  • API
  • Extensions
  • FAQ
  • Learn
  • Search
  • Search Search
  • Download VS Code Download VS Code Download

Version 1.69 is now available! Read about the new features and fixes from June.

Dismiss this update
'; document.body.appendChild(div.children[0]); } function pushCodingPackEvent(language, os) { let id = `${language}-${os}-coding-pack`; var analytics = window.vscodeAnalytics; analytics && analytics.event( 'click', 'download', id, ); }
  • Overview
  • Setup
    • Overview
    • Linux
    • macOS
    • Windows
    • Raspberry Pi
    • Network
    • Additional Components
    • Enterprise
    • Uninstall
  • Get Started
    • Intro Videos
    • Tips and Tricks
    • User Interface
    • Themes
    • Settings
    • Key Bindings
    • Display Language
    • Telemetry
  • User Guide
    • Basic Editing
    • Extension Marketplace
    • IntelliSense
    • Code Navigation
    • Refactoring
    • Debugging
    • Version Control
    • Working with GitHub
    • VS Code for the Web
    • Tasks
    • Settings Sync
    • Snippets
    • Emmet
    • Command Line Interface
    • Workspace Trust
    • Multi-root Workspaces
    • Accessibility
  • Terminal
    • Terminal Basics
    • Shell Integration
  • Languages
    • Overview
    • JavaScript
    • JSON
    • HTML
    • CSS, SCSS and Less
    • TypeScript
    • Markdown
    • PowerShell
    • C++
    • Java
    • PHP
    • Python
    • Julia
    • R
    • Rust
    • Go
    • T-SQL
    • C#
    • .NET
  • Node.js / JavaScript
    • Working with JavaScript
    • Node.js Tutorial
    • Node.js Debugging
    • Node.js Deployment
    • Browser Debugging
    • Angular Tutorial
    • React Tutorial
    • Vue Tutorial
    • Ember Tutorial
    • Debugging Recipes
    • Extensions
  • TypeScript
    • Tutorial
    • Compiling
    • Editing
    • Refactoring
    • Debugging
  • Python
    • Tutorial
    • Editing Code
    • Linting
    • Debugging
    • Environments
    • Testing
    • Data Science
    • Python Interactive
    • Django Tutorial
    • Flask Tutorial
    • Create containers
    • Python on Azure
    • Settings Reference
  • Java
    • Getting Started
    • Navigate and Edit
    • Refactoring
    • Formatting and Linting
    • Project Management
    • Build Tools
    • Run and Debug
    • Testing
    • Spring Boot
    • Application Servers
    • Java on Azure
    • GUI Applications
    • Extensions
    • FAQ
  • C++
    • Intro Videos
    • GCC on Linux
    • GCC on Windows
    • GCC on Windows Subsystem for Linux
    • Clang on macOS
    • Microsoft C++ on Windows
    • Build with CMake
    • CMake Tools on Linux
    • Editing
    • Debugging
    • Configure debugging
    • Settings
    • Configure IntelliSense for cross-compiling
    • FAQ
  • Containers
    • Overview
    • Node.js
    • Python
    • ASP.NET Core
    • Debug
    • Docker Compose
    • Registries
    • Deploy to Azure
    • Choose a dev environment
    • Customize
    • Develop with Kubernetes
    • Tips and Tricks
  • Data Science
    • Overview
    • Jupyter Notebooks
    • Data Science Tutorial
    • Python Interactive
    • PyTorch Support
    • Azure Machine Learning
  • Azure
    • Extensions
    • Deployment
    • Remote Debugging for Node.js
    • Docker
    • MongoDB
    • Kubernetes
    • Azure Kubernetes Service
  • Remote
    • Overview
    • SSH
    • Containers
    • Windows Subsystem for Linux
    • GitHub Codespaces
    • VS Code Server
    • SSH Tutorial
    • Containers Tutorial
    • WSL Tutorial
    • Attach to Container
    • Create a Dev Container
    • Advanced Containers
    • devcontainer.json
    • devcontainer CLI
    • Tips and Tricks
    • FAQ

Topics

Java formatting and linting

Language Support for Java™ by Red Hat also provides formatting settings. You can export an Eclipse formatter file and then use it for your project in VS Code.

In addition, there are also the Checkstyle for Java and SonarLint extensions, which provide features for live linting and code analysis.

Formatter

You can use Format Document command to format a Java file. If you didn't specify a formatter profile before, the Java file will be formatted using default settings.

Applying formatter settings

You can easily apply formatter settings from an existing formatter profile in Eclipse scheme. For example, if you want to apply Google Style for your Java project, then you can set the following property in settings.json:

"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",

The property can be set to a URL or a local file path. If the formatter XML file contains more than one profile, you can specify the profile name:

"java.format.settings.profile": "GoogleStyle",

After setting the formatter profile, the Format Document command will use the specific profile to format your Java files.

Editing formatter settings

The Extension Pack for Java provides an editor to help users edit an existing formatter profile. You can open the editor with the command Java: Open Java Formatter Settings with Preview. In the editor, you can change the formatter settings and preview the effects. After saving the current editor, the changes will be saved to the formatter profile.

Note: the formatter settings editor supports only local formatter profile. If your workspace contains a remote formatter profile, it will guide you to download it in .vscode folder.

When editing settings in the editor, you can preview the changes' effects in the right Preview panel.

You can also undo and redo changes.

SonarLint

SonarLint is an easy-to-use extension that helps you find and fix bugs and security issues as you code. The extension runs in the background and, just like a spell checker, highlights source code issues that pose a quality or security concern. The extension not only tells you what the issue is but also provides in-context guidance on why it's harmful and how to fix it, with examples. The extension supports over 500+ Java rules and includes several Quick Fixes to automatically fix certain quality issues.

Code analysis on the fly

Issues are highlighted directly in the editor with hovers to provide detailed explanations.

Issues found in the opened file can also be reviewed through the Problems panel of VS Code. When applicable, secondary code locations are mentioned so you can understand where the issue originates from (for example, the code path that led to a bug).

Rule documentation and remediation guidance

For any issues detected, SonarLint provides full documentation about the rule that was violated, and the best coding practice it relates to. This allows you to understand why an issue is raised, and how to fix it.

Enabling more quality and security rules

By default, SonarLint provides a wide array of rules to detect bugs and vulnerabilities. More checks can be enabled through the SonarLint Rules view.

For more details about the SonarLint for VS Code extension, visit the SonarLint website.

Checkstyle

With the Checkstyle for Java extension, you can use either existing checkstyle configurations (Google's or Sun's Check) or your own customized files for your project. When editing a Java file, the extension will check the file format and provide Quick Fixes if possible on the fly.

Set Checkstyle configuration file using the Checkstyle: Set the Checkstyle Configuration File command and selecting the Checkstyle file from the dropdown.

The Checkstyle for Java extension supports live linting.

And batch check.

The Problems panel will open when you click the Checkstyle status icon in the Status bar.

Set Checkstyle configuration file

To set the configuration file, right-click the .xml file and select Set the Checkstyle Configuration File.

Set Checkstyle configuration file

You can also trigger the command Checkstyle: Set Checkstyle Configuration File to choose the configuration file in the File Explorer. The extension looks for a checkstyle.xml file in your workspace to make Checkstyle configuration easier. You will also see the two built-in configurations:

  • Google's Check
  • Sun's Check

The command Checkstyle: Set the Checkstyle Configuration detects potential Checkstyle configuration files and lists them. You can also provide a configuration file by directly writing a URL in the input box.

You can also set the Checkstyle version by using the command Checkstyle: Set the Checkstyle Version.

The command will:

  • List the latest Checkstyle version from the main repo.
  • List all the downloaded versions.
  • List all the supported versions.
  • Mark the currently used version with a check symbol.

In addition, you can also bring any 3rd-party modules for Checkstyle by configuring its path. For example, after using the configuration below, you can add <module name="SingleBreakOrContinueCheck"/> or <module name="com.github.sevntu.checkstyle.checks.naming.SingleBreakOrContinueCheck"/> to checkstyle.xml to use those checks.

"java.checkstyle.modules": [ "${workspaceFolder}/src/main/resources/sevntu-checks-1.35.0.jar" ]

Check the style and fix the violations

When editing a Java file, the extension will check the file format and provide Quick Fixes if possible. You can click the lightbulb button in the editor to show the available Quick Fixes.

Fix style violation

For more details about Checkstyle for Java, visit its GitHub Repository.

12/12/2021

In this article there are 3 sectionsIn this article

  • Formatter
  • SonarLint
  • Checkstyle
  • Hello from Seattle.
  • Follow @code
  • Support
  • Privacy
  • Manage Cookies
  • Terms of Use
  • License
Microsoft homepage Microsoft homepage © 2022 Microsoft