openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.09k stars 312 forks source link

Add support for MethodParamPadding to java style auto-detection #2098

Closed pway99 closed 1 year ago

pway99 commented 2 years ago

Issue discovered with src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java

Problem

Error: src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java:[494] (sizes) LineLength: Line is longer than 120 characters (found 124). Error: src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java:[494,84] (whitespace) ParenPad: '(' is not followed by whitespace. Error: src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java:[494,122] (whitespace) ParenPad: ')' is not preceded with whitespace.

Expected behavior

Method Parameter Padding and Line Lenght style violations should not fail

Example diff

         {
             try
             {
-                if ( sourceDirectoryToCheck.getCanonicalPath().startsWith( excludeDir.getCanonicalPath() ) )
+                if ( sourceDirectoryToCheck.getCanonicalFile().toPath().startsWith(excludeDir.getCanonicalFile().toPath()) )
                 {
                     getLog().debug( "Directory " + sourceDirectoryToCheck.getAbsolutePath()
                                         + " has been excluded as it matches excludeRoot "

https://github.com/apache/maven-build-cache-extension/blob/master/src/main/java/org/apache/maven/buildcache/CacheUtils.java

             while ( entry != null )
             {
                 Path file = out.resolve( entry.getName() );
+                if (!file.normalize().startsWith(out.normalize())) {
+                    throw new RuntimeException("Bad zip entry");
+                }
                 if ( entry.isDirectory() )
                 {
                     Files.createDirectory( file );

Recipes in example diff:

References:

pway99 commented 2 years ago

Still requires update for AutoDecting Spaces#Within.MethodCallParentheses