Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
luangong opened this issue Apr 29, 2022 · 0 comments

Comments

@luangong
Copy link

luangong commented Apr 29, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants