checkstyle / patch-filters

Suppression Filter for Checkstyle that is based on patch file
GNU Lesser General Public License v2.1
4 stars 7 forks source link

Share in documentaiton ability to validate few last commits #351

Open romani opened 1 year ago

romani commented 1 year ago

detected at https://github.com/checkstyle/eclipse-cs/pull/350

Pull request contains several commits. on local history is linear, so patch using your last commit ONLY. in Travis CI, all commits are combined as one merge commit that is applied over master HEAD (it is non configurable feature of Travis) to not execute CI on old code and clearly know result after merge.

how to generate last commit file in maven: https://github.com/checkstyle/eclipse-cs/blob/3522eb691c7c1ad230900c6c26754783121d5154/pom.xml#L118-L120

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                      <phase>verify</phase>
                      <goals>
                        <goal>exec</goal>
                      </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>git</executable>
                    <arguments>
                      <argument>diff</argument>
                      <argument>HEAD~1</argument>
                      <argument>HEAD</argument>
                    </arguments>
                    <outputFile>${maven.multiModuleProjectDirectory}/show.patch</outputFile>
                </configuration>
            </plugin>

checkstyle config: https://github.com/checkstyle/eclipse-cs/blob/2cb3fb24be136882706b2dd4edd75ed31f9d6dae/config/checkstyle_sevntu_checks.xml#L15-L24

  <module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
    <property name="file" value="show.patch"/>
    <property name="strategy" value="patchedline" />
  </module>

  <module name="TreeWalker">
    <module name="com.puppycrawl.tools.checkstyle.filters.SuppressionJavaPatchFilter">
      <property name="file" value="show.patch"/>
      <property name="strategy" value="patchedline" />
    </module>

We need to find a way to generate patch file in same way as it is done by Travis to show whole code change diff in Pull Request or last changes. As not all in world use Travis, all other CIs does not make merge commit.


Without this smart patch generation there is gap in Patch filter to let uses put meaningless commit on top to hide all violations from previous commits. But in the same time it helps to bypass situations with avalanche of checkstyle violations (fix one violation, trigger changes in other lines, fixing them, another line affected, new violations, ......) and merge with failures in CI and have green build after merge.