Skip to content

Commit bdf8f28

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

File tree

56 files changed

+126
-149
lines changed

Some content is hidden

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

56 files changed

+126
-149
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: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
apply plugin: 'dev.equo.ide'
2-
equoIde {
3-
branding().title('Spotless').icon(file('_images/spotless_logo.png'))
4-
welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md')
5-
gradleBuildship().autoImport('.')
6-
}
72

8-
repositories {
9-
mavenCentral()
10-
}
11-
12-
apply from: rootProject.file('gradle/java-publish.gradle')
133
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+
147
allprojects {
158
apply from: rootProject.file('gradle/spotless.gradle')
9+
apply from: rootProject.file('gradle/rewrite.gradle')
10+
}
11+
12+
equoIde {
13+
branding().title('Spotless').icon(file('_images/spotless_logo.png'))
14+
welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md')
15+
gradleBuildship().autoImport('.')
1616
}
17-
apply from: rootProject.file('gradle/spotless-freshmark.gradle')
1817

1918
spotless {
2019
groovyGradle {
@@ -27,3 +26,11 @@ spotless {
2726
endWithNewline()
2827
}
2928
}
29+
30+
repositories {
31+
mavenCentral()
32+
}
33+
34+
dependencies {
35+
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.12.0")
36+
}

gradle/rewrite.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apply plugin: 'org.openrewrite.rewrite'
2+
3+
rewrite {
4+
//activeRecipe("org.openrewrite.java.RemoveUnusedImports") bug
5+
//activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedLocalVariables") bug
6+
activeRecipe("org.openrewrite.gradle.GradleBestPractices")
7+
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateFields")
8+
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods")
9+
failOnDryRunResults = true
10+
}
11+
12+
//2 problems were found storing the configuration cache.
13+
//- 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.
14+
// See https://docs.gradle.org/8.14.3/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
15+
//- Task `:rewriteDryRun` of type `org.openrewrite.gradle.RewriteDryRunTask`: invocation of 'Task.project' at execution time is unsupported.
16+
// See https://docs.gradle.org/8.14.3/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
17+
//

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 {

lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinUtilsFormatterFunc.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 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.
@@ -15,11 +15,7 @@
1515
*/
1616
package com.diffplug.spotless.glue.gherkin;
1717

18-
import org.slf4j.Logger;
19-
import org.slf4j.LoggerFactory;
20-
2118
import com.diffplug.spotless.FormatterFunc;
22-
import com.diffplug.spotless.gherkin.GherkinUtilsConfig;
2319

2420
import io.cucumber.gherkin.GherkinParser;
2521
import io.cucumber.gherkin.utils.pretty.Pretty;
@@ -30,13 +26,6 @@
3026
import io.cucumber.messages.types.SourceMediaType;
3127

3228
public class GherkinUtilsFormatterFunc implements FormatterFunc {
33-
private static final Logger LOGGER = LoggerFactory.getLogger(GherkinUtilsFormatterFunc.class);
34-
35-
private final GherkinUtilsConfig gherkinSimpleConfig;
36-
37-
public GherkinUtilsFormatterFunc(GherkinUtilsConfig gherkinSimpleConfig) {
38-
this.gherkinSimpleConfig = gherkinSimpleConfig;
39-
}
4029

4130
// Follows https://github.com/cucumber/gherkin-utils/blob/main/java/src/test/java/io/cucumber/gherkin/utils/pretty/PrettyTest.java
4231
private GherkinDocument parse(String gherkin) {

0 commit comments

Comments
 (0)