Skip to content

Renamed-and-modified files suppress violations on their changed lines #428

Description

@aclfe

Checkstyle jar: checkstyle-13.6.0-all.jar
Checkstyle patchjar: checkstyle-patchfilter-all.jar

╰─$ cat Bar.java

package Checker;

public class Foo {
    public static void main(String[] args) {
        System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
        System.out.println();
        System.out.println();
    }
}

╰─$ cat rename.patch

diff --git a/Foo.java b/Bar.java
similarity index 55%
rename from Foo.java
rename to Bar.java
index d188913..400ac79 100644
--- a/Foo.java
+++ b/Bar.java
@@ -2,7 +2,7 @@ package Checker;

 public class Foo {
     public static void main(String[] args) {
-        System.out.println("short");
+        System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
         System.out.println();
         System.out.println();
     }

╰─$ cat config-nofilter.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="LineLength">
    <property name="max" value="80"/>
  </module>
</module>

╰─$ cat config.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="LineLength">
    <property name="max" value="80"/>
  </module>
  <module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
    <property name="file" value="rename.patch" />
    <property name="strategy" value="patchedline" />
  </module>
</module>

Command:
java -classpath checkstyle-13.6.0-all.jar:checkstyle-patchfilter-all.jar com.puppycrawl.tools.checkstyle.Main -c config-nofilter.xml Bar.java shows

Starting audit...
[ERROR] /home/aclfe/Desktop/C1/testing/Bar.java:5: Line is longer than 80 characters (found 117). [LineLength]
Audit done.
Checkstyle ends with 1 errors.

java -classpath checkstyle-13.6.0-all.jar:checkstyle-patchfilter-all.jar com.puppycrawl.tools.checkstyle.Main -c config.xml Bar.java
shows

Starting audit...
Audit done.

You can see config-nofilter.xml shows the violation exists, but the filer config itself doesn't throw an error. The fix lies in src/main/java/com/puppycrawl/tools/checkstyle/filters/LoadPatchFileUtils.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions