Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused userData param in Ktlint format step #1891

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ public Unit invoke(LintError lint, Boolean corrected) {
}

@Override
public String format(final String text, Path path, final boolean isScript,
Path editorConfigPath, final Map<String, String> userData,
final Map<String, Object> editorConfigOverrideMap) {
public String format(
String text,
Path path,
boolean isScript,
Path editorConfigPath,
Map<String, Object> editorConfigOverrideMap) {
final FormatterCallback formatterCallback = new FormatterCallback();

Set<RuleProvider> allRuleProviders = ServiceLoader.load(RuleSetProviderV2.class, RuleSetProviderV2.class.getClassLoader())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ public Unit invoke(LintError lint, Boolean corrected) {
}

@Override
public String format(final String text, Path path, final boolean isScript,
Path editorConfigPath, final Map<String, String> userData,
final Map<String, Object> editorConfigOverrideMap) {
public String format(
String text,
Path path,
boolean isScript,
Path editorConfigPath,
Map<String, Object> editorConfigOverrideMap) {
final FormatterCallback formatterCallback = new FormatterCallback();

Set<RuleProvider> allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ public Unit invoke(LintError lint, Boolean corrected) {
}

@Override
public String format(final String text, Path path, final boolean isScript,
Path editorConfigPath, final Map<String, String> userData,
final Map<String, Object> editorConfigOverrideMap) {
public String format(
String text,
Path path,
boolean isScript,
Path editorConfigPath,
Map<String, Object> editorConfigOverrideMap) {
final FormatterCallback formatterCallback = new FormatterCallback();

Set<RuleProvider> allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ public Unit invoke(LintError lint, Boolean corrected) {
}

@Override
public String format(final String text, Path path, final boolean isScript,
Path editorConfigPath, final Map<String, String> userData,
final Map<String, Object> editorConfigOverrideMap) {
public String format(
String text,
Path path,
boolean isScript,
Path editorConfigPath,
Map<String, Object> editorConfigOverrideMap) {
final FormatterCallback formatterCallback = new FormatterCallback();

Set<RuleProvider> allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

public interface KtLintCompatAdapter {

String format(String text, Path path, boolean isScript, Path editorConfigPath, Map<String, String> userData,
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,13 +25,12 @@

public class KtlintFormatterFunc implements FormatterFunc.NeedsFile {

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

Expand All @@ -69,6 +67,6 @@ public String applyWithFile(String unix, File file) {
if (editorConfigPath != null) {
absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath();
}
return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, userData, editorConfigOverrideMap);
return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, editorConfigOverrideMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public static FormatterStep create(String versionDiktat, Provisioner provisioner
return create(versionDiktat, provisioner, false, config);
}

public static FormatterStep createForScript(String versionDiktat, Provisioner provisioner, @Nullable FileSignature config) {
return create(versionDiktat, provisioner, true, config);
}

public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) {
if (BadSemver.version(versionDiktat) < BadSemver.version(MIN_SUPPORTED_VERSION)) {
throw new IllegalStateException("Minimum required Diktat version is " + MIN_SUPPORTED_VERSION + ", you tried " + versionDiktat + " which is too old");
Expand Down
31 changes: 5 additions & 26 deletions lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,23 @@ public static FormatterStep create(Provisioner provisioner) {
}

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

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

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

public static FormatterStep createForScript(String version,
Provisioner provisioner,
@Nullable FileSignature editorConfigPath,
Map<String, String> userData,
Map<String, Object> editorConfigOverride) {
return create(version,
provisioner,
true,
editorConfigPath,
userData,
editorConfigOverride);
return create(version, provisioner, false, null, editorConfigOverride);
}

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

Expand All @@ -95,7 +77,6 @@ static final class State implements Serializable {
private final boolean isScript;
/** The jar that contains the formatter. */
final JarState jarState;
private final TreeMap<String, String> userData;
private final TreeMap<String, Object> editorConfigOverride;
private final String version;
@Nullable
Expand All @@ -105,10 +86,8 @@ static final class State implements Serializable {
Provisioner provisioner,
boolean isScript,
@Nullable FileSignature editorConfigPath,
Map<String, String> userData,
Map<String, Object> editorConfigOverride) throws IOException {
this.version = version;
this.userData = new TreeMap<>(userData);
this.editorConfigOverride = new TreeMap<>(editorConfigOverride);
this.jarState = JarState.from((version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version,
provisioner);
Expand All @@ -120,8 +99,8 @@ 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, Map.class);
return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, userData, editorConfigOverride);
String.class, boolean.class, FileSignature.class, Map.class);
return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, editorConfigOverride);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ public void testDefaults(@TempDir Path path) throws IOException {
String text = loadAndWriteText(path, "empty_class_body.kt");
final Path filePath = Paths.get(path.toString(), "empty_class_body.kt");

Map<String, String> userData = new HashMap<>();

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

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

Expand All @@ -50,15 +48,13 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
String text = loadAndWriteText(path, "fails_no_semicolons.kt");
final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt");

Map<String, String> userData = new HashMap<>();

Map<String, Object> editorConfigOverrideMap = new HashMap<>();
editorConfigOverrideMap.put("indent_style", "tab");
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");
// ktlint_filename is an invalid rule in ktlint 0.48.0
editorConfigOverrideMap.put("ktlint_filename", "disabled");

String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap);
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, 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 @@ -36,11 +36,9 @@ public void testDefaults(@TempDir Path path) throws IOException {
String text = loadAndWriteText(path, "EmptyClassBody.kt");
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");

Map<String, String> userData = new HashMap<>();

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

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

Expand All @@ -50,13 +48,11 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
String text = loadAndWriteText(path, "FailsNoSemicolons.kt");
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");

Map<String, String> userData = new HashMap<>();

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

String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap);
String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, 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 @@ -36,11 +36,9 @@ public void testDefaults(@TempDir Path path) throws IOException {
String text = loadAndWriteText(path, "EmptyClassBody.kt");
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");

Map<String, String> userData = new HashMap<>();

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

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

Expand All @@ -50,13 +48,11 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
String text = loadAndWriteText(path, "FailsNoSemicolons.kt");
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");

Map<String, String> userData = new HashMap<>();

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

String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap);
String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, 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 @@ -36,11 +36,9 @@ public void testDefaults(@TempDir Path path) throws IOException {
String text = loadAndWriteText(path, "EmptyClassBody.kt");
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");

Map<String, String> userData = new HashMap<>();

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

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

Expand All @@ -50,13 +48,11 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
String text = loadAndWriteText(path, "FailsNoSemicolons.kt");
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");

Map<String, String> userData = new HashMap<>();

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

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

Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Fixed
* Fix Eclipse JDT on some settings files. ([#1864](https://github.com/diffplug/spotless/pull/1864) fixes [#1638](https://github.com/diffplug/spotless/issues/1638))
* Check if EditorConfig file exist for Ktlint in KotlinGradleExtension. ([#1889](https://github.com/diffplug/spotless/pull/1889)
### Changes
* Bump default `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855))
### Fixed
Expand Down
3 changes: 1 addition & 2 deletions plugin-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,8 @@ Additionally, `editorConfigOverride` options will override what's supplied in `.
```kotlin
spotless {
kotlin {
// version, userData and editorConfigOverride are all optional
// version, editorConfigPath and editorConfigOverride are all optional
ktlint("1.0.0")
.userData(mapOf("android" to "true"))
.setEditorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement
.editorConfigOverride(
mapOf(
Expand Down
Loading
Loading