Skip to content

Commit 15c27e4

Browse files
author
Vincent Potucek
committed
[Experimental] Add rewrite support for RemoveUnusedPrivateMethods & RemoveUnusedImports
1 parent 9bc702f commit 15c27e4

File tree

57 files changed

+137
-159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+137
-159
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
uses: gradle/actions/setup-gradle@v4
3232
- name: spotlessCheck
3333
run: ./gradlew spotlessCheck
34+
- name: rewriteDryRun
35+
run: ./gradlew rewriteDryRun
3436
- name: assemble testClasses
3537
run: ./gradlew assemble testClasses
3638
build:
@@ -66,10 +68,10 @@ jobs:
6668
uses: gradle/actions/setup-gradle@v4
6769
- name: build (maven-only)
6870
if: matrix.kind == 'maven'
69-
run: ./gradlew :plugin-maven:build -x spotlessCheck
71+
run: ./gradlew :plugin-maven:build -x spotlessCheck rewriteDryRun
7072
- name: build (everything-but-maven)
7173
if: matrix.kind == 'gradle'
72-
run: ./gradlew build -x spotlessCheck -PSPOTLESS_EXCLUDE_MAVEN=true
74+
run: ./gradlew build -x spotlessCheck rewriteDryRun -PSPOTLESS_EXCLUDE_MAVEN=true
7375
- name: test npm
7476
if: matrix.kind == 'npm'
7577
run: ./gradlew testNpm

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1616
* Adds support for worktrees (fixes [#1765](https://github.com/diffplug/spotless/issues/1765))
1717
* Bump default `google-java-format` version to latest `1.24.0` -> `1.28.0`. ([#2345](https://github.com/diffplug/spotless/pull/2345))
1818
* Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555))
19+
* [Experimental] Add `rewrite` support for `RemoveUnusedPrivateMethods` & `RemoveUnusedImports` ([#2576](https://github.com/diffplug/spotless/pull/2576))
1920

2021
## [3.3.1] - 2025-07-21
2122
### Fixed

build.gradle

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
apply plugin: 'dev.equo.ide'
2+
3+
apply from: rootProject.file('gradle/changelog.gradle')
4+
apply from: rootProject.file('gradle/java-publish.gradle')
5+
apply from: rootProject.file('gradle/spotless-freshmark.gradle')
6+
7+
allprojects {
8+
apply from: rootProject.file('gradle/spotless.gradle')
9+
apply from: rootProject.file('gradle/rewrite.gradle')
10+
}
11+
212
equoIde {
313
branding().title('Spotless').icon(file('_images/spotless_logo.png'))
414
welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md')
@@ -9,21 +19,6 @@ repositories {
919
mavenCentral()
1020
}
1121

12-
apply from: rootProject.file('gradle/java-publish.gradle')
13-
apply from: rootProject.file('gradle/changelog.gradle')
14-
allprojects {
15-
apply from: rootProject.file('gradle/spotless.gradle')
16-
}
17-
apply from: rootProject.file('gradle/spotless-freshmark.gradle')
18-
19-
spotless {
20-
groovyGradle {
21-
target '*.gradle', 'gradle/*.gradle'
22-
}
23-
format 'dotfiles', {
24-
target '.gitignore', '.gitattributes', '.editorconfig'
25-
leadingTabsToSpaces(2)
26-
trimTrailingWhitespace()
27-
endWithNewline()
28-
}
22+
dependencies {
23+
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.12.0")
2924
}

gradle/rewrite.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apply plugin: 'org.openrewrite.rewrite'
2+
3+
rewrite {
4+
activeRecipe("org.openrewrite.gradle.GradleBestPractices")
5+
activeRecipe("org.openrewrite.java.RemoveUnusedImports")
6+
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedLocalVariables")
7+
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateFields")
8+
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods")
9+
exclusions.add("**package-info.java") // bug
10+
exclusions.add("**gradle/java-publish.gradle") // bug
11+
failOnDryRunResults = true
12+
}
13+
14+
// off switch for release: ' -x check' or ' -x rewriteDryRun spotlessJavaCheck'
15+
//tasks {
16+
// check.dependsOn(rewriteDryRun)
17+
//}
18+
//2 problems were found storing the configuration cache.
19+
//- Task `:rewriteDryRun` of type `org.openrewrite.gradle.RewriteDryRunTask`: cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project', as these are not supported with the configuration cache.
20+
// See https://docs.gradle.org/8.14.3/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
21+
//- Task `:rewriteDryRun` of type `org.openrewrite.gradle.RewriteDryRunTask`: invocation of 'Task.project' at execution time is unsupported.
22+
// See https://docs.gradle.org/8.14.3/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
23+
//

gradle/spotless.gradle

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
apply plugin: 'com.diffplug.spotless'
2+
23
spotless {
4+
groovyGradle {
5+
target '*.gradle', 'gradle/*.gradle'
6+
greclipse().configFile rootProject.files('gradle/spotless.eclipseformat.xml', 'gradle/spotless.groovyformat.prefs')
7+
}
8+
format 'dotfiles', {
9+
target '.gitignore', '.gitattributes', '.editorconfig'
10+
leadingTabsToSpaces(2)
11+
trimTrailingWhitespace()
12+
endWithNewline()
13+
}
314
def noInternalDepsClosure = {
415
String text = it
516
/*
@@ -26,8 +37,4 @@ spotless {
2637
custom 'noInternalDeps', noInternalDepsClosure
2738
}
2839
}
29-
groovyGradle {
30-
target '*.gradle'
31-
greclipse().configFile rootProject.files('gradle/spotless.eclipseformat.xml', 'gradle/spotless.groovyformat.prefs')
32-
}
3340
}

lib-extra/src/test/java/com/diffplug/spotless/extra/eclipse/EclipseResourceHarness.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,8 +15,6 @@
1515
*/
1616
package com.diffplug.spotless.extra.eclipse;
1717

18-
import static org.assertj.core.api.Assertions.*;
19-
2018
import java.io.File;
2119
import java.util.Arrays;
2220

lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,6 @@
2424
import com.diffplug.spotless.extra.eclipse.EquoResourceHarness;
2525

2626
public class GrEclipseFormatterStepTest extends EquoResourceHarness {
27-
private final static String INPUT = "class F{ def m(){} }";
28-
private final static String EXPECTED = "class F{\n\tdef m(){}\n}";
2927

3028
public GrEclipseFormatterStepTest() {
3129
super(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral()));

lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 DiffPlug
2+
* Copyright 2023-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,9 +27,6 @@
2727
import java.util.stream.Collectors;
2828
import java.util.stream.Stream;
2929

30-
import org.slf4j.Logger;
31-
import org.slf4j.LoggerFactory;
32-
3330
import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3;
3431
import com.pinterest.ktlint.rule.engine.api.Code;
3532
import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults;
@@ -55,8 +52,6 @@
5552

5653
public class KtLintCompat0Dot49Dot0Adapter implements KtLintCompatAdapter {
5754

58-
private static final Logger logger = LoggerFactory.getLogger(KtLintCompat0Dot49Dot0Adapter.class);
59-
6055
private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;
6156

6257
static {

lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 DiffPlug
2+
* Copyright 2023-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,9 +25,6 @@
2525
import java.util.stream.Collectors;
2626
import java.util.stream.Stream;
2727

28-
import org.slf4j.Logger;
29-
import org.slf4j.LoggerFactory;
30-
3128
import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3;
3229
import com.pinterest.ktlint.rule.engine.api.Code;
3330
import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults;
@@ -55,8 +52,6 @@
5552

5653
public class KtLintCompat0Dot50Dot0Adapter implements KtLintCompatAdapter {
5754

58-
private static final Logger logger = LoggerFactory.getLogger(KtLintCompat0Dot50Dot0Adapter.class);
59-
6055
private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;
6156

6257
static {

lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 DiffPlug
2+
* Copyright 2023-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,9 +24,6 @@
2424
import java.util.stream.Collectors;
2525
import java.util.stream.Stream;
2626

27-
import org.slf4j.Logger;
28-
import org.slf4j.LoggerFactory;
29-
3027
import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3;
3128
import com.pinterest.ktlint.rule.engine.api.Code;
3229
import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults;
@@ -54,8 +51,6 @@
5451

5552
public class KtLintCompat1Dot0Dot0Adapter implements KtLintCompatAdapter {
5653

57-
private static final Logger logger = LoggerFactory.getLogger(KtLintCompat1Dot0Dot0Adapter.class);
58-
5954
private static final List<EditorConfigProperty<?>> DEFAULT_EDITOR_CONFIG_PROPERTIES;
6055

6156
static {

0 commit comments

Comments
 (0)