jdneo / vscode-checkstyle

Checkstyle extension for VS Code
https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-checkstyle
GNU Lesser General Public License v3.0
68 stars 15 forks source link

Missing support for specifying suppressions filter file and violations to ignore #335

Open luangong opened 2 years ago

luangong commented 2 years ago

It would be great if this extension supports for specifying a suppressions filter config file without modifying the checkstyle config, because I’m currently using the Google Checks config that’s builtin to Checkstyle so the VSCode settings look like this:

{
  "java.checkstyle.version": "9.3",
  "java.checkstyle.configuration": "/google_checks.xml"
}

Here I’m using Checkstyle 9.3 because it’s the newest version that’s compatible with Java 8 and Checkstyle v10+ requires Java 11.

I don’t want to copy google_checks.xml into my workspace and add suppressions filter there because I’ll then have to maintain it myself. For example, if later I decide to use Checkstyle 10.2 along with Java 11, I’ll have to copy the google_checks.xml file from their GitHub repo at that particular version tag and then merge it with my local config and resolve any conflicts.

What’s nice about the Maven Checkstyle plugin is that it allows me to specify the location of the suppressions filter file with the <suppressionsLocation> property and to ignore certain violations with the <violationIgnore> property like this:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <version>${maven-checkstyle-plugin.version}</version>
  <dependencies>
    <dependency>
      <groupId>com.puppycrawl.tools</groupId>
      <artifactId>checkstyle</artifactId>
      <!-- https://checkstyle.org/#JRE_and_JDK -->
      <version>${checkstyle.version}</version>
    </dependency>
  </dependencies>
  <configuration>
    <configLocation>google_checks.xml</configLocation>
    <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
    <encoding>UTF-8</encoding>
    <consoleOutput>true</consoleOutput>
    <violationIgnore>MissingJavadocMethod,MissingJavadocType</violationIgnore>
    <violationSeverity>warning</violationSeverity>
  </configuration>
</plugin>

I would be great if this extension also supports these features and the VSCode settings may look like this:

{
  "java.checkstyle.verison": "9.3",
  "java.checkstyle.configuration": "/google_checks.xml",
  "java.checkstyle.suppressionsLocation": "checkstyle-suppressions.xml",
  "java.checkstyle.ignoreViolations": [
    "MissingJavadocMethod",
    "MissingJavadocType"
  ]
}

The content of checkstyle-suppressions.xml is like this:

<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN" "https://checkstyle.org/dtds/suppressions_1_0.dtd">
<suppressions>
  <suppress checks="MissingJavadocMethod" files=".*" />
  <suppress checks="MissingJavadocType" files=".*" />
</suppressions>

Note that specifying the location of suppressions filter and specifying violations to ignore are equivalent in the above case.