Skip to content

Commit

Permalink
Remove unused isScript param in Ktlint format step
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Nov 21, 2023
1 parent a0936e1 commit b383706
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public Unit invoke(LintError lint, Boolean corrected) {
public String format(
String text,
Path path,
boolean isScript,
Path editorConfigPath,
Map<String, Object> editorConfigOverrideMap) {
final FormatterCallback formatterCallback = new FormatterCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public Unit invoke(LintError lint, Boolean corrected) {
public String format(
String text,
Path path,
boolean isScript,
Path editorConfigPath,
Map<String, Object> editorConfigOverrideMap) {
final FormatterCallback formatterCallback = new FormatterCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public Unit invoke(LintError lint, Boolean corrected) {
public String format(
String text,
Path path,
boolean isScript,
Path editorConfigPath,
Map<String, Object> editorConfigOverrideMap) {
final FormatterCallback formatterCallback = new FormatterCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public Unit invoke(LintError lint, Boolean corrected) {
public String format(
String text,
Path path,
boolean isScript,
Path editorConfigPath,
Map<String, Object> editorConfigOverrideMap) {
final FormatterCallback formatterCallback = new FormatterCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public interface KtLintCompatAdapter {
String format(
String text,
Path path,
boolean isScript,
Path editorConfigPath,
Map<String, Object> editorConfigOverrideMap);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@

public class KtlintFormatterFunc implements FormatterFunc.NeedsFile {

private final boolean isScript;
private final KtLintCompatAdapter adapter;
private final FileSignature editorConfigPath;
private final Map<String, Object> editorConfigOverrideMap;

public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath,
public KtlintFormatterFunc(String version, FileSignature editorConfigPath,
Map<String, Object> editorConfigOverrideMap) {
String[] versions = version.split("\\.");
int majorVersion = Integer.parseInt(versions[0]);
Expand All @@ -57,7 +56,6 @@ public KtlintFormatterFunc(String version, boolean isScript, FileSignature edito
}
this.editorConfigPath = editorConfigPath;
this.editorConfigOverrideMap = editorConfigOverrideMap;
this.isScript = isScript;
}

@Override
Expand All @@ -67,6 +65,6 @@ public String applyWithFile(String unix, File file) {
if (editorConfigPath != null) {
absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath();
}
return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, editorConfigOverrideMap);
return adapter.format(unix, file.toPath(), absoluteEditorConfigPath, editorConfigOverrideMap);
}
}
17 changes: 3 additions & 14 deletions lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,17 @@ public static FormatterStep create(Provisioner provisioner) {
}

public static FormatterStep create(String version, Provisioner provisioner) {
return create(version, provisioner, Collections.emptyMap());
}

public static FormatterStep create(String version, Provisioner provisioner,
Map<String, Object> editorConfigOverride) {
return create(version, provisioner, false, null, editorConfigOverride);
return create(version, provisioner, null, Collections.emptyMap());
}

public static FormatterStep create(String version,
Provisioner provisioner,
boolean isScript,
@Nullable FileSignature editorConfig,
Map<String, Object> editorConfigOverride) {
Objects.requireNonNull(version, "version");
Objects.requireNonNull(provisioner, "provisioner");
return FormatterStep.createLazy(NAME,
() -> new State(version, provisioner, isScript, editorConfig, editorConfigOverride),
() -> new State(version, provisioner, editorConfig, editorConfigOverride),
State::createFormat);
}

Expand All @@ -72,9 +66,6 @@ public static String defaultVersion() {

static final class State implements Serializable {
private static final long serialVersionUID = 1L;

/** Are the files being linted Kotlin script files. */
private final boolean isScript;
/** The jar that contains the formatter. */
final JarState jarState;
private final TreeMap<String, Object> editorConfigOverride;
Expand All @@ -84,23 +75,21 @@ static final class State implements Serializable {

State(String version,
Provisioner provisioner,
boolean isScript,
@Nullable FileSignature editorConfigPath,
Map<String, Object> editorConfigOverride) throws IOException {
this.version = version;
this.editorConfigOverride = new TreeMap<>(editorConfigOverride);
this.jarState = JarState.from((version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version,
provisioner);
this.editorConfigPath = editorConfigPath;
this.isScript = isScript;
}

FormatterFunc createFormat() throws Exception {
final ClassLoader classLoader = jarState.getClassLoader();
Class<?> formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc");
Constructor<?> constructor = formatterFunc.getConstructor(
String.class, boolean.class, FileSignature.class, Map.class);
return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, editorConfigOverride);
return (FormatterFunc.NeedsFile) constructor.newInstance(version, editorConfigPath, editorConfigOverride);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException {

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

String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap);
assertEquals("class empty_class_body\n", formatted);
}

Expand All @@ -54,7 +54,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
// ktlint_filename is an invalid rule in ktlint 0.48.0
editorConfigOverrideMap.put("ktlint_filename", "disabled");

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException {

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

String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap);
assertEquals("class EmptyClassBody\n", formatted);
}

Expand All @@ -52,7 +52,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
editorConfigOverrideMap.put("indent_style", "tab");
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException {

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

String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap);
assertEquals("class EmptyClassBody\n", formatted);
}

Expand All @@ -52,7 +52,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
editorConfigOverrideMap.put("indent_style", "tab");
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException {

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

String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap);
assertEquals("class EmptyClassBody\n", formatted);
}

Expand All @@ -52,7 +52,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
editorConfigOverrideMap.put("indent_style", "tab");
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ private FormatterStep createStep() {
return KtLintStep.create(
version,
provisioner(),
isScript(),
editorConfigPath,
editorConfigOverride);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) {
editorConfigOverride = new HashMap<>();
}

return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, configPath, editorConfigOverride);
return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), configPath, editorConfigOverride);
}
}

0 comments on commit b383706

Please sign in to comment.