Skip to content
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
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
* Fix configuration cache failure when using LineEnding.GIT_ATTRIBUTES ([#1644](https://github.com/diffplug/spotless/issues/1644))
* Fix configuration cache failure when formatting proto files with Buf. ([#1779]https://github.com/diffplug/spotless/pull/1779))
* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788)
### Changes
* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ public class KotlinFormatExtension {
addStep(createStep());
}

public KotlinFormatExtension setEditorConfigPath(Object editorConfigFile) throws IOException {
if (editorConfigFile == null) {
public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException {
if (editorConfigPath == null) {
this.editorConfigPath = null;
} else {
this.editorConfigPath = FileSignature.signAsList(getProject().file(editorConfigFile));
File editorConfigFile = getProject().file(editorConfigPath);
if (!editorConfigFile.exists()) {
throw new IllegalArgumentException("EditorConfig file does not exist: " + editorConfigFile);
}
this.editorConfigPath = FileSignature.signAsList(editorConfigFile);
}
replaceStep(createStep());
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.diffplug.gradle.spotless;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -81,6 +84,27 @@ void withExperimentalEditorConfigOverride() throws IOException {
assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean");
}

@Test
void testWithInvalidEditorConfigFile() throws IOException {
String invalidPath = "invalid/path/to/.editorconfig".replace('/', File.separatorChar);

setFile("build.gradle").toLines(
"plugins {",
" id 'org.jetbrains.kotlin.jvm' version '1.5.31'",
" id 'com.diffplug.spotless'",
"}",
"repositories { mavenCentral() }",
"spotless {",
" kotlin {",
" ktlint().setEditorConfigPath('" + invalidPath.replace("\\", "\\\\") + "')",
" }",
"}");
setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
String buildOutput = gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput();
assertThat(buildOutput).contains("EditorConfig file does not exist: ");
assertThat(buildOutput).contains(invalidPath);
}

@Test
void testWithHeader() throws IOException {
setFile("build.gradle").toLines(
Expand Down