Skip to content

Commit d5ddbcf

Browse files
authored
Remove more unused params in Ktlint format step (#1897)
2 parents f3bf1e7 + 8469300 commit d5ddbcf

File tree

13 files changed

+32
-53
lines changed

13 files changed

+32
-53
lines changed

lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java

-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public Unit invoke(LintError lint, Boolean corrected) {
7474

7575
@Override
7676
public String format(
77-
String text,
7877
Path path,
79-
boolean isScript,
8078
Path editorConfigPath,
8179
Map<String, Object> editorConfigOverrideMap) {
8280
final FormatterCallback formatterCallback = new FormatterCallback();

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

-2
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ public Unit invoke(LintError lint, Boolean corrected) {
120120

121121
@Override
122122
public String format(
123-
String text,
124123
Path path,
125-
boolean isScript,
126124
Path editorConfigPath,
127125
Map<String, Object> editorConfigOverrideMap) {
128126
final FormatterCallback formatterCallback = new FormatterCallback();

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

-2
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ public Unit invoke(LintError lint, Boolean corrected) {
8383

8484
@Override
8585
public String format(
86-
String text,
8786
Path path,
88-
boolean isScript,
8987
Path editorConfigPath,
9088
Map<String, Object> editorConfigOverrideMap) {
9189
final FormatterCallback formatterCallback = new FormatterCallback();

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

-2
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ public Unit invoke(LintError lint, Boolean corrected) {
8383

8484
@Override
8585
public String format(
86-
String text,
8786
Path path,
88-
boolean isScript,
8987
Path editorConfigPath,
9088
Map<String, Object> editorConfigOverrideMap) {
9189
final FormatterCallback formatterCallback = new FormatterCallback();

lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java

-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
public interface KtLintCompatAdapter {
2222

2323
String format(
24-
String text,
2524
Path path,
26-
boolean isScript,
2725
Path editorConfigPath,
2826
Map<String, Object> editorConfigOverrideMap);
2927
}

lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
import com.diffplug.spotless.glue.ktlint.compat.*;
2525

2626
public class KtlintFormatterFunc implements FormatterFunc.NeedsFile {
27-
28-
private final boolean isScript;
2927
private final KtLintCompatAdapter adapter;
3028
private final FileSignature editorConfigPath;
3129
private final Map<String, Object> editorConfigOverrideMap;
3230

33-
public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath,
31+
public KtlintFormatterFunc(
32+
String version,
33+
FileSignature editorConfigPath,
3434
Map<String, Object> editorConfigOverrideMap) {
3535
String[] versions = version.split("\\.");
3636
int majorVersion = Integer.parseInt(versions[0]);
@@ -57,16 +57,17 @@ public KtlintFormatterFunc(String version, boolean isScript, FileSignature edito
5757
}
5858
this.editorConfigPath = editorConfigPath;
5959
this.editorConfigOverrideMap = editorConfigOverrideMap;
60-
this.isScript = isScript;
6160
}
6261

6362
@Override
6463
public String applyWithFile(String unix, File file) {
65-
6664
Path absoluteEditorConfigPath = null;
6765
if (editorConfigPath != null) {
6866
absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath();
6967
}
70-
return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, editorConfigOverrideMap);
68+
return adapter.format(
69+
file.toPath(),
70+
absoluteEditorConfigPath,
71+
editorConfigOverrideMap);
7172
}
7273
}

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

+8-19
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,26 @@ public class KtLintStep {
3737
private KtLintStep() {}
3838

3939
private static final String DEFAULT_VERSION = "1.0.1";
40-
static final String NAME = "ktlint";
41-
static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:";
42-
static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:";
40+
private static final String NAME = "ktlint";
41+
private static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:";
42+
private static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:";
4343

4444
public static FormatterStep create(Provisioner provisioner) {
4545
return create(defaultVersion(), provisioner);
4646
}
4747

4848
public static FormatterStep create(String version, Provisioner provisioner) {
49-
return create(version, provisioner, Collections.emptyMap());
50-
}
51-
52-
public static FormatterStep create(String version, Provisioner provisioner,
53-
Map<String, Object> editorConfigOverride) {
54-
return create(version, provisioner, false, null, editorConfigOverride);
49+
return create(version, provisioner, null, Collections.emptyMap());
5550
}
5651

5752
public static FormatterStep create(String version,
5853
Provisioner provisioner,
59-
boolean isScript,
6054
@Nullable FileSignature editorConfig,
6155
Map<String, Object> editorConfigOverride) {
6256
Objects.requireNonNull(version, "version");
6357
Objects.requireNonNull(provisioner, "provisioner");
6458
return FormatterStep.createLazy(NAME,
65-
() -> new State(version, provisioner, isScript, editorConfig, editorConfigOverride),
59+
() -> new State(version, provisioner, editorConfig, editorConfigOverride),
6660
State::createFormat);
6761
}
6862

@@ -72,35 +66,30 @@ public static String defaultVersion() {
7266

7367
static final class State implements Serializable {
7468
private static final long serialVersionUID = 1L;
75-
76-
/** Are the files being linted Kotlin script files. */
77-
private final boolean isScript;
7869
/** The jar that contains the formatter. */
79-
final JarState jarState;
70+
private final JarState jarState;
8071
private final TreeMap<String, Object> editorConfigOverride;
8172
private final String version;
8273
@Nullable
8374
private final FileSignature editorConfigPath;
8475

8576
State(String version,
8677
Provisioner provisioner,
87-
boolean isScript,
8878
@Nullable FileSignature editorConfigPath,
8979
Map<String, Object> editorConfigOverride) throws IOException {
9080
this.version = version;
9181
this.editorConfigOverride = new TreeMap<>(editorConfigOverride);
9282
this.jarState = JarState.from((version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version,
9383
provisioner);
9484
this.editorConfigPath = editorConfigPath;
95-
this.isScript = isScript;
9685
}
9786

9887
FormatterFunc createFormat() throws Exception {
9988
final ClassLoader classLoader = jarState.getClassLoader();
10089
Class<?> formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc");
10190
Constructor<?> constructor = formatterFunc.getConstructor(
102-
String.class, boolean.class, FileSignature.class, Map.class);
103-
return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, editorConfigOverride);
91+
String.class, FileSignature.class, Map.class);
92+
return (FormatterFunc.NeedsFile) constructor.newInstance(version, editorConfigPath, editorConfigOverride);
10493
}
10594
}
10695
}

lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ public class KtLintCompat0Dot48Dot0AdapterTest {
3333
@Test
3434
public void testDefaults(@TempDir Path path) throws IOException {
3535
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
36-
String text = loadAndWriteText(path, "empty_class_body.kt");
36+
loadAndWriteText(path, "empty_class_body.kt");
3737
final Path filePath = Paths.get(path.toString(), "empty_class_body.kt");
3838

3939
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
4040

41-
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
41+
String formatted = ktLintCompat0Dot48Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
4242
assertEquals("class empty_class_body\n", formatted);
4343
}
4444

4545
@Test
4646
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
4747
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
48-
String text = loadAndWriteText(path, "fails_no_semicolons.kt");
48+
loadAndWriteText(path, "fails_no_semicolons.kt");
4949
final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt");
5050

5151
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
@@ -54,7 +54,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
5454
// ktlint_filename is an invalid rule in ktlint 0.48.0
5555
editorConfigOverrideMap.put("ktlint_filename", "disabled");
5656

57-
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
57+
String formatted = ktLintCompat0Dot48Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
5858
assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted);
5959
}
6060

lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ public class KtLintCompat0Dot49Dot0AdapterTest {
3333
@Test
3434
public void testDefaults(@TempDir Path path) throws IOException {
3535
KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter();
36-
String text = loadAndWriteText(path, "EmptyClassBody.kt");
36+
loadAndWriteText(path, "EmptyClassBody.kt");
3737
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");
3838

3939
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
4040

41-
String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
41+
String formatted = ktLintCompat0Dot49Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
4242
assertEquals("class EmptyClassBody\n", formatted);
4343
}
4444

4545
@Test
4646
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
4747
KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter();
48-
String text = loadAndWriteText(path, "FailsNoSemicolons.kt");
48+
loadAndWriteText(path, "FailsNoSemicolons.kt");
4949
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");
5050

5151
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
5252
editorConfigOverrideMap.put("indent_style", "tab");
5353
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");
5454

55-
String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
55+
String formatted = ktLintCompat0Dot49Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
5656
assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted);
5757
}
5858

lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ public class KtLintCompat0Dot50Dot0AdapterTest {
3333
@Test
3434
public void testDefaults(@TempDir Path path) throws IOException {
3535
KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter();
36-
String text = loadAndWriteText(path, "EmptyClassBody.kt");
36+
loadAndWriteText(path, "EmptyClassBody.kt");
3737
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");
3838

3939
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
4040

41-
String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
41+
String formatted = KtLintCompat0Dot50Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
4242
assertEquals("class EmptyClassBody\n", formatted);
4343
}
4444

4545
@Test
4646
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
4747
KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter();
48-
String text = loadAndWriteText(path, "FailsNoSemicolons.kt");
48+
loadAndWriteText(path, "FailsNoSemicolons.kt");
4949
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");
5050

5151
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
5252
editorConfigOverrideMap.put("indent_style", "tab");
5353
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");
5454

55-
String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
55+
String formatted = KtLintCompat0Dot50Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
5656
assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted);
5757
}
5858

lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ public class KtLintCompat1Dot0Dot0AdapterTest {
3333
@Test
3434
public void testDefaults(@TempDir Path path) throws IOException {
3535
KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter();
36-
String text = loadAndWriteText(path, "EmptyClassBody.kt");
36+
loadAndWriteText(path, "EmptyClassBody.kt");
3737
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");
3838

3939
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
4040

41-
String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
41+
String formatted = KtLintCompat1Dot0Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
4242
assertEquals("class EmptyClassBody\n", formatted);
4343
}
4444

4545
@Test
4646
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
4747
KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter();
48-
String text = loadAndWriteText(path, "FailsNoSemicolons.kt");
48+
loadAndWriteText(path, "FailsNoSemicolons.kt");
4949
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");
5050

5151
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
5252
editorConfigOverrideMap.put("indent_style", "tab");
5353
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");
5454

55-
String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
55+
String formatted = KtLintCompat1Dot0Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
5656
assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted);
5757
}
5858

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java

-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ private FormatterStep createStep() {
186186
return KtLintStep.create(
187187
version,
188188
provisioner(),
189-
isScript(),
190189
editorConfigPath,
191190
editorConfigOverride);
192191
}

plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) {
4747
editorConfigOverride = new HashMap<>();
4848
}
4949

50-
return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, configPath, editorConfigOverride);
50+
return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), configPath, editorConfigOverride);
5151
}
5252
}

0 commit comments

Comments
 (0)