Skip to content

Commit

Permalink
Add support for ktlint FilenameRule (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Oct 26, 2021
2 parents 2e61129 + e0b2131 commit 4016c91
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Changed
* Added support and bump Eclipse formatter default versions to `4.21` for `eclipse-groovy`. Change is only applied for JVM 11+.
* Added support for ktlint's FilenameRule ([#974](https://github.com/diffplug/spotless/pull/974)).

### Fixed
* Temporary workspace deletion for Eclipse based formatters on JVM shutdown ([#967](https://github.com/diffplug/spotless/issues/967)). Change is only applied for Eclipse versions using JVM 11+, no back-port to older versions is planned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ FormatterFunc createFormat() throws Exception {
/* editorConfigPath, nullable */ String.class,
/* debug */ boolean.class);
Method formatterMethod = ktlintClass.getMethod("format", paramsClass);
formatterFunc = input -> {
FormatterFunc.NeedsFile needsFile = (input, file) -> {
try {
Object params = constructor.newInstance(
/* fileName, nullable */ null,
/* fileName, nullable */ file.getName(),
/* text */ input,
/* ruleSets */ ruleSets,
/* userData */ userData,
Expand All @@ -170,6 +170,7 @@ FormatterFunc createFormat() throws Exception {
throw ThrowingEx.unwrapCause(e);
}
};
formatterFunc = FormatterFunc.needsFile(needsFile);
} else {
// and its format method
String formatterMethodName = isScript ? "formatScript" : "format";
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]
### Changed
* Added support and bump Eclipse formatter default versions to `4.21` for `eclipse-groovy`. Change is only applied for JVM 11+.
* Added support for ktlint's FilenameRule ([#974](https://github.com/diffplug/spotless/pull/974)).

### Fixed
* Temporary workspace deletion for Eclipse based formatters on JVM shutdown ([#967](https://github.com/diffplug/spotless/issues/967)). Change is only applied for Eclipse versions using JVM 11+, no back-port to older versions is planned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ void testWithHeader() throws IOException {
" ktlint()",
" }",
"}");
setFile("src/main/kotlin/test.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test");
setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/kotlin/test.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"));
assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"));
}

@Test
Expand All @@ -173,9 +173,9 @@ void testWithHeaderKtfmt() throws IOException {
" ktfmt()",
" }",
"}");
setFile("src/main/kotlin/test.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test");
setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/kotlin/test.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeaderKtfmt.test"));
assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeaderKtfmt.test"));
}

@Test
Expand All @@ -192,9 +192,9 @@ void testWithCustomHeaderSeparator() throws IOException {
" ktlint()",
" }",
"}");
setFile("src/main/kotlin/test.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test");
setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/kotlin/test.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"));
assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"));
}

@Test
Expand All @@ -212,9 +212,9 @@ void testWithCustomHeaderSeparatorKtfmt() throws IOException {
" ktfmt()",
" }",
"}");
setFile("src/main/kotlin/test.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test");
setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/kotlin/test.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeaderKtfmt.test"));
assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeaderKtfmt.test"));
}

@Test
Expand All @@ -232,13 +232,13 @@ void testWithNonStandardYearSeparator() throws IOException {
" }",
"}");

setFile("src/main/kotlin/test.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test");
setFile("src/main/kotlin/test2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test");
setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test");
setFile("src/main/kotlin/AnObject2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/kotlin/test.kt").matches(matcher -> {
assertFile("src/main/kotlin/AnObject.kt").matches(matcher -> {
matcher.startsWith("// License Header 2012, 2014");
});
assertFile("src/main/kotlin/test2.kt").matches(matcher -> {
assertFile("src/main/kotlin/AnObject2.kt").matches(matcher -> {
matcher.startsWith("// License Header 2012, 2014");
});
}
Expand All @@ -259,13 +259,13 @@ void testWithNonStandardYearSeparatorKtfmt() throws IOException {
" }",
"}");

setFile("src/main/kotlin/test.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test");
setFile("src/main/kotlin/test2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test");
setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test");
setFile("src/main/kotlin/AnObject2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/kotlin/test.kt").matches(matcher -> {
assertFile("src/main/kotlin/AnObject.kt").matches(matcher -> {
matcher.startsWith("// License Header 2012, 2014");
});
assertFile("src/main/kotlin/test2.kt").matches(matcher -> {
assertFile("src/main/kotlin/AnObject2.kt").matches(matcher -> {
matcher.startsWith("// License Header 2012, 2014");
});
}
Expand Down
2 changes: 2 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Changed
* Added support and bump Eclipse formatter default versions to `4.21` for `eclipse-groovy`. Change is only applied for JVM 11+.
* Added support for ktlint's FilenameRule ([#974](https://github.com/diffplug/spotless/pull/974)).

### Fixed
* Revert change from 2.17.2 regarding [skip bug](https://github.com/diffplug/spotless/pull/969) because fixing the skip bug caused inconsistent behavior between `check.skip` and `apply.skip`.
* [skip bug](https://github.com/diffplug/spotless/issues/968) if ratchetFrom is specified, the build will still fail in if no Git repository is found, even if `skip` is true (new fix).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
@file:JvmName("SomeFileName")
package my.test

object AnObject
object AnObject2

0 comments on commit 4016c91

Please sign in to comment.