Skip to content

Commit 0cfc8f7

Browse files
author
Vincent Potucek
committed
[Experimental] Add rewrite support for RemoveUnusedPrivateMethods & RemoveUnusedImports
1 parent b7c829e commit 0cfc8f7

File tree

53 files changed

+120
-142
lines changed

Some content is hidden

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

53 files changed

+120
-142
lines changed

build.gradle

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
apply plugin: 'dev.equo.ide'
2+
apply plugin: 'org.openrewrite.rewrite'
3+
4+
apply from: rootProject.file('gradle/changelog.gradle')
5+
apply from: rootProject.file('gradle/java-publish.gradle')
6+
apply from: rootProject.file('gradle/spotless-freshmark.gradle')
7+
8+
allprojects {
9+
apply from: rootProject.file('gradle/spotless.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')
515
gradleBuildship().autoImport('.')
616
}
717

8-
repositories {
9-
mavenCentral()
10-
}
11-
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')
18+
rewrite {
19+
activeRecipe("org.openrewrite.gradle.GradleBestPractices")
20+
activeRecipe("org.openrewrite.java.RemoveUnusedImports")
21+
//activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedLocalVariables") bug
22+
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateFields")
23+
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods")
24+
failOnDryRunResults = true
1625
}
17-
apply from: rootProject.file('gradle/spotless-freshmark.gradle')
1826

1927
spotless {
2028
groovyGradle {
@@ -27,3 +35,16 @@ spotless {
2735
endWithNewline()
2836
}
2937
}
38+
39+
// off switch for release: ' -x check' or ' -x rewriteDryRun spotlessJavaCheck'
40+
tasks {
41+
check.dependsOn(rewriteDryRun, spotlessCheck)
42+
}
43+
44+
repositories {
45+
mavenCentral()
46+
}
47+
48+
dependencies {
49+
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.12.0")
50+
}

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 & 5 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,9 +15,6 @@
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;
2219
import com.diffplug.spotless.gherkin.GherkinUtilsConfig;
2320

@@ -30,7 +27,6 @@
3027
import io.cucumber.messages.types.SourceMediaType;
3128

3229
public class GherkinUtilsFormatterFunc implements FormatterFunc {
33-
private static final Logger LOGGER = LoggerFactory.getLogger(GherkinUtilsFormatterFunc.class);
3430

3531
private final GherkinUtilsConfig gherkinSimpleConfig;
3632

lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 DiffPlug
2+
* Copyright 2022-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.
@@ -432,7 +432,6 @@ private static final class State implements Serializable {
432432

433433
// group 1 is the basename of the annotation.
434434
private static final String annoNoArgRegex = "@(?:[A-Za-z_][A-Za-z0-9_.]*\\.)?([A-Za-z_][A-Za-z0-9_]*)";
435-
private static final Pattern annoNoArgPattern = Pattern.compile(annoNoArgRegex);
436435
// 3 non-empty cases: () (".*") (.*)
437436
private static final String annoArgRegex = "(?:\\(\\)|\\(\"[^\"]*\"\\)|\\([^\")][^)]*\\))?";
438437
// group 1 is the basename of the annotation.

lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2024 DiffPlug
2+
* Copyright 2021-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.
@@ -18,7 +18,7 @@
1818
import java.io.File;
1919
import java.io.Serializable;
2020
import java.lang.reflect.Constructor;
21-
import java.util.*;
21+
import java.util.Objects;
2222

2323
import javax.annotation.Nullable;
2424

lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ abstract class NpmFormatterStepStateBase implements Serializable {
4141

4242
private static final Logger logger = LoggerFactory.getLogger(NpmFormatterStepStateBase.class);
4343

44-
private static final TimedLogger timedLogger = TimedLogger.forLogger(logger);
45-
4644
private static final long serialVersionUID = 1460749955865959948L;
4745

4846
private final String stepName;

0 commit comments

Comments
 (0)