diff --git a/.editorconfig b/.editorconfig index 5d0704bd2b..9fe2fbc6c6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,7 @@ charset = utf-8 [*.md] indent_style = space indent_size = 2 +trim_trailing_whitespace = false [*.java] # Doc: https://youtrack.jetbrains.com/issue/IDEA-170643#focus=streamItem-27-3708697.0-0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6a2e612aa..5e436abd95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,7 +79,7 @@ jobs: if: matrix.kind == 'npm' run: ./gradlew testNpm - name: junit result - uses: mikepenz/action-junit-report@v3 + uses: mikepenz/action-junit-report@v4 if: always() # always run even if the previous step fails with: check_name: JUnit ${{ matrix.kind }} ${{ matrix.jre }} ${{ matrix.os }} diff --git a/CHANGES.md b/CHANGES.md index dd89d2c5bd..f2bc6974c6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,13 +11,22 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +## [2.43.0] - 2023-11-27 +### Added +* Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896) +### 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)) +### Changes +* Bump default `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855)) +* Add a Step to remove semicolons from Groovy files. ([#1881](https://github.com/diffplug/spotless/pull/1881)) + ## [2.42.0] - 2023-09-28 ### Added * Support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). The configuration is still the same, but you should switch to the new `biome` tag / function and adjust the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). * Support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793)) -* Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)). +* Support configuration of mirrors for P2 repositories in Maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)). * New line endings mode `GIT_ATTRIBUTES_FAST_ALLSAME`. ([#1838](https://github.com/diffplug/spotless/pull/1838)) ### Fixed * Fix support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) @@ -131,7 +140,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.33.0] - 2023-01-26 ### Added -* `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) +* `ProcessRunner` has added some convenience methods so it can be used for Maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) * `ProcessRunner` allows to limit captured output to a certain number of bytes. ([#1511](https://github.com/diffplug/spotless/pull/1511)) * `ProcessRunner` is now capable of handling long-running tasks where waiting for exit is delegated to the caller. ([#1511](https://github.com/diffplug/spotless/pull/1511)) * Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) @@ -204,7 +213,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.29.0] - 2022-08-23 ### Added -* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) +* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the Maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) * Converted `scalafmt` integration to use a compile-only source set (fixes [#524](https://github.com/diffplug/spotless/issues/524)) ### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) @@ -429,7 +438,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changed * Update ktfmt from 0.21 to 0.24 ### Fixed -* The `` field in the maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) +* The `` field in the Maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) * Node is re-installed if some other build step removed it ([#863](https://github.com/diffplug/spotless/issues/863)) ## [2.13.4] - 2021-04-21 @@ -503,7 +512,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.8.0] - 2020-10-05 ### Added -* Exposed new methods in `GitRatchet` to support faster ratcheting in the maven plugin ([#706](https://github.com/diffplug/spotless/pull/706)). +* Exposed new methods in `GitRatchet` to support faster ratcheting in the Maven plugin ([#706](https://github.com/diffplug/spotless/pull/706)). ## [2.7.0] - 2020-09-21 ### Added @@ -574,10 +583,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `FormatterFunc.NeedsFile` for implementing file-based formatters more cleanly than we have so far ([#637](https://github.com/diffplug/spotless/issues/637)). ### Changed * **BREAKING** `FileSignature` can no longer sign folders, only files. Signatures are now based only on filename (not path), size, and a content hash. It throws an error if a signature is attempted on a folder or on multiple files with different paths but the same filename - it never breaks silently. This change does not break any of Spotless' internal logic, so it is unlikely to affect any of Spotless' consumers either. ([#571](https://github.com/diffplug/spotless/pull/571)) - * This change allows the maven plugin to cache classloaders across subprojects when loading config resources from the classpath (fixes [#559](https://github.com/diffplug/spotless/issues/559)). - * This change also allows the gradle plugin to work with the remote buildcache (fixes [#280](https://github.com/diffplug/spotless/issues/280)). + * This change allows the Maven plugin to cache classloaders across subprojects when loading config resources from the classpath (fixes [#559](https://github.com/diffplug/spotless/issues/559)). + * This change also allows the Gradle plugin to work with the remote buildcache (fixes [#280](https://github.com/diffplug/spotless/issues/280)). * **BREAKING** `FormatterFunc` no longer `extends ThrowingEx.Function` and `BiFunction`. In a major win for Java's idea of ["target typing"](https://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-final.html), this required no changes anywhere in the codebase except deleting the `extends` part of `FormatterFunc` ([#638](https://github.com/diffplug/spotless/issues/638)). -* **BREAKING** Heavy refactor of the `LicenseHeaderStep` public API. Doesn't change internal behavior, but makes implementation of the gradle and maven plugins much easier. ([#628](https://github.com/diffplug/spotless/pull/628)) +* **BREAKING** Heavy refactor of the `LicenseHeaderStep` public API. Doesn't change internal behavior, but makes implementation of the Gradle and Maven plugins much easier. ([#628](https://github.com/diffplug/spotless/pull/628)) * **BREAKING** Removed all deprecated methods and classes from `lib` and `lib-extra`. * [#629](https://github.com/diffplug/spotless/pull/629) removes the code which wasn't being used in plugin-gradle or plugin-maven. * [#630](https://github.com/diffplug/spotless/pull/630) moves the code which was still being used in deprecated parts of plugin-gradle into `.deprecated` package in `plugin-gradle`, which allows us to break `lib` without a breaking change in `plugin-gradle`. @@ -610,7 +619,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `NodeJsGlobal.setSharedLibFolder` allows to set the location of nodejs shared libs. ([#586](https://github.com/diffplug/spotless/pull/586)) * `PaddedCell.isClean()` returns the instance of `PaddedCell.DirtyState` which represents clean. ([#590](https://github.com/diffplug/spotless/pull/590)) ### Fixed -* Previously, the nodejs-based steps would throw `UnsatisfiedLinkError` if they were ever used from more than one classloader. Now they can be used from any number of classloaders (important for gradle build daemon). ([#586](https://github.com/diffplug/spotless/pull/586)) +* Previously, the nodejs-based steps would throw `UnsatisfiedLinkError` if they were ever used from more than one classloader. Now they can be used from any number of classloaders (important for Gradle build daemon). ([#586](https://github.com/diffplug/spotless/pull/586)) ## [1.31.0] - 2020-05-21 ### Added @@ -632,8 +641,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changed * Updated a bunch of dependencies, most notably: ([#564](https://github.com/diffplug/spotless/pull/564)) * jgit `5.5.0.201909110433-r` -> `5.7.0.202003110725-r` - * gradle `6.2.2` -> `6.3` - * spotbugs gradle plugin `2.0.0` -> `4.0.8` + * Gradle `6.2.2` -> `6.3` + * spotbugs Gradle plugin `2.0.0` -> `4.0.8` ## [1.28.1] - 2020-04-02 ### Fixed @@ -650,12 +659,12 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * We now use [javadoc.io](https://javadoc.io/) instead of github pages. ([#508](https://github.com/diffplug/spotless/pull/508)) * We no longer publish `-SNAPSHOT` for every build to `main`, since we have good [JitPack integration](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#gradle---any-commit-in-a-public-github-repo-this-one-or-any-fork). ([#508](https://github.com/diffplug/spotless/pull/508)) * Improved how we use Spotless on itself. ([#509](https://github.com/diffplug/spotless/pull/509)) -* Fix build warnings when building on Gradle 6+, bump build gradle to 6.2.2, and fix javadoc links. ([#536](https://github.com/diffplug/spotless/pull/536)) +* Fix build warnings when building on Gradle 6+, bump build Gradle to 6.2.2, and fix javadoc links. ([#536](https://github.com/diffplug/spotless/pull/536)) ## [1.27.0] - 2020-01-01 * Ignored `KtLintStepTest`, because [gradle/gradle#11752](https://github.com/gradle/gradle/issues/11752) is causing too many CI failures. ([#499](https://github.com/diffplug/spotless/pull/499)) * Also fixed a minor problem in TestProvisioner. -* If you set the environment variable `SPOTLESS_EXCLUDE_MAVEN=true` then the maven plugin will be excluded from the build. ([#502](https://github.com/diffplug/spotless/pull/502)) +* If you set the environment variable `SPOTLESS_EXCLUDE_MAVEN=true` then the Maven plugin will be excluded from the build. ([#502](https://github.com/diffplug/spotless/pull/502)) * We have set this in JitPack, as a workaround for [jitpack/jitpack.io#4112](https://github.com/jitpack/jitpack.io/issues/4112) * Deprecated `SpotlessCache.clear()` in favor of the new `SpotlessCache.clearOnce(Object key)`. ([#501](https://github.com/diffplug/spotless/issues/#501)) @@ -690,7 +699,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - but incorrectly marked as good by "check" - this led to "check" says all good, but then "apply" still causes format (https://github.com/diffplug/spotless/issues/453) - combined with up-to-date checking, could lead to even more confusing results (https://github.com/diffplug/spotless/issues/338) - - only affects the gradle plugin, since that was the only plugin to use this feature + - only affects the Gradle plugin, since that was the only plugin to use this feature * Minor change to `TestProvisioner`, which should fix the cache-breaking issues, allowing us to speed-up the CI builds a bit. * Bumped `scalafmt` default version from `1.1.0` to `2.0.1`, since there are [bugs](https://github.com/diffplug/spotless/issues/454) in the old default ([#458](https://github.com/diffplug/spotless/pull/458)). @@ -703,11 +712,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Updated default eclipse-jdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * Updated default eclipse-cdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * **KNOWN BUG - accidentally published CDT 9.7 rather than 9.8 - fixed in 1.26.0** -* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) +* Added new Maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) ## [1.23.1] - 2019-06-17 * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) -* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) +* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because Gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) ## [1.23.0] - 2019-04-24 * Updated default ktlint from 0.21.0 to 0.32.0, and Maven coords to com.pinterest ([#394](https://github.com/diffplug/spotless/pull/394)) @@ -783,7 +792,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [1.12.0] - 2018-05-14 * Fixed a bug in `LicenseHeaderStep` which caused an exception with some malformed date-aware licenses. ([#222](https://github.com/diffplug/spotless/pull/222)) * Updated default ktlint from 0.14.0 to 0.21.0 -* Add ability to pass custom options to ktlint in gradle plugin. See plugin-gradle/README for details. +* Add ability to pass custom options to ktlint in Gradle plugin. See plugin-gradle/README for details. ## [1.11.0] - 2018-02-26 * Added default indentation of `4` to `IndentStep`. ([#209](https://github.com/diffplug/spotless/pull/209)) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 852a694470..287d835bca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,7 +27,7 @@ Spotless also provides `PaddedCell`, which makes it easy to diagnose and correct ## Project layout -For the folders below in monospace text, they are published on maven central at the coordinate `com.diffplug.spotless:spotless-${FOLDER_NAME}`. The other folders are dev infrastructure. +For the folders below in monospace text, they are published on MavenCentral at the coordinate `com.diffplug.spotless:spotless-${FOLDER_NAME}`. The other folders are dev infrastructure. | Folder | Description | | ------ | ----------- | diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 0ae5167a13..76d0ce19ab 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,7 +1,7 @@ If you are submitting a **bug**, please include the following: - [ ] summary of problem -- [ ] gradle or maven version +- [ ] Gradle or Maven version - [ ] spotless version - [ ] operating system and version - [ ] copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible diff --git a/README.md b/README.md index 80dcec21eb..d31fd15b8c 100644 --- a/README.md +++ b/README.md @@ -169,14 +169,14 @@ Once someone has filled in one square of the formatter/build system matrix, it's ## Acknowledgements -- Thanks to [Konstantin Lutovich](https://github.com/lutovich) for [implementing and maintaining the maven plugin](https://github.com/diffplug/spotless/pull/188), as well as fixing [remote-build cache support for Gradle](https://github.com/diffplug/spotless/pull/571). +- Thanks to [Konstantin Lutovich](https://github.com/lutovich) for [implementing and maintaining the Maven plugin](https://github.com/diffplug/spotless/pull/188), as well as fixing [remote-build cache support for Gradle](https://github.com/diffplug/spotless/pull/571). - Thanks to [Frank Vennemeyer](https://github.com/fvgh) for [Groovy support via greclipse](https://github.com/diffplug/spotless/issues/13), [C++ support via CDT](https://github.com/diffplug/spotless/issues/232), [XML support via WTP](https://github.com/diffplug/spotless/pull/241) and a huge body of work with other eclipse-based formatters. - Thanks to [Jonathan Bluett-Duncan](https://github.com/jbduncan) for - implementing up-to-date checking [#31](https://github.com/diffplug/spotless/issues/31) - breaking spotless into libraries [#56](https://github.com/diffplug/spotless/issues/56) - lots of other things, but especially the diff support in `spotlessCheck` - constant improvements on a variety of topics with high-quality code reviews -- Thanks to [Daz DeBoer](https://github.com/bigdaz) for the reworking the guts of our gradle plugin to support [buildcache](https://github.com/diffplug/spotless/pull/576), [InputChanges](https://github.com/diffplug/spotless/pull/607), and [lazy configuration](https://github.com/diffplug/spotless/pull/617). +- Thanks to [Daz DeBoer](https://github.com/bigdaz) for the reworking the guts of our Gradle plugin to support [buildcache](https://github.com/diffplug/spotless/pull/576), [InputChanges](https://github.com/diffplug/spotless/pull/607), and [lazy configuration](https://github.com/diffplug/spotless/pull/617). - Thanks to [Richard Willis](https://github.com/badsyntax) for creating the [VS Code extension for Spotless Gradle](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle). - Thanks to [Ryan Gurney](https://github.com/ragurney) for creating the [IntelliJ plugin for Spotless Gradle](https://plugins.jetbrains.com/plugin/18321-spotless-gradle). - Thanks to [Markus Heberling](https://github.com/tisoft) for adding [generic native formatters](https://github.com/diffplug/spotless/pull/949), [jsr-223 formatters](https://github.com/diffplug/spotless/pull/945), and [maven pom sorting](https://github.com/diffplug/spotless/pull/946). @@ -195,7 +195,7 @@ Once someone has filled in one square of the formatter/build system matrix, it's - Thanks to [Baptiste Mesta](https://github.com/baptistemesta) for - porting the DBeaver formatter to Spotless, and thanks to [DBeaver](https://dbeaver.jkiss.org/) and [its authors](https://github.com/serge-rider/dbeaver/graphs/contributors) for their excellent SQL formatter. - making license headers date-aware [#179](https://github.com/diffplug/spotless/pull/179) -- Thanks to [vmdominguez](https://github.com/vmdominguez) and [Luis Fors](https://github.com/luis-fors-cb) for adding the ability to limit formatting to specific files in gradle ([#322](https://github.com/diffplug/spotless/pull/322)) and maven ([#392](https://github.com/diffplug/spotless/pull/392)), respectively. +- Thanks to [vmdominguez](https://github.com/vmdominguez) and [Luis Fors](https://github.com/luis-fors-cb) for adding the ability to limit formatting to specific files in Gradle ([#322](https://github.com/diffplug/spotless/pull/322)) and Maven ([#392](https://github.com/diffplug/spotless/pull/392)), respectively. - Thanks to [bender316](https://github.com/bender316) for fixing classloading on Java 9 ([#426](https://github.com/diffplug/spotless/pull/426)). - Thanks to [Stefan Oehme](https://github.com/oehme) for tons of help on the internal mechanics of Gradle. - Thanks to [eyalkaspi](https://github.com/eyalkaspi) for adding configurable date ranges to the date-aware license headers. @@ -203,7 +203,7 @@ Once someone has filled in one square of the formatter/build system matrix, it's - Thanks to [Oliver Horn](https://github.com/ohorn) for adding AOSP support for Spotless' google-java-format integration. - Formatting by Eclipse - Special thanks to [Mateusz Matela](https://waynebeaton.wordpress.com/2015/03/15/great-fixes-for-mars-winners-part-i/) for huge improvements to the eclipse code formatter! -- Thanks to [Zac Sweers](https://github.com/ZacSweers) for fixing the highly requested ktlint 0.34+ support ([#469](https://github.com/diffplug/spotless/pull/469)), multiple build updates and fixing a gradle deprecation warning ([#434](https://github.com/diffplug/spotless/pull/434) and others). +- Thanks to [Zac Sweers](https://github.com/ZacSweers) for fixing the highly requested ktlint 0.34+ support ([#469](https://github.com/diffplug/spotless/pull/469)), multiple build updates and fixing a Gradle deprecation warning ([#434](https://github.com/diffplug/spotless/pull/434) and others). - Thanks to [Stephen Panaro](https://github.com/smpanaro) for adding support for ktlint FilenameRule ([#974](https://github.com/diffplug/spotless/pull/974)). - Thanks to [Nelson Osacky](https://github.com/runningcode) for android doc improvements, versions bump, and a build improvement. - Thanks to [Stanley Shyiko](https://github.com/shyiko) for his help integrating [ktlint](https://github.com/shyiko/ktlint). diff --git a/_ext/eclipse-wtp/CHANGES.md b/_ext/eclipse-wtp/CHANGES.md index 0001618b1f..d57618ad8c 100644 --- a/_ext/eclipse-wtp/CHANGES.md +++ b/_ext/eclipse-wtp/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Fix typo in gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) +* Fix typo in Gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) ## [3.23.0] - 2021-09-22 ### Added diff --git a/_ext/gradle/java-setup.gradle b/_ext/gradle/java-setup.gradle index d1a1075d84..0007407250 100644 --- a/_ext/gradle/java-setup.gradle +++ b/_ext/gradle/java-setup.gradle @@ -20,6 +20,7 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation projects.testlib + testRuntimeOnly "org.junit.platform:junit-platform-launcher" } tasks.withType(Test).configureEach { diff --git a/gradle.properties b/gradle.properties index dae471f1e7..b60fa2f805 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8 org.gradle.parallel=true org.gradle.caching=true -org.gradle.unsafe.configuration-cache=true +org.gradle.configuration-cache=true name=spotless description=Spotless - keep your code spotless with Gradle @@ -21,7 +21,6 @@ artifactIdGradle=spotless-plugin-gradle # Build requirements VER_JAVA=11 -VER_SPOTBUGS=4.7.3 VER_JSR_305=3.0.2 # Dependencies provided by Spotless plugin @@ -32,4 +31,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.7.0.202309050840-r VER_JUNIT=5.10.0 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.5.0 +VER_MOCKITO=5.6.0 diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 495694a5be..d6f0afa5a0 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -192,17 +192,13 @@ if (System.env['JITPACK'] == 'true' || version.endsWith('-SNAPSHOT')) { changelogTasks.named('changelogBump').configure { dependsOn ":${thisProj.path}:publishPluginMavenPublicationToSonatypeRepository" dependsOn ":closeAndReleaseSonatypeStagingRepository" - // if we have a gradle plugin, we need to push it up to the plugin portal too + // if we have a Gradle plugin, we need to push it up to the plugin portal too if (thisProj.tasks.names.contains('publishPlugins')) { dependsOn thisProj.tasks.named('publishPlugins') } } } -tasks.withType(Sign).configureEach { - notCompatibleWithConfigurationCache("https://github.com/gradle/gradle/issues/13470") -} - tasks.withType(AbstractArchiveTask).configureEach { preserveFileTimestamps = false reproducibleFileOrder = true diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 5a1e23ef0a..b152097653 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -14,11 +14,14 @@ tasks.withType(JavaCompile).configureEach { ////////////// apply plugin: 'com.github.spotbugs' spotbugs { - toolVersion = VER_SPOTBUGS ignoreFailures = false // bug free or it doesn't ship! reportLevel = 'medium' // low|medium|high (low = sensitive to even minor mistakes) omitVisitors = [ - 'FindReturnRef'] // https://spotbugs.readthedocs.io/en/latest/detectors.html#findreturnref + // https://spotbugs.readthedocs.io/en/latest/detectors.html#constructorthrow + 'ConstructorThrow', + // https://spotbugs.readthedocs.io/en/latest/detectors.html#findreturnref + 'FindReturnRef', + ] } tasks.named('spotbugsTest') { enabled = false @@ -30,16 +33,10 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { reports { html.enabled = true } - notCompatibleWithConfigurationCache("https://github.com/spotbugs/spotbugs-gradle-plugin/issues/670") } -tasks.named('spotbugsMain') { - reports { - html.enabled = true - } -} dependencies { compileOnly 'net.jcip:jcip-annotations:1.0' - compileOnly "com.github.spotbugs:spotbugs-annotations:${VER_SPOTBUGS}" + compileOnly "com.github.spotbugs:spotbugs-annotations:${spotbugs.toolVersion.get()}" compileOnly "com.google.code.findbugs:jsr305:${VER_JSR_305}" } diff --git a/gradle/special-tests.gradle b/gradle/special-tests.gradle index d4de449bdd..b096efbe13 100644 --- a/gradle/special-tests.gradle +++ b/gradle/special-tests.gradle @@ -17,6 +17,12 @@ tasks.withType(Test).configureEach { maxRetries = 2 maxFailures = 10 } + + // There are only 2 cores in each GitHub Action Runner, we use all of them here. + maxParallelForks = Runtime.getRuntime().availableProcessors() + } else { + // https://docs.gradle.org/8.4/userguide/performance.html#execute_tests_in_parallel + maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 } } diff --git a/gradle/spotless-freshmark.gradle b/gradle/spotless-freshmark.gradle index 2a79ab01ba..54623eb05a 100644 --- a/gradle/spotless-freshmark.gradle +++ b/gradle/spotless-freshmark.gradle @@ -11,7 +11,6 @@ Action freshmarkSetup = { it.put('no', ':white_large_square:') } it.indentWithSpaces(2) - it.trimTrailingWhitespace() it.endWithNewline() } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar old mode 100755 new mode 100644 index afba109285..7f93135c49 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4e86b92707..3fa8f862f7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 65dcd68d65..1aa94a4269 100755 --- a/gradlew +++ b/gradlew @@ -83,10 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 794ab515be..e6524f76bf 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -24,6 +24,7 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" + testRuntimeOnly "org.junit.platform:junit-platform-launcher" } spotless { java { @@ -55,16 +56,16 @@ for (needsP2 in NEEDS_P2_DEPS) { add("${needsP2}CompileOnly", "dev.equo.ide:solstice:${VER_SOLSTICE}") } } -jar { + +def jar = tasks.named('jar', Jar) { for (needsP2 in NEEDS_P2_DEPS) { - from sourceSets.getByName(needsP2).output.classesDirs + from sourceSets.named(needsP2).map { it.output.classesDirs } } } + tasks.withType(Test).configureEach { dependsOn jar - doFirst { - classpath += jar.outputs.files - } + classpath += jar.get().outputs.files } apply plugin: 'dev.equo.p2deps' diff --git a/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtFormatterStepImpl.java b/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtFormatterStepImpl.java index 40c02d8f3a..b394b6278d 100644 --- a/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtFormatterStepImpl.java +++ b/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtFormatterStepImpl.java @@ -16,11 +16,14 @@ package com.diffplug.spotless.extra.glue.jdt; import java.io.File; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; +import java.util.stream.Collectors; -import org.eclipse.jdt.core.ToolFactory; import org.eclipse.jdt.core.formatter.CodeFormatter; import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.text.edits.TextEdit; @@ -33,7 +36,12 @@ public class EclipseJdtFormatterStepImpl { private final CodeFormatter codeFormatter; public EclipseJdtFormatterStepImpl(Properties settings) { - this.codeFormatter = ToolFactory.createCodeFormatter(settings, ToolFactory.M_FORMAT_EXISTING); + Map options = settings.entrySet().stream().collect(Collectors.toMap( + e -> String.valueOf(e.getKey()), + e -> String.valueOf(e.getValue()), + (prev, next) -> next, + HashMap::new)); + this.codeFormatter = new DefaultCodeFormatter(options); } /** Formatting Java string, distinguishing module-info and compilation unit by file name */ diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java index 3be75637be..93a95bd6ac 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java @@ -246,7 +246,7 @@ static class Runtime { /** * Default line ending, determined in this order (paths are a teensy different platform to platform). - * + *

* - .git/config (per-repo) * - ~/.gitconfig (per-user) * - /etc/gitconfig (system-wide) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java index 70f0b9cb99..94065f0059 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ private GitWorkarounds() {} /** * Finds the .git directory for the given project directory. - * + *

* Ordinarily one would just use JGit for this, but it doesn't support worktrees properly. * So this applies an additional workaround for that. * @@ -55,7 +55,7 @@ private GitWorkarounds() {} /** * Creates a {@link RepositorySpecificResolver} for the given project directory. - * + *

* This applies a workaround for JGit not supporting worktrees properly. * * @param projectDir the project directory. @@ -67,7 +67,7 @@ static RepositorySpecificResolver fileRepositoryResolverForProject(File projectD /** * Creates a {@link RepositorySpecificResolver} for the given project directory. - * + *

* This applies a workaround for JGit not supporting worktrees properly. * * @param projectDir the project directory. @@ -86,7 +86,7 @@ static RepositorySpecificResolver fileRepositoryResolverForProject(File projectD /** * Piggyback on the {@link FileRepositoryBuilder} mechanics for finding the git directory. - * + *

* Here we take into account that git repositories can share a common directory. This directory * will contain ./config ./objects/, ./info/, and ./refs/. */ diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java index bcbb58c0f6..8767b68dfe 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java @@ -27,7 +27,7 @@ /** * Formatter step which calls out to the Eclipse CDT formatter. - * + *

* Eclipse-CDT org.eclipse.core.contenttype.contentTypes * extension cSource, cHeader, cxxSource and cxxHeader. * can handle: "c", "h", "C", "cpp", "cxx", "cc", "c++", "h", "hpp", "hh", "hxx", "inc" diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java index 55336e8c04..d43478c0b6 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java @@ -249,9 +249,9 @@ private String diff(File file) throws IOException { /** * Returns a git-style diff between the two unix strings. - * + *

* Output has no trailing newlines. - * + *

* Boolean args determine whether whitespace or line endings will be visible. */ private static String diffWhitespaceLineEndings(String dirty, String clean, boolean whitespace, boolean lineEndings) throws IOException { @@ -278,7 +278,7 @@ private static String diffWhitespaceLineEndings(String dirty, String clean, bool /** * Makes the whitespace and/or the lineEndings visible. - * + *

* MyersDiff wants inputs with only unix line endings. So this ensures that that is the case. */ private static String visibleWhitespaceLineEndings(String input, boolean whitespace, boolean lineEndings) { diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java index 25a269834c..0702881ef9 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java @@ -24,7 +24,7 @@ public class GrEclipseFormatterStepSpecialCaseTest { /** * https://github.com/diffplug/spotless/issues/1657 - * + *

* broken: ${parm == null ? "" : "$parm"} * works: ${parm == null ? "" : "parm"} */ diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepSpecialCaseTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepSpecialCaseTest.java index eb93cf1f09..21ec889ed6 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepSpecialCaseTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepSpecialCaseTest.java @@ -15,16 +15,24 @@ */ package com.diffplug.spotless.extra.java; +import java.io.File; +import java.util.List; + import org.junit.jupiter.api.Test; import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.TestProvisioner; +import com.diffplug.spotless.extra.EquoBasedStepBuilder; public class EclipseJdtFormatterStepSpecialCaseTest { /** https://github.com/diffplug/spotless/issues/1638 */ @Test public void issue_1638() { - StepHarness.forStep(EclipseJdtFormatterStep.createBuilder(TestProvisioner.mavenCentral()).build()) + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource("eclipse_formatter_issue_1638.xml").getFile()); + EquoBasedStepBuilder builder = EclipseJdtFormatterStep.createBuilder(TestProvisioner.mavenCentral()); + builder.setPreferences(List.of(file)); + StepHarness.forStep(builder.build()) .testResource("java/eclipse/AbstractType.test", "java/eclipse/AbstractType.clean"); } } diff --git a/lib-extra/src/test/resources/eclipse_formatter_issue_1638.xml b/lib-extra/src/test/resources/eclipse_formatter_issue_1638.xml new file mode 100644 index 0000000000..583df63026 --- /dev/null +++ b/lib-extra/src/test/resources/eclipse_formatter_issue_1638.xml @@ -0,0 +1,391 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/build.gradle b/lib/build.gradle index 0288277c78..a3424a7ee9 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -69,6 +69,7 @@ dependencies { testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ" testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" + testCommonRuntimeOnly "org.junit.platform:junit-platform-launcher" // GLUE CODE (alphabetic order please) // cleanthat diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 4ee70c6c88..32ef497de8 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -17,8 +17,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -53,17 +51,15 @@ public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter { private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; static { - List> list = new ArrayList<>(); - list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); //noinspection deprecation - list.add(DisabledRulesEditorConfigPropertyKt.getDISABLED_RULES_PROPERTY()); - //noinspection KotlinInternalInJava,deprecation - list.add(DisabledRulesEditorConfigPropertyKt.getKTLINT_DISABLED_RULES_PROPERTY()); - list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); - list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); - list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); - list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); - DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of( + CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(), + DisabledRulesEditorConfigPropertyKt.getDISABLED_RULES_PROPERTY(), + DisabledRulesEditorConfigPropertyKt.getKTLINT_DISABLED_RULES_PROPERTY(), + IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(), + IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(), + InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(), + MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); } static class FormatterCallback implements Function2 { @@ -77,9 +73,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format( + Path path, + Path editorConfigPath, + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV2.class, RuleSetProviderV2.class.getClassLoader()) diff --git a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java index b391c7b740..1ad52da661 100644 --- a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java @@ -19,8 +19,6 @@ import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -61,15 +59,14 @@ public class KtLintCompat0Dot49Dot0Adapter implements KtLintCompatAdapter { private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; static { - List> list = new ArrayList<>(); - list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); - list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY()); - list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); - list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); - list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); - list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); - list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); - DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of( + CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(), + EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY(), + IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(), + IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(), + InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(), + MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY(), + RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); } private static final Method RULEID_METHOD; @@ -122,9 +119,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format( + Path path, + Path editorConfigPath, + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) diff --git a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java index 22333392c1..2c7fff3f2e 100644 --- a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java @@ -17,7 +17,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -61,15 +60,14 @@ public class KtLintCompat0Dot50Dot0Adapter implements KtLintCompatAdapter { private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; static { - List> list = new ArrayList<>(); - list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); - list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY()); - list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); - list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); - list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); - list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); - list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); - DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of( + CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(), + EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY(), + IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(), + IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(), + InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(), + MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY(), + RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); } static class FormatterCallback implements Function2 { @@ -84,9 +82,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format( + Path path, + Path editorConfigPath, + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index 9c2792f769..e65d0503ba 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -17,7 +17,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -61,15 +60,14 @@ public class KtLintCompat1Dot0Dot0Adapter implements KtLintCompatAdapter { private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; static { - List> list = new ArrayList<>(); - list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); - list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY()); - list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); - list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); - list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); - list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); - list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); - DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of( + CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(), + EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY(), + IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(), + IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(), + InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(), + MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY(), + RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); } static class FormatterCallback implements Function2 { @@ -84,9 +82,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format( + Path path, + Path editorConfigPath, + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 5e5e5fb445..1bfa0da6da 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -20,6 +20,8 @@ public interface KtLintCompatAdapter { - String format(String text, Path path, boolean isScript, Path editorConfigPath, Map userData, + String format( + Path path, + Path editorConfigPath, Map editorConfigOverrideMap); } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 7ae0222566..b81e107609 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -24,14 +24,13 @@ import com.diffplug.spotless.glue.ktlint.compat.*; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { - - private final Map userData; - private final boolean isScript; private final KtLintCompatAdapter adapter; private final FileSignature editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath, Map userData, + public KtlintFormatterFunc( + String version, + FileSignature editorConfigPath, Map editorConfigOverrideMap) { String[] versions = version.split("\\."); int majorVersion = Integer.parseInt(versions[0]); @@ -58,17 +57,17 @@ public KtlintFormatterFunc(String version, boolean isScript, FileSignature edito } this.editorConfigPath = editorConfigPath; this.editorConfigOverrideMap = editorConfigOverrideMap; - this.userData = userData; - this.isScript = isScript; } @Override public String applyWithFile(String unix, File file) { - Path absoluteEditorConfigPath = null; if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } - return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, userData, editorConfigOverrideMap); + return adapter.format( + file.toPath(), + absoluteEditorConfigPath, + editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java index d07e7e4324..0eb5aa4d2e 100644 --- a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java +++ b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java @@ -34,7 +34,7 @@ * but linked against the `Url[]`. This allows us to ship classfiles which function as glue * code but delay linking/definition to runtime after the user has specified which version * of the formatter they want. - * + *

* For `"org.slf4j.` and (`com.diffplug.spotless.` but not `com.diffplug.spotless.extra.`) * the classes are loaded from the buildToolClassLoader. */ diff --git a/lib/src/main/java/com/diffplug/spotless/ForeignExe.java b/lib/src/main/java/com/diffplug/spotless/ForeignExe.java index d1f8abd3ee..4cb15d1a8a 100644 --- a/lib/src/main/java/com/diffplug/spotless/ForeignExe.java +++ b/lib/src/main/java/com/diffplug/spotless/ForeignExe.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ * Finds a foreign executable and checks its version. * If either part of that fails, it shows you why * and helps you fix it. - * + *

* Usage: {@code ForeignExe.nameAndVersion("grep", "2.5.7").confirmVersionAndGetAbsolutePath()} * will find grep, confirm that it is version 2.5.7, and then return. */ diff --git a/lib/src/main/java/com/diffplug/spotless/FormatExceptionPolicy.java b/lib/src/main/java/com/diffplug/spotless/FormatExceptionPolicy.java index da23f74432..50f49e41db 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatExceptionPolicy.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatExceptionPolicy.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ public interface FormatExceptionPolicy extends Serializable, NoLambda { /** * Returns a byte array representation of everything inside this {@code FormatExceptionPolicy}. - * + *

* The main purpose of this method is to ensure one can't instantiate this class with lambda * expressions, which are notoriously difficult to serialize and deserialize properly. */ diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index 46793e24f6..68d9c443bf 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -193,7 +193,7 @@ public void applyTo(File file) throws IOException { /** * Applies formatting to the given file. - * + *

* Returns null if the file was already clean, or the * formatted result with unix newlines if it was not. */ diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java index 14b407a2eb..acd05e031b 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java @@ -42,11 +42,11 @@ interface Closeable extends FormatterFunc, AutoCloseable { /** * Dangerous way to create a {@link Closeable} from an AutoCloseable and a function. - * + *

* It's important for FormatterStep's to allocate their resources as lazily as possible. * It's easy to create a resource inside the state, and not realize that it may not be * released. It's far better to use one of the non-deprecated {@code of()} methods below. - * + *

* The bug (and its fix) which is easy to write using this method: https://github.com/diffplug/spotless/commit/7f16ecca031810b5e6e6f647e1f10a6d2152d9f4 * How the {@code of()} methods below make the correct thing easier to write and safer: https://github.com/diffplug/spotless/commit/18c10f9c93d6f18f753233d0b5f028d5f0961916 */ diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index 5f6ec168d4..ca37303b1f 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -23,7 +23,7 @@ /** * An implementation of this class specifies a single step in a formatting process. - * + *

* The input is guaranteed to have unix-style newlines, and the output is required * to not introduce any windows-style newlines as well. */ @@ -75,7 +75,7 @@ public default FormatterStep filterByContent(OnMatch onMatch, String contentPatt /** * Returns a new FormatterStep which will only apply its changes * to files which pass the given filter. - * + *

* The provided filter must be serializable. */ public default FormatterStep filterByFile(SerializableFileFilter filter) { @@ -86,7 +86,7 @@ public default FormatterStep filterByFile(SerializableFileFilter filter) { * Implements a FormatterStep in a strict way which guarantees correct and lazy implementation * of up-to-date checks. This maximizes performance for cases where the FormatterStep is not * actually needed (e.g. don't load eclipse setting file unless this step is actually running) - * while also ensuring that gradle can detect changes in a step's settings to determine that + * while also ensuring that Gradle can detect changes in a step's settings to determine that * it needs to rerun a format. */ abstract class Strict extends LazyForwardingEquality implements FormatterStep { diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java index 17b62e75c6..869e7b7966 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java @@ -27,7 +27,7 @@ /** * Standard implementation of FormatExtension which cleanly enforces * separation of serializable configuration and a pure format function. - * + *

* Not an inner-class of FormatterStep so that it can stay entirely private * from the API. */ diff --git a/lib/src/main/java/com/diffplug/spotless/JarState.java b/lib/src/main/java/com/diffplug/spotless/JarState.java index afd7c1ddf2..48686c49f8 100644 --- a/lib/src/main/java/com/diffplug/spotless/JarState.java +++ b/lib/src/main/java/com/diffplug/spotless/JarState.java @@ -32,7 +32,7 @@ * Grabs a jar and its dependencies from maven, * and makes it easy to access the collection in * a classloader. - * + *

* Serializes the full state of the jar, so it can * catch changes in a SNAPSHOT version. */ diff --git a/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java b/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java index e2d6ba8988..8727be3a3c 100644 --- a/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java +++ b/lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ public abstract class LazyForwardingEquality implements /** * This function is guaranteed to be called at most once. * If the state is never required, then it will never be called at all. - * + *

* Throws exception because it's likely that there will be some IO going on. */ protected abstract T calculateState() throws Exception; diff --git a/lib/src/main/java/com/diffplug/spotless/NoLambda.java b/lib/src/main/java/com/diffplug/spotless/NoLambda.java index ce326a6ceb..d2ca6c1401 100644 --- a/lib/src/main/java/com/diffplug/spotless/NoLambda.java +++ b/lib/src/main/java/com/diffplug/spotless/NoLambda.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +21,12 @@ /** * Marker interface to prevent lambda implementations of * single-method interfaces that require serializability. - * + *

* In order for Spotless to support up-to-date checks, all * of its parameters must be {@link Serializable} so that * entries can be written to file, and they must implement * equals and hashCode correctly. - * + *

* This interface and its standard implementation, * {@link EqualityBasedOnSerialization}, are a quick way * to accomplish these goals. @@ -34,7 +34,7 @@ public interface NoLambda extends Serializable { /** * Returns a byte array representation of everything inside this {@code SerializableFileFilter}. - * + *

* The main purpose of this method is to ensure one can't instantiate this class with lambda * expressions, which are notoriously difficult to serialize and deserialize properly. (See * {@code SerializableFileFilterImpl.SkipFilesNamed} for an example of how to make a serializable diff --git a/lib/src/main/java/com/diffplug/spotless/PaddedCell.java b/lib/src/main/java/com/diffplug/spotless/PaddedCell.java index 91914b7908..910fa940d3 100644 --- a/lib/src/main/java/com/diffplug/spotless/PaddedCell.java +++ b/lib/src/main/java/com/diffplug/spotless/PaddedCell.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ /** * Models the result of applying a {@link Formatter} on a given {@link File} * while characterizing various failure modes (slow convergence, cycles, and divergence). - * + *

* See {@link #check(Formatter, File)} as the entry point to this class. */ public final class PaddedCell { @@ -78,9 +78,9 @@ public List steps() { /** * Applies the given formatter to the given file, checking that * F(F(input)) == F(input). - * + *

* If it meets this test, {@link #misbehaved()} will return false. - * + *

* If it fails the test, {@link #misbehaved()} will return true, and you can find * out more about the misbehavior based on its {@link Type}. * diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 4e48042184..48307d7d3a 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -43,7 +43,7 @@ * Shelling out to a process is harder than it ought to be in Java. * If you don't read stdout and stderr on their own threads, you risk * deadlock on a clogged buffer. - * + *

* ProcessRunner allocates two threads specifically for the purpose of * flushing stdout and stderr to buffers. These threads will remain alive until * the ProcessRunner is closed, so it is especially useful for repeated @@ -239,7 +239,7 @@ public boolean exitNotZero() { /** * Asserts that the exit code was zero, and if so, returns * the content of stdout encoded with the given charset. - * + *

* If the exit code was not zero, throws an exception * with useful debugging information. */ diff --git a/lib/src/main/java/com/diffplug/spotless/ThrowingEx.java b/lib/src/main/java/com/diffplug/spotless/ThrowingEx.java index f664c62bf3..6eb573b5d8 100644 --- a/lib/src/main/java/com/diffplug/spotless/ThrowingEx.java +++ b/lib/src/main/java/com/diffplug/spotless/ThrowingEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ /** * Basic functional interfaces which throw exception, along with * static helper methods for calling them. - * + *

* Contains most of the functionality of Durian's Throwing and Errors * classes, but stripped down and renamed to avoid any confusion. */ @@ -80,7 +80,7 @@ public static java.util.function.Function wrap(ThrowingEx.Function< /** * Casts or wraps the given exception to be a RuntimeException. - * + *

* If the input exception is a RuntimeException, it is simply * cast and returned. Otherwise, it wrapped in a * {@link WrappedAsRuntimeException} and returned. diff --git a/lib/src/main/java/com/diffplug/spotless/annotations/Internal.java b/lib/src/main/java/com/diffplug/spotless/annotations/Internal.java index 77a318f268..d87265fe2d 100644 --- a/lib/src/main/java/com/diffplug/spotless/annotations/Internal.java +++ b/lib/src/main/java/com/diffplug/spotless/annotations/Internal.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ /** * Signifies that a {@code public} API is actually an implementation detail, and should be treated as if it * were {@code private}. - * + *

* The user of the API should be warned that it may unexpectedly disappear in future versions of * Spotless. Usually the best place to put this warning is in the API's class JavaDoc. */ diff --git a/lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java b/lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java new file mode 100644 index 0000000000..e24feb5cd3 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java @@ -0,0 +1,76 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.groovy; + +import java.io.BufferedReader; +import java.io.Serializable; +import java.io.StringReader; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; + +/** + * Removes all semicolons from the end of lines. + * + * @author Jose Luis Badano + */ +public final class RemoveSemicolonsStep { + private static final String NAME = "Remove unnecessary semicolons"; + + private RemoveSemicolonsStep() { + // do not instantiate + } + + public static FormatterStep create() { + return FormatterStep.createLazy(NAME, + State::new, + RemoveSemicolonsStep.State::toFormatter); + } + + private static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + FormatterFunc toFormatter() { + return raw -> { + try (BufferedReader reader = new BufferedReader(new StringReader(raw))) { + StringBuilder result = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + result.append(removeSemicolon(line)); + result.append(System.lineSeparator()); + } + return result.toString(); + } + }; + } + + /** + * Removes the last semicolon in a line if it exists. + * + * @param line the line to remove the semicolon from + * @return the line without the last semicolon + */ + private String removeSemicolon(String line) { + // find last semicolon in a string a remove it + int lastSemicolon = line.lastIndexOf(";"); + if (lastSemicolon != -1 && lastSemicolon == line.length() - 1) { + return line.substring(0, lastSemicolon); + } else { + return line; + } + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java index b2424cbe2a..e5d990d807 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java @@ -58,7 +58,11 @@ public static FormatterStep create(String version, String style, Provisioner pro } public static FormatterStep create(String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings) { - return create(groupArtifact, version, style, provisioner, reflowLongStrings, false, DEFAULT_FORMAT_JAVADOC); + return create(groupArtifact, version, style, provisioner, reflowLongStrings, DEFAULT_REORDER_IMPORTS); + } + + public static FormatterStep create(String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings, boolean reorderImports) { + return create(groupArtifact, version, style, provisioner, reflowLongStrings, reorderImports, DEFAULT_FORMAT_JAVADOC); } /** Creates a step which formats everything - groupArtifact, code, import order, and unused imports - and optionally reflows long strings. */ @@ -127,7 +131,11 @@ static final class State implements Serializable { } State(String stepName, String version, String style, Provisioner provisioner, boolean reflowLongStrings) throws Exception { - this(stepName, MAVEN_COORDINATE, version, style, provisioner, reflowLongStrings, DEFAULT_REORDER_IMPORTS, DEFAULT_FORMAT_JAVADOC); + this(stepName, version, style, provisioner, reflowLongStrings, DEFAULT_REORDER_IMPORTS); + } + + State(String stepName, String version, String style, Provisioner provisioner, boolean reflowLongStrings, boolean reorderImports) throws Exception { + this(stepName, MAVEN_COORDINATE, version, style, provisioner, reflowLongStrings, reorderImports, DEFAULT_FORMAT_JAVADOC); } State(String stepName, String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings, boolean reorderImports, boolean formatJavadoc) throws Exception { diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index fefda39784..a2650e31fc 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -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"); diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index d08c59b839..55b4ca4520 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -19,8 +19,11 @@ import java.io.Serializable; import java.lang.reflect.Constructor; import java.util.Collections; +import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.TreeMap; import javax.annotation.Nullable; @@ -36,51 +39,28 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "1.0.0"; - static final String NAME = "ktlint"; - static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; - static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; + private static final String DEFAULT_VERSION = "1.0.1"; + private static final String NAME = "ktlint"; + private static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; + private static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); } public static FormatterStep create(String version, Provisioner provisioner) { - return create(version, provisioner, Collections.emptyMap(), Collections.emptyMap()); - } - - public static FormatterStep create(String version, Provisioner provisioner, - Map userData, Map 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 userData, - Map editorConfigOverride) { - return create(version, - provisioner, - true, - editorConfigPath, - userData, - editorConfigOverride); + return create(version, provisioner, null, Collections.emptyMap(), Collections.emptyList()); } public static FormatterStep create(String version, Provisioner provisioner, - boolean isScript, @Nullable FileSignature editorConfig, - Map userData, - Map editorConfigOverride) { + Map editorConfigOverride, + List customRuleSets) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, isScript, editorConfig, userData, editorConfigOverride), + () -> new State(version, provisioner, editorConfig, editorConfigOverride, customRuleSets), State::createFormat); } @@ -88,14 +68,10 @@ public static String defaultVersion() { return DEFAULT_VERSION; } - static final class State implements Serializable { + private 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 userData; + private final JarState jarState; private final TreeMap editorConfigOverride; private final String version; @Nullable @@ -103,25 +79,24 @@ static final class State implements Serializable { State(String version, Provisioner provisioner, - boolean isScript, @Nullable FileSignature editorConfigPath, - Map userData, - Map editorConfigOverride) throws IOException { + Map editorConfigOverride, + List customRuleSets) 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); + String ktlintCoordinate = (version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version; + Set mavenCoordinates = new HashSet<>(customRuleSets); + mavenCoordinates.add(ktlintCoordinate); + this.jarState = JarState.from(mavenCoordinates, 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, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, userData, editorConfigOverride); + String.class, FileSignature.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(version, editorConfigPath, editorConfigOverride); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java b/lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java index 76016d68db..fce1497de6 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ class FileFinder { private final List>> fileCandidateFinders; private FileFinder(Builder builder) { - this.fileCandidateFinders = Collections.unmodifiableList(new ArrayList<>(builder.candidateFinders)); + this.fileCandidateFinders = List.copyOf(builder.candidateFinders); } static Builder finderForFilename(String fileName) { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java b/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java index 3ac20d892b..848dd030dd 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java @@ -60,7 +60,7 @@ private static String jsonEscape(JsonRawValue jsonRawValue) { private static String jsonEscape(String unescaped) { /** * the following characters are reserved in JSON and must be properly escaped to be used in strings: - * + *

* Backspace is replaced with \b * Form feed is replaced with \f * Newline is replaced with \n @@ -68,7 +68,7 @@ private static String jsonEscape(String unescaped) { * Tab is replaced with \t * Double quote is replaced with \" * Backslash is replaced with \\ - * + *

* additionally we handle xhtml '' string * and non-ascii chars */ diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java index 4759d2f914..1a7db1c9b8 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java @@ -16,8 +16,6 @@ package com.diffplug.spotless.npm; import java.io.File; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; @@ -35,7 +33,7 @@ public NpmPathResolver(File explicitNpmExecutable, File explicitNodeExecutable, this.explicitNpmExecutable = explicitNpmExecutable; this.explicitNodeExecutable = explicitNodeExecutable; this.explicitNpmrcFile = explicitNpmrcFile; - this.additionalNpmrcLocations = Collections.unmodifiableList(new ArrayList<>(additionalNpmrcLocations)); + this.additionalNpmrcLocations = List.copyOf(additionalNpmrcLocations); } /** diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java index 6956545135..cc04c7b182 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java @@ -95,8 +95,8 @@ private static String recommendPlugin(File file) { + String.format("", pluginName) + "\n\n" + "For instructions on how to include plugins for prettier in spotless see our documentation:\n" - + "- for gradle \n" - + "- for maven "; + + "- for Gradle \n" + + "- for Maven "; } private static String guessPlugin(File file) { diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBPKeywordType.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBPKeywordType.java index 93c9afb5f8..d31b7520f7 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBPKeywordType.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBPKeywordType.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ * Forked from * DBeaver - Universal Database Manager * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * + *

* Based on DBPKeywordType from https://github.com/serge-rider/dbeaver, * which itself is licensed under the Apache 2.0 license. */ diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBeaverSQLFormatterConfiguration.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBeaverSQLFormatterConfiguration.java index f488bd5a00..58a0119a7f 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBeaverSQLFormatterConfiguration.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBeaverSQLFormatterConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +22,11 @@ /** * **Warning:** Use this class at your own risk. It is an implementation detail and is not * guaranteed to exist in future versions. - * + *

* Forked from * DBeaver - Universal Database Manager * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * + *

* Based on SQLFormatterConfiguration from https://github.com/serge-rider/dbeaver, * which itself is licensed under the Apache 2.0 license. */ diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/Pair.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/Pair.java index c06ea5a1c0..4ab9f54a0b 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/Pair.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/Pair.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ * Forked from * DBeaver - Universal Database Manager * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * + *

* Based on Pair from https://github.com/serge-rider/dbeaver, * which itself is licensed under the Apache 2.0 license. */ diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLConstants.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLConstants.java index 2dc0b61aa0..698c87458f 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLConstants.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLConstants.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ * Forked from * DBeaver - Universal Database Manager * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * + *

* Based on SQLConstants from https://github.com/serge-rider/dbeaver, * which itself is licensed under the Apache 2.0 license. */ diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLDialect.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLDialect.java index 3c973885f6..daabd5386b 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLDialect.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLDialect.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ * Forked from * DBeaver - Universal Database Manager * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * + *

* Based on SQLDialect from https://github.com/serge-rider/dbeaver, * which itself is licensed under the Apache 2.0 license. */ diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java index f2c98eebc1..01f0fd759e 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,11 +25,11 @@ /** * **Warning:** Use this class at your own risk. It is an implementation detail and is not * guaranteed to exist in future versions. - * + *

* Forked from * DBeaver - Universal Database Manager * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * + *

* Based on SQLTokenizedFormatter from https://github.com/serge-rider/dbeaver, * which itself is licensed under the Apache 2.0 license. */ diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokensParser.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokensParser.java index 72080d22fc..b1931c3c4c 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokensParser.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokensParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ * Forked from * DBeaver - Universal Database Manager * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * + *

* Based on SQLTokensParser from https://github.com/serge-rider/dbeaver, * which itself is licensed under the Apache 2.0 license. */ diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/TokenType.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/TokenType.java index 5f727db571..d6d75faf9a 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/TokenType.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/TokenType.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ * Forked from * DBeaver - Universal Database Manager * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) - * + *

* Based on TokenType from https://github.com/serge-rider/dbeaver, * which itself is licensed under the Apache 2.0 license. */ diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index 7fc9d1d9a4..17fe40fb9c 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -33,32 +33,28 @@ public class KtLintCompat0Dot48Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - String text = loadAndWriteText(path, "empty_class_body.kt"); + loadAndWriteText(path, "empty_class_body.kt"); final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - String text = loadAndWriteText(path, "fails_no_semicolons.kt"); + loadAndWriteText(path, "fails_no_semicolons.kt"); final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); - Map userData = new HashMap<>(); - Map 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(filePath, null, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java index a0db6ecddc..b34a83ebc3 100644 --- a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java @@ -33,30 +33,26 @@ public class KtLintCompat0Dot49Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); - String text = loadAndWriteText(path, "EmptyClassBody.kt"); + loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); - String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); - Map userData = new HashMap<>(); - Map 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(filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java index f5b76ccae0..0bb501a06e 100644 --- a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java @@ -33,30 +33,26 @@ public class KtLintCompat0Dot50Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); - String text = loadAndWriteText(path, "EmptyClassBody.kt"); + loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); - String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); - Map userData = new HashMap<>(); - Map 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(filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java index 1f8e6023b4..0f5f9cf16c 100644 --- a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -33,30 +33,26 @@ public class KtLintCompat1Dot0Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); - String text = loadAndWriteText(path, "EmptyClassBody.kt"); + loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); - String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); - Map userData = new HashMap<>(); - Map 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(filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 536747a4ff..03ddf370f4 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,18 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896) +### 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)) +* Add a Step to remove semicolons from Groovy files. ([#1881](https://github.com/diffplug/spotless/pull/1881)) +### Fixed +* Fix `GoogleJavaFormatConfig.reorderImports` not working. ([#1872](https://github.com/diffplug/spotless/issues/1872)) + +## [6.22.0] - 2023-09-28 +### Added * Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793)) * Add support for `flexmark` in gradle. Previously only Maven was supported. ([#1801](https://github.com/diffplug/spotless/pull/1801)) * Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). @@ -153,7 +165,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. * `npm`-based formatters `ESLint`, `prettier` and `tsfmt` delay their `npm install` call until the formatters are first - used. For gradle this effectively moves the `npm install` call out of the configuration phase and as such enables + used. For Gradle this effectively moves the `npm install` call out of the configuration phase and as such enables better integration with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522)) * Bump default `ktlint` version to latest `0.48.1` -> `0.48.2` ([#1529](https://github.com/diffplug/spotless/pull/1529)) * Bump default `scalafmt` version to latest `3.6.1` -> `3.7.1` ([#1529](https://github.com/diffplug/spotless/pull/1529)) @@ -203,7 +215,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [6.10.0] - 2022-08-23 ### Added -* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) +* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the Maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) ### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) * Bump default `scalafmt` to latest `3.0.8` -> `3.5.9` (removed support for pre-`3.0.0`) ([#1283](https://github.com/diffplug/spotless/pull/1283)) @@ -363,7 +375,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [6.0.4] - 2021-12-07 ### Fixed -* Fix gradle composite builds ([#860](https://github.com/diffplug/spotless/issues/860)). +* Fix Gradle composite builds ([#860](https://github.com/diffplug/spotless/issues/860)). ## [6.0.3] - 2021-12-06 ### Fixed @@ -488,7 +500,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changed * Update ktfmt from 0.21 to 0.24 ### Fixed -* The `` field in the maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) +* The `` field in the Maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) * Node is re-installed if some other build step removed it ([#863](https://github.com/diffplug/spotless/issues/863)) ## [5.12.4] - 2021-04-21 @@ -679,7 +691,7 @@ println "isEager $isEager" * LineEndings.GIT_ATTRIBUTES is now a bit more efficient, and paves the way for remote build cache support in Gradle. ([#621](https://github.com/diffplug/spotless/pull/621)) * `ratchetFrom` now ratchets from the merge base of `HEAD` and the specified branch. This fixes the surprising behavior when a remote branch advanced ([#631](https://github.com/diffplug/spotless/pull/631) fixes [#627](https://github.com/diffplug/spotless/issues/627)). ### Deprecated -* The default targets for `C/C++`, `freshmark`, `sql`, and `typescript` now generate a warning, asking the user to specify a target manually. There is no well-established convention for these languages in the gradle ecosystem, and the performance of the default target is far worse than a user-provided one. If you dislike this change, please complain in [#634](https://github.com/diffplug/spotless/pull/634). +* The default targets for `C/C++`, `freshmark`, `sql`, and `typescript` now generate a warning, asking the user to specify a target manually. There is no well-established convention for these languages in the Gradle ecosystem, and the performance of the default target is far worse than a user-provided one. If you dislike this change, please complain in [#634](https://github.com/diffplug/spotless/pull/634). * `customLazy` and `customLazyGroovy` now generate a warning, asking the user to migrate to `custom`. There is no longer a performance advantage to `customLazy` in the new modern plugin. See [#635](https://github.com/diffplug/spotless/pull/635/files) for example migrations. * inside the `cpp { }` block, the `eclipse` step now generates a warning, asking you to switch to `eclipseCdt`. It is the same underlying step, but the new name clears up any confusion with the more common Java `eclipse`. [#636](https://github.com/diffplug/spotless/pull/635/files) @@ -757,7 +769,7 @@ spotless { **TLDR: This version improves performance and adds support for the local Gradle Build Cache. You will not need to make any changes in your buildscript.** It is a breaking change only for a few users who have built *other* plugins on top of this one. ### Added -* Support for the gradle build cache. ([#576](https://github.com/diffplug/spotless/pull/576)) +* Support for the Gradle build cache. ([#576](https://github.com/diffplug/spotless/pull/576)) * The local cache will work great, but the remote cache will always miss until [#566](https://github.com/diffplug/spotless/issues/566) is resolved. ### Removed * **BREAKING** it used to be possible for any project to format files in any other project. For example, `:a` could format files in `:b`. It is now only possible to format files within the project directory. It is okay (but not advised) to format files in subprojects, since they are within the project directory. @@ -765,7 +777,7 @@ spotless { * Previously, the `check` and `apply` tasks were just marker tasks, and they called `setCheck` and `setApply` on the "worker" task. Now `check` and `apply` are real tasks in their own right, so the marker-task kludge is no longer necessary. ### Changed * (Power users only) **BREAKING** `SpotlessTask FormatExtension::createIndependentTask` has been removed, and replaced with `SpotlessApply::createIndependentApplyTask`. ([#576](https://github.com/diffplug/spotless/pull/576)) -* Improve suggested gradle invocation for running `spotlessApply`. ([#578](https://github.com/diffplug/spotless/pull/578)) +* Improve suggested Gradle invocation for running `spotlessApply`. ([#578](https://github.com/diffplug/spotless/pull/578)) ## [3.30.0] - 2020-05-11 ### Added @@ -856,11 +868,11 @@ spotless { * Updated default eclipse-jdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * Updated default eclipse-cdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * **KNOWN BUG - accidentally published CDT 9.7 rather than 9.8 - fixed in 3.26.0** -* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) +* Added new Maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) ## [3.23.1] - 2019-06-17 * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) -* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) +* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because Gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) ## [3.23.0] - 2019-04-24 * Updated default ktlint from 0.21.0 to 0.32.0, and Maven coords to com.pinterest ([#394](https://github.com/diffplug/spotless/pull/394)) @@ -1020,7 +1032,7 @@ spotless { ## [3.0.0] - 2017-01-09 * BREAKING CHANGE: `customReplace` and `customReplaceRegex` renamed to just `replace` and `replaceRegex`. -* BREAKING CHANGE: Plugin portal ID is still `com.diffplug.gradle.spotless`, but maven coordinate has changed to `com.diffplug.spotless:spotless-plugin-gradle`. +* BREAKING CHANGE: Plugin portal ID is still `com.diffplug.gradle.spotless`, but Maven coordinate has changed to `com.diffplug.spotless:spotless-plugin-gradle`. * HUGE SPEEDUP: Now supports incremental build / up-to-date-checking. + If you are using `custom` or `customLazy`, you might want to take a look at [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/3.27.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-). * BREAKING CHANGE: `freshmark` no longer includes all project properties by default. All properties must now be added manually: diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index d4537d4b11..4f6b74bdb7 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -5,7 +5,7 @@ output = [ link(shield('Gradle plugin', 'plugins.gradle.org', 'com.diffplug.spotless', 'blue'), 'https://plugins.gradle.org/plugin/com.diffplug.spotless'), link(shield('Changelog', 'changelog', '{{versionLast}}', 'blue'), 'CHANGES.md'), - link(shield('Maven central', 'mavencentral', 'here', 'blue'), 'https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22'), + link(shield('MavenCentral', 'mavencentral', 'here', 'blue'), 'https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22'), link(shield('Javadoc', 'javadoc', 'here', 'blue'), 'https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/{{versionLast}}/index.html'), '', link(shield('VS Code plugin', 'IDE', 'VS Code', 'blueviolet'), 'https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle'), @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.21.0-blue.svg)](CHANGES.md) -[![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-6.22.0-blue.svg)](CHANGES.md) +[![MavenCentral](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -105,7 +105,7 @@ spotless { format 'misc', { // define the files to apply `misc` to - target '*.gradle', '*.md', '.gitignore' + target '*.gradle', '.gitattributes', '.gitignore' // define the steps to apply to those files trimTrailingWhitespace() @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -144,7 +144,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer. ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -301,8 +301,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -320,13 +320,18 @@ spotless { // optional: instead of specifying import groups directly you can specify a config file // export config file: https://github.com/diffplug/spotless/blob/main/ECLIPSE_SCREENSHOTS.md#creating-spotlessimportorder importOrderFile('eclipse-import-order.txt') // import order file as exported from eclipse - - excludeJava() // excludes all Java sources within the Groovy source dirs from formatting + // removes semicolons at the end of lines + removeSemicolons() // the Groovy Eclipse formatter extends the Java Eclipse formatter, // so it formats Java files by default (unless `excludeJava` is used). greclipse() // has its own section below + + licenseHeader('/* (C) $YEAR */') // or licenseHeaderFile - licenseHeader '/* (C) $YEAR */' // or licenseHeaderFile + //---- Below is for `groovy` only ---- + + // excludes all Java sources within the Groovy source dirs from formatting + excludeJava() } groovyGradle { target '*.gradle' // default target of groovyGradle @@ -352,8 +357,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -399,15 +404,19 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```kotlin spotless { kotlin { - // version, userData and editorConfigOverride are all optional + // version, editorConfigPath, editorConfigOverride and customRuleSets are all optional ktlint("1.0.0") - .userData(mapOf("android" to "true")) .setEditorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement .editorConfigOverride( mapOf( "indent_size" to 2, ) ) + .customRuleSets( + listOf( + "io.nlopez.compose.rules:ktlint:0.3.3" + ) + ) } } ``` @@ -427,7 +436,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -459,7 +468,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -491,7 +500,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -527,7 +536,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ### buf -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) **WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem. @@ -559,7 +568,7 @@ buf { ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -580,7 +589,7 @@ spotless { ## Flexmark -`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) [homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). @@ -599,7 +608,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -624,7 +633,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -664,7 +673,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -758,7 +767,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -823,7 +832,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -943,7 +952,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -975,7 +984,7 @@ spotless { ## Gherkin -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/GherkinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java) +- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/GherkinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java) ```gradle spotless { @@ -1362,7 +1371,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1442,9 +1451,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1477,11 +1486,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index ba800173a2..9f6ff31cc9 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -26,6 +26,7 @@ dependencies { testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" testImplementation 'org.owasp.encoder:encoder:1.2.3' + testRuntimeOnly "org.junit.platform:junit-platform-launcher" } apply from: rootProject.file('gradle/special-tests.gradle') diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java new file mode 100644 index 0000000000..657ef06a66 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java @@ -0,0 +1,80 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import static com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull; + +import java.util.Map; +import java.util.Objects; + +import org.gradle.api.Project; + +import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; +import com.diffplug.spotless.groovy.RemoveSemicolonsStep; +import com.diffplug.spotless.java.ImportOrderStep; + +abstract class BaseGroovyExtension extends FormatExtension { + protected BaseGroovyExtension(SpotlessExtension spotless) { + super(spotless); + } + + public void importOrder(String... importOrder) { + addStep(ImportOrderStep.forGroovy().createFrom(importOrder)); + } + + public void importOrderFile(Object importOrderFile) { + Objects.requireNonNull(importOrderFile); + addStep(ImportOrderStep.forGroovy().createFrom(getProject().file(importOrderFile))); + } + + public void removeSemicolons() { + addStep(RemoveSemicolonsStep.create()); + } + + public GrEclipseConfig greclipse() { + return greclipse(GrEclipseFormatterStep.defaultVersion()); + } + + public GrEclipseConfig greclipse(String version) { + return new GrEclipseConfig(version, this); + } + + public static class GrEclipseConfig { + private final EquoBasedStepBuilder builder; + private final FormatExtension extension; + + private GrEclipseConfig(String version, FormatExtension extension) { + this.extension = extension; + builder = GrEclipseFormatterStep.createBuilder(extension.provisioner()); + builder.setVersion(version); + extension.addStep(builder.build()); + } + + public void configFile(Object... configFiles) { + requireElementsNonNull(configFiles); + Project project = extension.getProject(); + builder.setPreferences(project.files(configFiles).getFiles()); + extension.replaceStep(builder.build()); + } + + public GrEclipseConfig withP2Mirrors(Map mirrors) { + builder.setP2Mirrors(mirrors); + extension.replaceStep(builder.build()); + return this; + } + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java new file mode 100644 index 0000000000..7a40d99f26 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -0,0 +1,205 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.Consumer; + +import javax.annotation.Nullable; + +import com.diffplug.common.collect.ImmutableList; +import com.diffplug.common.collect.ImmutableSortedMap; +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.kotlin.DiktatStep; +import com.diffplug.spotless.kotlin.KtLintStep; +import com.diffplug.spotless.kotlin.KtfmtStep; + +abstract class BaseKotlinExtension extends FormatExtension { + protected BaseKotlinExtension(SpotlessExtension spotless) { + super(spotless); + } + + public DiktatConfig diktat() { + return diktat(DiktatStep.defaultVersionDiktat()); + } + + /** Adds the specified version of diktat. */ + public DiktatConfig diktat(String version) { + return new DiktatConfig(version); + } + + public KtlintConfig ktlint() throws IOException { + return ktlint(KtLintStep.defaultVersion()); + } + + /** Adds the specified version of ktlint. */ + public KtlintConfig ktlint(String version) throws IOException { + return new KtlintConfig(version, Collections.emptyMap(), Collections.emptyList()); + } + + /** Uses the ktfmt jar to format source code. */ + public KtfmtConfig ktfmt() { + return ktfmt(KtfmtStep.defaultVersion()); + } + + /** + * Uses the given version of ktfmt and applies the dropbox style + * option to format source code. + */ + public KtfmtConfig ktfmt(String version) { + return new KtfmtConfig(version); + } + + protected abstract boolean isScript(); + + public class DiktatConfig { + private final String version; + private FileSignature config; + + private DiktatConfig(String version) { + Objects.requireNonNull(version, "version"); + this.version = version; + addStep(createStep()); + } + + public DiktatConfig configFile(Object file) throws IOException { + // Specify the path to the configuration file + if (file == null) { + this.config = null; + } else { + this.config = FileSignature.signAsList(getProject().file(file)); + } + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return DiktatStep.create(version, provisioner(), isScript(), config); + } + } + + public class KtfmtConfig { + private final String version; + private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); + private KtfmtStep.Style style; + private KtfmtStep.KtfmtFormattingOptions options; + + private KtfmtConfig(String version) { + Objects.requireNonNull(version); + this.version = Objects.requireNonNull(version); + addStep(createStep()); + } + + public ConfigurableStyle dropboxStyle() { + return style(KtfmtStep.Style.DROPBOX); + } + + public ConfigurableStyle googleStyle() { + return style(KtfmtStep.Style.GOOGLE); + } + + public ConfigurableStyle kotlinlangStyle() { + return style(KtfmtStep.Style.KOTLINLANG); + } + + public void configure(Consumer optionsConfiguration) { + this.configurableStyle.configure(optionsConfiguration); + } + + private ConfigurableStyle style(KtfmtStep.Style style) { + this.style = style; + replaceStep(createStep()); + return configurableStyle; + } + + private FormatterStep createStep() { + return KtfmtStep.create(version, provisioner(), style, options); + } + + public class ConfigurableStyle { + private void configure(Consumer optionsConfiguration) { + KtfmtStep.KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtStep.KtfmtFormattingOptions(); + optionsConfiguration.accept(ktfmtFormattingOptions); + options = ktfmtFormattingOptions; + replaceStep(createStep()); + } + } + } + + public class KtlintConfig { + private final String version; + private FileSignature editorConfigPath; + private Map editorConfigOverride; + private List customRuleSets; + + private KtlintConfig( + String version, + Map editorConfigOverride, + List customRuleSets) throws IOException { + Objects.requireNonNull(version); + File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); + FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; + this.version = version; + this.editorConfigPath = editorConfigPath; + this.editorConfigOverride = editorConfigOverride; + this.customRuleSets = customRuleSets; + addStep(createStep()); + } + + public KtlintConfig setEditorConfigPath(@Nullable Object editorConfigPath) throws IOException { + if (editorConfigPath == null) { + this.editorConfigPath = null; + } else { + 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; + } + + public KtlintConfig editorConfigOverride(Map editorConfigOverride) { + // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized + // representation. + this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); + replaceStep(createStep()); + return this; + } + + public KtlintConfig customRuleSets(List customRuleSets) { + this.customRuleSets = ImmutableList.copyOf(customRuleSets); + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return KtLintStep.create( + version, + provisioner(), + editorConfigPath, + editorConfigOverride, + customRuleSets); + } + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 30fded9d5f..eae8ac667d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -204,14 +204,14 @@ protected boolean isLicenseHeaderStep(FormatterStep formatterStep) { /** * Sets which files should be formatted. Files to be formatted = (target - * targetExclude). - * + *

* When this method is called multiple times, only the last call has any effect. - * + *

* FileCollections pass through raw. Strings are treated as the 'include' arg to * fileTree, with project.rootDir as the dir. List are treated as the * 'includes' arg to fileTree, with project.rootDir as the dir. Anything else * gets passed to getProject().files(). - * + *

* If you pass any strings that start with "**\/*", this method will * automatically filter out "build", ".gradle", and ".git" folders. */ @@ -222,9 +222,9 @@ public void target(Object... targets) { /** * Sets which files will be excluded from formatting. Files to be formatted = * (target - targetExclude). - * + *

* When this method is called multiple times, only the last call has any effect. - * + *

* FileCollections pass through raw. Strings are treated as the 'include' arg to * fileTree, with project.rootDir as the dir. List are treated as the * 'includes' arg to fileTree, with project.rootDir as the dir. Anything else @@ -236,7 +236,7 @@ public void targetExclude(Object... targets) { /** * Excludes all files whose content contains {@code string}. - * + *

* When this method is called multiple times, only the last call has any effect. */ public void targetExcludeIfContentContains(String string) { @@ -245,7 +245,7 @@ public void targetExcludeIfContentContains(String string) { /** * Excludes all files whose content contains the given regex. - * + *

* When this method is called multiple times, only the last call has any effect. */ public void targetExcludeIfContentContainsRegex(String regex) { @@ -392,13 +392,13 @@ public void clearSteps() { * An optional performance optimization if you are using any of the * {@code custom} methods. If you aren't explicitly calling {@code custom}, then * this method has no effect. - * + *

* Spotless tracks what files have changed from run to run, so that it can run * faster by only checking files which have changed, or whose formatting steps - * have changed. If you use the {@code custom} methods, then gradle can never + * have changed. If you use the {@code custom} methods, then Gradle can never * mark your files as {@code up-to-date}, because it can't know if perhaps the * behavior of your custom function has changed. - * + *

* If you set {@code bumpThisNumberIfACustomStepChanges( )}, then * spotless will assume that the custom rules have not changed if the number has * not changed. If a custom rule does change, then you must bump the number so @@ -1090,16 +1090,16 @@ public SpotlessApply createIndependentApplyTask(String taskName) { /** * Creates an independent {@link SpotlessApply} for (very) unusual * circumstances. - * + *

* Most users will not want this method. In the rare case that you want to * create a {@code SpotlessApply} which is independent of the normal Spotless * machinery, this will let you do that. - * + *

* The returned task will not be hooked up to the global {@code spotlessApply}, * and there will be no corresponding {@code check} task. - * + *

* The task name must not end with `Apply`. - * + *

* NOTE: does not respect the rarely-used {@code spotlessFiles} * property. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java index a7f3d98ce4..676bed0aea 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java @@ -15,27 +15,19 @@ */ package com.diffplug.gradle.spotless; -import static com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull; - -import java.util.Map; -import java.util.Objects; - import javax.inject.Inject; import org.gradle.api.GradleException; -import org.gradle.api.Project; import org.gradle.api.internal.plugins.DslObject; import org.gradle.api.plugins.GroovyBasePlugin; import org.gradle.api.tasks.GroovySourceDirectorySet; import org.gradle.api.tasks.GroovySourceSet; import org.gradle.util.GradleVersion; -import com.diffplug.spotless.extra.EquoBasedStepBuilder; -import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; import com.diffplug.spotless.generic.LicenseHeaderStep; -import com.diffplug.spotless.java.ImportOrderStep; -public class GroovyExtension extends FormatExtension implements HasBuiltinDelimiterForLicense, JvmLang { +public class GroovyExtension extends BaseGroovyExtension implements HasBuiltinDelimiterForLicense, JvmLang { + private boolean excludeJava = false; static final String NAME = "groovy"; @Inject @@ -43,8 +35,6 @@ public GroovyExtension(SpotlessExtension spotless) { super(spotless); } - boolean excludeJava = false; - /** Excludes .java files, to focus on only .groovy files. */ public void excludeJava() { excludeJava(true); @@ -65,48 +55,6 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { return licenseHeaderFile(licenseHeaderFile, JavaExtension.LICENSE_HEADER_DELIMITER); } - public void importOrder(String... importOrder) { - addStep(ImportOrderStep.forGroovy().createFrom(importOrder)); - } - - public void importOrderFile(Object importOrderFile) { - Objects.requireNonNull(importOrderFile); - addStep(ImportOrderStep.forGroovy().createFrom(getProject().file(importOrderFile))); - } - - public GrEclipseConfig greclipse() { - return greclipse(GrEclipseFormatterStep.defaultVersion()); - } - - public GrEclipseConfig greclipse(String version) { - return new GrEclipseConfig(version, this); - } - - public static class GrEclipseConfig { - private final EquoBasedStepBuilder builder; - private final FormatExtension extension; - - GrEclipseConfig(String version, FormatExtension extension) { - this.extension = extension; - builder = GrEclipseFormatterStep.createBuilder(extension.provisioner()); - builder.setVersion(version); - extension.addStep(builder.build()); - } - - public void configFile(Object... configFiles) { - requireElementsNonNull(configFiles); - Project project = extension.getProject(); - builder.setPreferences(project.files(configFiles).getFiles()); - extension.replaceStep(builder.build()); - } - - public GrEclipseConfig withP2Mirrors(Map mirrors) { - builder.setP2Mirrors(mirrors); - extension.replaceStep(builder.build()); - return this; - } - } - /** If the user hasn't specified the files yet, we'll assume he/she means all of the groovy files. */ @Override protected void setupTask(SpotlessTask task) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java index 30cb75a2a3..120f99f27a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,9 @@ */ package com.diffplug.gradle.spotless; -import java.util.Objects; - import javax.inject.Inject; -import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; -import com.diffplug.spotless.java.ImportOrderStep; - -public class GroovyGradleExtension extends FormatExtension { +public class GroovyGradleExtension extends BaseGroovyExtension { private static final String GRADLE_FILE_EXTENSION = "*.gradle"; static final String NAME = "groovyGradle"; @@ -31,23 +26,6 @@ public GroovyGradleExtension(SpotlessExtension spotless) { super(spotless); } - public void importOrder(String... importOrder) { - addStep(ImportOrderStep.forGroovy().createFrom(importOrder)); - } - - public void importOrderFile(Object importOrderFile) { - Objects.requireNonNull(importOrderFile); - addStep(ImportOrderStep.forGroovy().createFrom(getProject().file(importOrderFile))); - } - - public GroovyExtension.GrEclipseConfig greclipse() { - return new GroovyExtension.GrEclipseConfig(GrEclipseFormatterStep.defaultVersion(), this); - } - - public GroovyExtension.GrEclipseConfig greclipse(String version) { - return new GroovyExtension.GrEclipseConfig(version, this); - } - @Override protected void setupTask(SpotlessTask task) { if (target == null) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index c576eb7da8..bb24a716cd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -159,7 +159,7 @@ public GoogleJavaFormatConfig googleJavaFormat() { /** * Uses the given version of google-java-format to format source code. - * + *

* Limited to published versions. See issue #33 * for a workaround for using snapshot versions. */ @@ -211,6 +211,7 @@ public GoogleJavaFormatConfig reflowLongStrings(boolean reflowLongStrings) { public GoogleJavaFormatConfig reorderImports(boolean reorderImports) { this.reorderImports = reorderImports; + replaceStep(createStep()); return this; } @@ -243,7 +244,7 @@ public PalantirJavaFormatConfig palantirJavaFormat() { /** * Uses the given version of palantir-java-format to format source code. - * + *

* Limited to published versions. See issue #33 * for a workaround for using snapshot versions. */ diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 27d93717f4..21ccb8dd0f 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -17,28 +17,11 @@ import static com.diffplug.spotless.kotlin.KotlinConstants.LICENSE_HEADER_DELIMITER; -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Objects; -import java.util.function.Consumer; - -import javax.annotation.Nullable; import javax.inject.Inject; import org.gradle.api.tasks.SourceSet; -import com.diffplug.common.collect.ImmutableSortedMap; -import com.diffplug.spotless.FileSignature; -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.kotlin.DiktatStep; -import com.diffplug.spotless.kotlin.KtLintStep; -import com.diffplug.spotless.kotlin.KtfmtStep; -import com.diffplug.spotless.kotlin.KtfmtStep.KtfmtFormattingOptions; -import com.diffplug.spotless.kotlin.KtfmtStep.Style; - -public class KotlinExtension extends FormatExtension implements HasBuiltinDelimiterForLicense, JvmLang { +public class KotlinExtension extends BaseKotlinExtension implements HasBuiltinDelimiterForLicense, JvmLang { static final String NAME = "kotlin"; @Inject @@ -56,167 +39,9 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { return licenseHeaderFile(licenseHeaderFile, LICENSE_HEADER_DELIMITER); } - /** Adds the specified version of ktlint. */ - public KotlinFormatExtension ktlint(String version) throws IOException { - Objects.requireNonNull(version); - File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); - FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; - return new KotlinFormatExtension(version, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); - } - - public KotlinFormatExtension ktlint() throws IOException { - return ktlint(KtLintStep.defaultVersion()); - } - - public class KotlinFormatExtension { - - private final String version; - @Nullable - private FileSignature editorConfigPath; - private Map userData; - private Map editorConfigOverride; - - KotlinFormatExtension(String version, @Nullable FileSignature editorConfigPath, Map config, - Map editorConfigOverride) { - this.version = version; - this.editorConfigPath = editorConfigPath; - this.userData = config; - this.editorConfigOverride = editorConfigOverride; - addStep(createStep()); - } - - public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException { - if (editorConfigPath == null) { - this.editorConfigPath = null; - } else { - 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; - } - - public KotlinFormatExtension userData(Map userData) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.userData = ImmutableSortedMap.copyOf(userData); - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension editorConfigOverride(Map editorConfigOverride) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return KtLintStep.create(version, provisioner(), false, editorConfigPath, userData, editorConfigOverride); - } - } - - /** Uses the ktfmt jar to format source code. */ - public KtfmtConfig ktfmt() { - return ktfmt(KtfmtStep.defaultVersion()); - } - - /** - * Uses the given version of ktfmt and applies the dropbox style - * option to format source code. - */ - public KtfmtConfig ktfmt(String version) { - Objects.requireNonNull(version); - return new KtfmtConfig(version); - } - - public class KtfmtConfig { - final String version; - Style style; - KtfmtFormattingOptions options; - - private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); - - KtfmtConfig(String version) { - this.version = Objects.requireNonNull(version); - addStep(createStep()); - } - - private ConfigurableStyle style(Style style) { - this.style = style; - replaceStep(createStep()); - return configurableStyle; - } - - public ConfigurableStyle dropboxStyle() { - return style(Style.DROPBOX); - } - - public ConfigurableStyle googleStyle() { - return style(Style.GOOGLE); - } - - public ConfigurableStyle kotlinlangStyle() { - return style(Style.KOTLINLANG); - } - - public void configure(Consumer optionsConfiguration) { - this.configurableStyle.configure(optionsConfiguration); - } - - private FormatterStep createStep() { - return KtfmtStep.create(version, provisioner(), style, options); - } - - public class ConfigurableStyle { - - public void configure(Consumer optionsConfiguration) { - KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtFormattingOptions(); - optionsConfiguration.accept(ktfmtFormattingOptions); - options = ktfmtFormattingOptions; - replaceStep(createStep()); - } - } - } - - /** Adds the specified version of diktat. */ - public DiktatFormatExtension diktat(String version) { - Objects.requireNonNull(version); - return new DiktatFormatExtension(version); - } - - public DiktatFormatExtension diktat() { - return diktat(DiktatStep.defaultVersionDiktat()); - } - - public class DiktatFormatExtension { - - private final String version; - private FileSignature config; - - DiktatFormatExtension(String version) { - this.version = version; - addStep(createStep()); - } - - public DiktatFormatExtension configFile(Object file) throws IOException { - // Specify the path to the configuration file - if (file == null) { - this.config = null; - } else { - this.config = FileSignature.signAsList(getProject().file(file)); - } - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return DiktatStep.create(version, provisioner(), config); - } + @Override + protected boolean isScript() { + return false; } /** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */ diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index b3351194ba..5cf2847d62 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -15,26 +15,9 @@ */ package com.diffplug.gradle.spotless; -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Objects; -import java.util.function.Consumer; - -import javax.annotation.Nullable; import javax.inject.Inject; -import com.diffplug.common.collect.ImmutableSortedMap; -import com.diffplug.spotless.FileSignature; -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.kotlin.DiktatStep; -import com.diffplug.spotless.kotlin.KtLintStep; -import com.diffplug.spotless.kotlin.KtfmtStep; -import com.diffplug.spotless.kotlin.KtfmtStep.KtfmtFormattingOptions; -import com.diffplug.spotless.kotlin.KtfmtStep.Style; - -public class KotlinGradleExtension extends FormatExtension { +public class KotlinGradleExtension extends BaseKotlinExtension { private static final String GRADLE_KOTLIN_DSL_FILE_EXTENSION = "*.gradle.kts"; static final String NAME = "kotlinGradle"; @@ -44,170 +27,9 @@ public KotlinGradleExtension(SpotlessExtension spotless) { super(spotless); } - /** Adds the specified version of ktlint. */ - public KotlinFormatExtension ktlint(String version) throws IOException { - Objects.requireNonNull(version, "version"); - File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); - FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; - return new KotlinFormatExtension(version, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); - } - - public KotlinFormatExtension ktlint() throws IOException { - return ktlint(KtLintStep.defaultVersion()); - } - - public class KotlinFormatExtension { - - private final String version; - @Nullable - private FileSignature editorConfigPath; - private Map userData; - private Map editorConfigOverride; - - KotlinFormatExtension(String version, FileSignature editorConfigPath, Map config, - Map editorConfigOverride) { - this.version = version; - this.editorConfigPath = editorConfigPath; - this.userData = config; - this.editorConfigOverride = editorConfigOverride; - addStep(createStep()); - } - - public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException { - - if (editorConfigPath == null) { - this.editorConfigPath = null; - } else { - this.editorConfigPath = FileSignature.signAsList(getProject().file(editorConfigPath)); - } - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension userData(Map userData) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.userData = ImmutableSortedMap.copyOf(userData); - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension editorConfigOverride(Map editorConfigOverride) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return KtLintStep.createForScript( - version, - provisioner(), - editorConfigPath, - userData, - editorConfigOverride); - } - } - - /** Uses the ktfmt jar to format source code. */ - public KtfmtConfig ktfmt() { - return ktfmt(KtfmtStep.defaultVersion()); - } - - /** - * Uses the given version of ktfmt to format source - * code. - */ - public KtfmtConfig ktfmt(String version) { - Objects.requireNonNull(version); - return new KtfmtConfig(version); - } - - public class KtfmtConfig { - final String version; - Style style; - KtfmtFormattingOptions options; - - private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); - - KtfmtConfig(String version) { - this.version = Objects.requireNonNull(version); - this.style = Style.DEFAULT; - addStep(createStep()); - } - - private ConfigurableStyle style(Style style) { - this.style = style; - replaceStep(createStep()); - return configurableStyle; - } - - public ConfigurableStyle dropboxStyle() { - return style(Style.DROPBOX); - } - - public ConfigurableStyle googleStyle() { - return style(Style.GOOGLE); - } - - public ConfigurableStyle kotlinlangStyle() { - return style(Style.KOTLINLANG); - } - - public void configure(Consumer optionsConfiguration) { - this.configurableStyle.configure(optionsConfiguration); - } - - private FormatterStep createStep() { - return KtfmtStep.create(version, provisioner(), style, options); - } - - public class ConfigurableStyle { - - public void configure(Consumer optionsConfiguration) { - KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtFormattingOptions(); - optionsConfiguration.accept(ktfmtFormattingOptions); - options = ktfmtFormattingOptions; - replaceStep(createStep()); - } - } - } - - /** Adds the specified version of diktat. */ - public DiktatFormatExtension diktat(String version) { - Objects.requireNonNull(version, "version"); - return new DiktatFormatExtension(version); - } - - public DiktatFormatExtension diktat() { - return diktat(DiktatStep.defaultVersionDiktat()); - } - - public class DiktatFormatExtension { - - private final String version; - private FileSignature config; - - DiktatFormatExtension(String version) { - this.version = version; - addStep(createStep()); - } - - public DiktatFormatExtension configFile(Object file) throws IOException { - // Specify the path to the configuration file - if (file == null) { - this.config = null; - } else { - this.config = FileSignature.signAsList(getProject().file(file)); - } - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return DiktatStep.createForScript(version, provisioner(), config); - } + @Override + protected boolean isScript() { + return true; } @Override diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java index b7ffd0a295..33aded8bdd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java @@ -39,7 +39,7 @@ /** * NOT AN END-USER TASK, DO NOT USE FOR ANYTHING! - * + *

* - When a user asks for a formatter, we need to download the jars for that formatter * - Gradle wants us to resolve all our dependencies in the root project - no new dependencies in subprojects * - So, whenever a SpotlessTask in a subproject gets configured, we call {@link #hookSubprojectTask(SpotlessTask)}, diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java index d0e27d60bf..95f051371b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,8 +86,8 @@ public void visitFile(FileVisitDetails fileVisitDetails) { // in its output directory which ought to have been removed. As // best I can tell, this is a filesytem race which is very hard // to trigger. GitRatchetGradleTest can *sometimes* reproduce it - // but it's very erratic, and that test writes both to gradle cache - // and git cache very quickly. Either of gradle or jgit might be + // but it's very erratic, and that test writes both to Gradle cache + // and git cache very quickly. Either of Gradle or jgit might be // caching something wrong because of the fast repeated writes. if (!Arrays.equals(userFile, formatted)) { // If the on-disk content is equal to the formatted content, diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java index 514945f22d..7ed0837eb5 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java @@ -234,7 +234,7 @@ public boolean isEnforceCheck() { /** * Configures Gradle's {@code check} task to run {@code spotlessCheck} if {@code true}, * but to not do so if {@code false}. - * + *

* {@code true} by default. */ public void setEnforceCheck(boolean enforceCheck) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java index 975ec5576e..bca8ea7c70 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java @@ -73,7 +73,7 @@ public void apply(Project project) { "If you like the idea behind 'ratchetFrom', you should checkout spotless-changelog", "https://github.com/diffplug/spotless-changelog"); if (gradleIsTooOld(project)) { - errorMsg = errorMsg.replace("To migrate:\n", "To migrate:\n- Upgrade gradle to " + SpotlessPlugin.VER_GRADLE_min + " or newer (you're on " + project.getGradle().getGradleVersion() + ")\n"); + errorMsg = errorMsg.replace("To migrate:\n", "To migrate:\n- Upgrade Gradle to " + SpotlessPlugin.VER_GRADLE_min + " or newer (you're on " + project.getGradle().getGradleVersion() + ")\n"); } throw new GradleException(errorMsg); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java index ab584fa7b6..04951a4577 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java @@ -48,7 +48,7 @@ public abstract class SpotlessTaskImpl extends SpotlessTask { void init(Provider service) { taskServiceProvider = service; - usesService(service); + SpotlessTaskService.usesServiceTolerateTestFailure(this, service); getTaskService().set(service); getProjectDir().set(getProject().getProjectDir()); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java index 67de4b946c..b5a1300ead 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.gradle.api.file.DirectoryProperty; import org.gradle.api.model.ObjectFactory; import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; import org.gradle.api.services.BuildService; import org.gradle.api.services.BuildServiceParameters; import org.gradle.api.tasks.Internal; @@ -91,6 +92,16 @@ public void close() throws Exception { static String INDEPENDENT_HELPER = "Helper"; + static void usesServiceTolerateTestFailure(DefaultTask task, Provider serviceProvider) { + try { + task.usesService(serviceProvider); + } catch (ClassCastException e) { + // this happens only in our test mocking, e.g. DiffMessageFormatterTest + // https://github.com/diffplug/spotless/pull/1570/commits/c45e1f2322c78f272689feb35753bbc633422bfa + // it's fine to swallow these exceptions + } + } + static abstract class ClientTask extends DefaultTask { @Internal abstract Property getSpotlessOutDirectory(); @@ -105,7 +116,7 @@ static abstract class ClientTask extends DefaultTask { protected abstract ObjectFactory getConfigCacheWorkaround(); void init(SpotlessTaskImpl impl) { - usesService(impl.getTaskServiceProvider()); + usesServiceTolerateTestFailure(this, impl.getTaskServiceProvider()); getSpotlessOutDirectory().set(impl.getOutputDirectory()); getTaskService().set(impl.getTaskService()); getProjectDir().set(impl.getProjectDir()); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java index 42d9f4314a..b2ee012091 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java @@ -46,6 +46,32 @@ void integration() throws IOException { checkRunsThenUpToDate(); } + @Test + void integrationWithReorderImports() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "", + "spotless {", + " java {", + " target file('test.java')", + " googleJavaFormat('1.12.0').aosp().reorderImports(true)", + " }", + "}"); + + setFile("test.java").toResource("java/googlejavaformat/JavaWithReorderImportsUnformatted.test"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("test.java").sameAsResource("java/googlejavaformat/JavaWithReorderImportsEnabledFormatted.test"); + + checkRunsThenUpToDate(); + replace("build.gradle", + "googleJavaFormat('1.12.0')", + "googleJavaFormat()"); + checkRunsThenUpToDate(); + } + @Test void integrationWithSkipJavadocFormatting() throws IOException { setFile("build.gradle").toLines( diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java index 61d191bab1..ade5cf3d1d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java @@ -94,12 +94,12 @@ public static Provider providerOf(T value) { /** * Each test gets its own temp folder, and we create a gradle * build there and run it. - * + *

* Because those test folders don't have a .gitattributes file, * git (on windows) will default to \r\n. So now if you read a * test file from the spotless test resources, and compare it * to a build result, the line endings won't match. - * + *

* By sticking this .gitattributes file into the test directory, * we ensure that the default Spotless line endings policy of * GIT_ATTRIBUTES will use \n, so that tests match the test diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java index c38df40d54..7f87d8793c 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java @@ -88,6 +88,27 @@ void excludeJavaWithCustomTarget() throws IOException { assertThat(error).hasMessageContaining("'excludeJava' is not supported"); } + @Test + void removeSemicolons() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "apply plugin: 'groovy'", + "", + "spotless {", + " groovy {", + " removeSemicolons()", + " }", + "}"); + + String withSemicolons = getTestResource("groovy/removeSemicolons/GroovyCodeWithSemicolons.test"); + String withoutSemicolons = getTestResource("groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test"); + setFile("src/main/groovy/test.groovy").toContent(withSemicolons); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/groovy/test.groovy").hasContent(withoutSemicolons); + } + @Test void groovyPluginMissingCheck() throws IOException { setFile("build.gradle").toLines( diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyGradleExtensionTest.java index 7f4d593a9c..e94d269644 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyGradleExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,24 +17,20 @@ import java.io.IOException; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import com.diffplug.common.base.StringPrinter; -class GroovyGradleExtensionTest extends GradleIntegrationHarness { +/** + * We test GroovyGradleExtension only behaviors here. + */ +class GroovyGradleExtensionTest extends GroovyExtensionTest { private static final String HEADER = "//My tests header"; - @Test - void defaultTarget() throws IOException { - testTarget(true); - } - - @Test - void customTarget() throws IOException { - testTarget(false); - } - - private void testTarget(boolean useDefaultTarget) throws IOException { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testTarget(boolean useDefaultTarget) throws IOException { String target = useDefaultTarget ? "" : "target 'other.gradle'"; String buildContent = StringPrinter.buildStringFromLines( "plugins {", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 1c23728244..bd1175b992 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -30,7 +30,7 @@ class KotlinExtensionTest extends GradleIntegrationHarness { void integrationDiktat() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.4.30'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -48,7 +48,7 @@ void integrationDiktat() throws IOException { void integrationKtfmt_dropboxStyle_0_19() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -66,7 +66,7 @@ void integrationKtfmt_dropboxStyle_0_19() throws IOException { void withExperimentalEditorConfigOverride() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -90,7 +90,7 @@ void testWithInvalidEditorConfigFile() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -105,11 +105,71 @@ void testWithInvalidEditorConfigFile() throws IOException { assertThat(buildOutput).contains(invalidPath); } + @Test + void testReadCodeStyleFromEditorConfigFile() throws IOException { + setFile(".editorconfig").toResource("kotlin/ktlint/ktlint_official/.editorconfig"); + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint()", + " }", + "}"); + checkKtlintOfficialStyle(); + } + + @Test + void testSetEditorConfigCanOverrideEditorConfigFile() throws IOException { + setFile(".editorconfig").toResource("kotlin/ktlint/intellij_idea/.editorconfig"); + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint().editorConfigOverride([", + " ktlint_code_style: \"ktlint_official\",", + " ])", + " }", + "}"); + checkKtlintOfficialStyle(); + } + + @Test + void withCustomRuleSetApply() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint(\"1.0.1\")", + " .customRuleSets([", + " \"io.nlopez.compose.rules:ktlint:0.3.3\"", + " ])", + " .editorConfigOverride([", + " ktlint_function_naming_ignore_when_annotated_with: \"Composable\",", + " ])", + " }", + "}"); + setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/listScreen.dirty"); + String buildOutput = gradleRunner().withArguments("spotlessCheck").buildAndFail().getOutput(); + assertThat(buildOutput).contains("Composable functions that return Unit should start with an uppercase letter."); + } + @Test void testWithHeader() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -128,7 +188,7 @@ void testWithHeader() throws IOException { void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -144,4 +204,11 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); } + + private void checkKtlintOfficialStyle() throws IOException { + String path = "src/main/kotlin/Main.kt"; + setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean"); + } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 7dade5f2ff..c607c36912 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -15,42 +15,28 @@ */ package com.diffplug.gradle.spotless; -import static org.assertj.core.api.Assertions.assertThat; - import java.io.IOException; -import org.gradle.testkit.runner.BuildResult; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -class KotlinGradleExtensionTest extends GradleIntegrationHarness { - @Test - void integration_default_diktat() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.4.30'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " diktat()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/diktat/basic.dirty"); - BuildResult result = gradleRunner().withArguments("spotlessApply").buildAndFail(); - assertThat(result.getOutput()).contains("[AVOID_NESTED_FUNCTIONS] try to avoid using nested functions"); - } +/** + * We test KotlinGradleExtension only behaviors here. + */ +class KotlinGradleExtensionTest extends KotlinExtensionTest { - @Test - void withExperimentalEditorConfigOverride() throws IOException { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testTarget(boolean useDefaultTarget) throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", "spotless {", " kotlinGradle {", + " " + (useDefaultTarget ? "" : "target \"*.kts\""), " ktlint().editorConfigOverride([", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", @@ -59,25 +45,14 @@ void withExperimentalEditorConfigOverride() throws IOException { " }", "}"); setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + setFile("configuration.kts").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); - } - - @Test - void integration_ktfmt_with_dropbox_style() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktfmt().dropboxStyle()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktfmt/dropboxstyle.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktfmt/dropboxstyle.clean"); + if (useDefaultTarget) { + assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + assertFile("configuration.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + } else { + assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + assertFile("configuration.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + } } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java index acb57f3763..a427d6f2ec 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,7 +54,7 @@ void redirectPluginOldGradle() throws IOException { " > We have moved from 'com.diffplug.gradle.spotless'", " to 'com.diffplug.spotless'", " To migrate:", - " - Upgrade gradle to 6.1.1 or newer (you're on 5.0)", + " - Upgrade Gradle to 6.1.1 or newer (you're on 5.0)", " - Test your build with: id 'com.diffplug.gradle.spotless' version '4.5.1'")); } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a6c98e2c96..78fb6f84ca 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,17 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* CompileSourceRoots and TestCompileSourceRoots are now respected as default includes. These properties are commonly set when adding extra source directories. ([#1846](https://github.com/diffplug/spotless/issues/1846)) +* Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896) +### Fixed +* Fix crash when build dir is a softlink to another directory. ([#1859](https://github.com/diffplug/spotless/pull/1859)) +* Fix Eclipse JDT on some settings files. ([#1864](https://github.com/diffplug/spotless/pull/1864) fixes [#1638](https://github.com/diffplug/spotless/issues/1638)) +### Changes +* Bump default `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855)) +* Add a Step to remove semicolons from Groovy files. ([#1881](https://github.com/diffplug/spotless/pull/1881)) + +## [2.40.0] - 2023-09-28 +### Added * Add `-DspotlessIdeHook` that provides the ability to apply Spotless exclusively to a specified file. It accepts the absolute path of the file. ([#1782](https://github.com/diffplug/spotless/pull/1782)) * BETA, subject to change until we have proven compatibility with some IDE plugins. * Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793)) @@ -133,7 +144,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Respect `sourceDirectory` and `testSourceDirectory` POM configurations for Java formatters ([#1553](https://github.com/diffplug/spotless/pull/1553)) * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) -* Any commit of the Spotless maven plugin now available via JitPack ([#1547](https://github.com/diffplug/spotless/pull/1547)) +* Any commit of the Spotless Maven plugin now available via JitPack ([#1547](https://github.com/diffplug/spotless/pull/1547)) ## [2.31.0] - 2023-01-26 ### Added @@ -219,7 +230,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.25.0] - 2022-08-23 ### Added -* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) +* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the Maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) ### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) * Bump default `scalafmt` to latest `3.0.8` -> `3.5.9` (removed support for pre-`3.0.0`) ([#1283](https://github.com/diffplug/spotless/pull/1283)) @@ -453,7 +464,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changed * Update ktfmt from 0.21 to 0.24 ### Fixed -* The `` field in the maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) +* The `` field in the Maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) ## [2.10.3] - 2021-04-21 ### Fixed @@ -587,7 +598,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `prettier` will now autodetect the parser (and formatter) to use based on the filename, unless you override this using `config` or `configFile` with the option `parser` or `filepath` ([#620](https://github.com/diffplug/spotless/pull/620)). * Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ### Removed -* **BREAKING** the default includes for `` and `` were removed, and will now generate an error if an `` is not specified. There is no well-established convention for these languages in the maven ecosystem, and the performance of the default includes is far worse than a user-provided one. If you dislike this change, please complain in [#634](https://github.com/diffplug/spotless/pull/634), it would not be a breaking change to bring the defaults back. +* **BREAKING** the default includes for `` and `` were removed, and will now generate an error if an `` is not specified. There is no well-established convention for these languages in the Maven ecosystem, and the performance of the default includes is far worse than a user-provided one. If you dislike this change, please complain in [#634](https://github.com/diffplug/spotless/pull/634), it would not be a breaking change to bring the defaults back. * **BREAKING** inside the `` block, `` has been renamed to `` to avoid any confusion with the java `` ([#636](https://github.com/diffplug/spotless/pull/636)). * **BREAKING** the long-deprecated `` and `` formats have been removed, in favor of the long-available [``](https://github.com/diffplug/spotless/tree/main/plugin-maven#eclipse-wtp) step which is available in every generic format ([#630](https://github.com/diffplug/spotless/pull/630)). * This probably doesn't affect you, but if it does, you just need to change `...` into `XML...` @@ -635,7 +646,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Enable IntelliJ-compatible token `$today.year` for specifying the year in license header files. ([#542](https://github.com/diffplug/spotless/pull/542)) ### Fixed -* Fix scala and kotlin maven config documentation. +* Fix scala and kotlin Maven config documentation. * Eclipse-WTP formatter (web tools platform, not java) could encounter errors in parallel multiproject builds [#492](https://github.com/diffplug/spotless/issues/492). Fixed for Eclipse-WTP formatter Eclipse version 4.13.0 (default version). ## [1.27.0] - 2020-01-01 @@ -683,11 +694,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Updated default eclipse-jdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * Updated default eclipse-cdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * **KNOWN BUG - accidentally published CDT 9.7 rather than 9.8 fixed in 1.26.0** -* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) +* Added new Maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) ## [1.23.1] - 2019-06-17 * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) -* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) +* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because Gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) ## [1.23.0] - 2019-04-24 * Updated default ktlint from 0.21.0 to 0.32.0, and Maven coords to com.pinterest ([#394](https://github.com/diffplug/spotless/pull/394)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 919a05dfbb..857597beb2 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -2,14 +2,14 @@ -[![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.39.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.39.0/index.html) +[![MavenCentral](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) +[![Changelog](https://img.shields.io/badge/changelog-2.40.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.40.0/index.html) - *.md + .gitattributes .gitignore @@ -331,14 +331,16 @@ These mechanisms already exist for the Gradle plugin. src/test/groovy/**/*.groovy - + java|javax,org,com,com.diffplug,,\#com.diffplug,\# + + + - - + /* (C)$YEAR */ @@ -416,6 +418,9 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. true true + + io.nlopez.compose.rules:ktlint:0.3.3 + ``` diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index dcada0b9c9..f2f85f0383 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -56,6 +56,7 @@ dependencies { testImplementation "org.eclipse.aether:aether-api:${VER_ECLIPSE_AETHER}" testImplementation "org.codehaus.plexus:plexus-resources:${VER_PLEXUS_RESOURCES}" testImplementation "org.apache.maven:maven-core:${VER_MAVEN_API}" + testRuntimeOnly "org.junit.platform:junit-platform-launcher" } apply from: rootProject.file('gradle/special-tests.gradle') diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java index 35b91f3677..db4b35dfd6 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java @@ -52,4 +52,8 @@ public void addGreclipse(GrEclipse greclipse) { public void addImportOrder(ImportOrder importOrder) { addStepFactory(importOrder); } + + public void addRemoveSemicolons(RemoveSemicolons removeSemicolons) { + addStepFactory(removeSemicolons); + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/RemoveSemicolons.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/RemoveSemicolons.java new file mode 100644 index 0000000000..a96a078692 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/RemoveSemicolons.java @@ -0,0 +1,29 @@ +/* + * Copyright 2016-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.groovy; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.groovy.RemoveSemicolonsStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class RemoveSemicolons implements FormatterStepFactory { + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig config) { + return RemoveSemicolonsStep.create(); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/FileIndex.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/FileIndex.java index 8330319cfb..c719419923 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/FileIndex.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/FileIndex.java @@ -26,6 +26,7 @@ import java.io.PrintWriter; import java.io.UncheckedIOException; import java.nio.file.Files; +import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Instant; @@ -144,7 +145,14 @@ private void ensureParentDirExists() { throw new IllegalStateException("Index file does not have a parent dir: " + indexFile); } try { - Files.createDirectories(parentDir); + if (Files.exists(parentDir, LinkOption.NOFOLLOW_LINKS)) { + Path realPath = parentDir.toRealPath(); + if (!Files.exists(realPath)) { + Files.createDirectories(realPath); + } + } else { + Files.createDirectories(parentDir); + } } catch (IOException e) { throw new UncheckedIOException("Unable to create parent directory for the index file: " + indexFile, e); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index b0692446b7..e0ff14b51e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -20,8 +20,9 @@ import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; import java.util.Set; -import java.util.stream.Stream; import org.apache.maven.model.Build; import org.apache.maven.project.MavenProject; @@ -44,7 +45,15 @@ public class Java extends FormatterFactory { public Set defaultIncludes(MavenProject project) { Path projectDir = project.getBasedir().toPath(); Build build = project.getBuild(); - return Stream.of(build.getSourceDirectory(), build.getTestSourceDirectory()) + + List includes = new ArrayList<>(); + includes.add(build.getSourceDirectory()); + includes.add(build.getTestSourceDirectory()); + includes.addAll(project.getCompileSourceRoots()); + includes.addAll(project.getTestCompileSourceRoots()); + + return includes.stream() + .distinct() .map(Paths::get) .map(projectDir::relativize) .map(Java::fileMask) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index fd59d8ba9d..2459a52828 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -17,6 +17,7 @@ import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.maven.plugins.annotations.Parameter; @@ -29,13 +30,14 @@ import com.diffplug.spotless.maven.FormatterStepFactory; public class Ktlint implements FormatterStepFactory { - @Parameter private String version; @Parameter private String editorConfigPath; @Parameter private Map editorConfigOverride; + @Parameter + private List customRuleSets; @Override public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { @@ -47,7 +49,14 @@ public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { if (editorConfigOverride == null) { editorConfigOverride = new HashMap<>(); } - - return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, configPath, Collections.emptyMap(), editorConfigOverride); + if (customRuleSets == null) { + customRuleSets = Collections.emptyList(); + } + return KtLintStep.create( + ktlintVersion, + stepConfig.getProvisioner(), + configPath, + editorConfigOverride, + customRuleSets); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 5fd59752e6..4710874e9f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -70,12 +70,12 @@ public class MavenIntegrationHarness extends ResourceHarness { /** * Each test gets its own temp folder, and we create a maven * build there and run it. - * + *

* Because those test folders don't have a .gitattributes file, * git on windows will default to \r\n. So now if you read a * test file from the spotless test resources, and compare it * to a build result, the line endings won't match. - * + *

* By sticking this .gitattributes file into the test directory, * we ensure that the default Spotless line endings policy of * GIT_ATTRIBUTES will use \n, so that tests match the test diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java index d878b18c5f..c8d845f8a2 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java @@ -28,8 +28,8 @@ import com.diffplug.spotless.ProcessRunner; /** - * Harness for running a maven build, same idea as the - * GradleRunner from the gradle testkit. + * Harness for running a Maven build, same idea as the + * GradleRunner from the Gradle testkit. */ public class MavenRunner { public static MavenRunner create() { @@ -67,7 +67,7 @@ public MavenRunner withRemoteDebug(int port) { private ProcessRunner.Result run() throws IOException, InterruptedException { Objects.requireNonNull(projectDir, "Need to call withProjectDir() first"); Objects.requireNonNull(args, "Need to call withArguments() first"); - // run maven with the given args in the given directory + // run Maven with the given args in the given directory String argsString = "-e " + String.join(" ", Arrays.asList(args)); return runner.shellWinUnix(projectDir, environment, "mvnw " + argsString, "./mvnw " + argsString); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java new file mode 100644 index 0000000000..fc78c87a27 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.groovy; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +class RemoveSemicolonsTest extends MavenIntegrationHarness { + + @Test + void testRemoveSemicolonsString() throws Exception { + writePomWithGroovySteps(""); + runTest("Hello World;", "Hello World"); + } + + @Test + void testNotRemoveSemicolonsString() throws Exception { + writePomWithGroovySteps(""); + runTest("Hello;World", "Hello;World"); + } + + @Test + void testRemoveSemicolons() throws Exception { + writePomWithGroovySteps(""); + + String path = "src/main/groovy/test.groovy"; + setFile(path).toResource("groovy/removeSemicolons/GroovyCodeWithSemicolons.test"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test"); + } + + private void runTest(String sourceContent, String targetContent) throws Exception { + String path = "src/main/groovy/test.groovy"; + setFile(path).toContent(sourceContent); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).hasContent(targetContent); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java index 76b2c40fd3..40d8edfed2 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java @@ -52,6 +52,18 @@ void specificVersionReflowLongStrings() throws Exception { runTest("java/googlejavaformat/JavaCodeFormattedReflowLongStrings.test"); } + @Test + void specificVersionReorderImports() throws Exception { + writePomWithJavaSteps( + "", + " 1.12.0", + " ", + " true", + ""); + + runTest("java/googlejavaformat/JavaWithReorderImportsEnabledFormatted.test", "java/googlejavaformat/JavaWithReorderImportsUnformatted.test"); + } + @Test void specificVersionSkipJavadocFormatting() throws Exception { writePomWithJavaSteps( @@ -64,8 +76,12 @@ void specificVersionSkipJavadocFormatting() throws Exception { } private void runTest(String targetResource) throws Exception { + runTest(targetResource, "java/googlejavaformat/JavaCodeUnformatted.test"); + } + + private void runTest(String targetResource, String sourceResource) throws Exception { String path = "src/main/java/test.java"; - setFile(path).toResource("java/googlejavaformat/JavaCodeUnformatted.test"); + setFile(path).toResource(sourceResource); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource(targetResource); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index 060e0de84f..fe5b0e1b57 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -15,8 +15,11 @@ */ package com.diffplug.spotless.maven.kotlin; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.maven.MavenIntegrationHarness; class KtlintTest extends MavenIntegrationHarness { @@ -44,4 +47,44 @@ void testKtlintEditorConfigOverride() throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); } + + @Test + void testReadCodeStyleFromEditorConfigFile() throws Exception { + setFile(".editorconfig").toResource("kotlin/ktlint/ktlint_official/.editorconfig"); + writePomWithKotlinSteps(""); + checkKtlintOfficialStyle(); + } + + @Test + void testSetEditorConfigCanOverrideEditorConfigFile() throws Exception { + setFile(".editorconfig").toResource("kotlin/ktlint/intellij_idea/.editorconfig"); + writePomWithKotlinSteps("\n" + + " \n" + + " ktlint_official\n" + + " \n" + + ""); + checkKtlintOfficialStyle(); + } + + @Test + void testWithCustomRuleSetApply() throws Exception { + writePomWithKotlinSteps("\n" + + " \n" + + " io.nlopez.compose.rules:ktlint:0.3.3\n" + + " \n" + + " \n" + + " Composable\n" + + " \n" + + ""); + setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/listScreen.dirty"); + ProcessRunner.Result result = mavenRunner().withArguments("spotless:check").runHasError(); + assertTrue(result.toString().contains("Composable functions that return Unit should start with an uppercase letter.")); + } + + private void checkKtlintOfficialStyle() throws Exception { + String path = "src/main/kotlin/Main.kt"; + setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean"); + } } diff --git a/settings.gradle b/settings.gradle index f09ed33f57..e7e5a6d4ea 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,24 +6,24 @@ pluginManagement { } plugins { - id 'com.diffplug.spotless' version '6.21.0' apply false + id 'com.diffplug.spotless' version '6.22.0' apply false // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.2.1' apply false // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.1.3' apply false + id 'com.github.spotbugs' version '5.2.3' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md id 'com.diffplug.spotless-changelog' version '3.0.2' apply false // https://github.com/diffplug/goomph/blob/main/CHANGES.md // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 id 'com.diffplug.p2.asmaven' version '3.27.0' apply false // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md - id 'com.adarshr.test-logger' version '3.2.0' apply false + id 'com.adarshr.test-logger' version '4.0.0' apply false // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise - id 'com.gradle.enterprise' version '3.15' + id 'com.gradle.enterprise' version '3.15.1' // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md id 'dev.equo.ide' version '1.7.3' apply false } diff --git a/testlib/build.gradle b/testlib/build.gradle index 12b3bcd135..a4c83cfdf4 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -13,6 +13,7 @@ dependencies { api "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" api "org.assertj:assertj-core:${VER_ASSERTJ}" api "org.mockito:mockito-core:$VER_MOCKITO" + runtimeOnly "org.junit.platform:junit-platform-launcher" implementation "com.diffplug.durian:durian-io:${VER_DURIAN}" implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}" diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java index e06640ccfd..7c7b7b67f7 100644 --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java @@ -52,10 +52,10 @@ public static Project gradleProject(File dir) { /** * Creates a Provisioner for the given repositories. - * + *

* The first time a project is created, there are ~7 seconds of configuration * which will go away for all subsequent runs. - * + *

* Every call to resolve will take about 1 second, even when all artifacts are resolved. */ private static Provisioner createWithRepositories(Consumer repoConfig) { diff --git a/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolons.test b/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolons.test new file mode 100644 index 0000000000..b66af4e820 --- /dev/null +++ b/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolons.test @@ -0,0 +1,10 @@ +import mylib.Unused; +import mylib.UsedB; +import mylib.UsedA; + +public class SomeClass { +System.out.println("hello"); +UsedB.someMethod(); +UsedA.someMethod(); +} +} \ No newline at end of file diff --git a/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test b/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test new file mode 100644 index 0000000000..434addfa68 --- /dev/null +++ b/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test @@ -0,0 +1,10 @@ +import mylib.Unused +import mylib.UsedB +import mylib.UsedA + +public class SomeClass { +System.out.println("hello") +UsedB.someMethod() +UsedA.someMethod() +} +} \ No newline at end of file diff --git a/testlib/src/main/resources/java/eclipse/AbstractType.clean b/testlib/src/main/resources/java/eclipse/AbstractType.clean index 475b1186fd..314dbac1ac 100644 --- a/testlib/src/main/resources/java/eclipse/AbstractType.clean +++ b/testlib/src/main/resources/java/eclipse/AbstractType.clean @@ -2,37 +2,40 @@ package test; public abstract class AbstractType { - private String _typeName; - - AbstractType(String typeName) { - _typeName = typeName; - } - - private String _type() { - String name = getClass().getSimpleName(); - return name.endsWith("Type") ? name.substring(0, getClass().getSimpleName().length() - 4) : name; - } - - AbstractType argument() { - throw new UnsupportedOperationException(getClass().getSimpleName()); - } - - @Override - public boolean equals(Object another) { - if (this == another) { - return true; - } - return another instanceof AbstractType t && _typeName.equals(t._typeName); - } - - @Override - public int hashCode() { - return _typeName.hashCode(); - } - - @Override - public String toString() { - return getClass().getSimpleName() + "(typeName)"; - } + private String _typeName; + + AbstractType(String typeName) { + _typeName = typeName; + } + + private String _type() { + String name = getClass().getSimpleName(); + return name.endsWith("Type") + ? name.substring(0, getClass().getSimpleName().length() - 4) + : name; + } + + AbstractType argument() { + throw new UnsupportedOperationException(getClass().getSimpleName()); + } + + @Override + public boolean equals(Object another) { + if (this == another) { + return true; + } + return another instanceof AbstractType t + && _typeName.equals(t._typeName); + } + + @Override + public int hashCode() { + return _typeName.hashCode(); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "(typeName)"; + } } diff --git a/testlib/src/main/resources/java/googlejavaformat/JavaWithReorderImportsDisabledFormatted.test b/testlib/src/main/resources/java/googlejavaformat/JavaWithReorderImportsDisabledFormatted.test new file mode 100644 index 0000000000..5e62d24108 --- /dev/null +++ b/testlib/src/main/resources/java/googlejavaformat/JavaWithReorderImportsDisabledFormatted.test @@ -0,0 +1,11 @@ +import java.nio.file.Paths; +import my.UsedB; +import org.xml.sax.InputSource; + +public class Java { + public static void main(String[] args) { + UsedB b = new UsedB(); + InputSource inputSource = new InputSource(); + Paths.get("dir"); + } +} diff --git a/testlib/src/main/resources/java/googlejavaformat/JavaWithReorderImportsEnabledFormatted.test b/testlib/src/main/resources/java/googlejavaformat/JavaWithReorderImportsEnabledFormatted.test new file mode 100644 index 0000000000..d0d4951601 --- /dev/null +++ b/testlib/src/main/resources/java/googlejavaformat/JavaWithReorderImportsEnabledFormatted.test @@ -0,0 +1,13 @@ +import my.UsedB; + +import org.xml.sax.InputSource; + +import java.nio.file.Paths; + +public class Java { + public static void main(String[] args) { + UsedB b = new UsedB(); + InputSource inputSource = new InputSource(); + Paths.get("dir"); + } +} diff --git a/testlib/src/main/resources/java/googlejavaformat/JavaWithReorderImportsUnformatted.test b/testlib/src/main/resources/java/googlejavaformat/JavaWithReorderImportsUnformatted.test new file mode 100644 index 0000000000..bfdbe83d88 --- /dev/null +++ b/testlib/src/main/resources/java/googlejavaformat/JavaWithReorderImportsUnformatted.test @@ -0,0 +1,11 @@ +import my.UsedB; +import java.nio.file.Paths; +import org.xml.sax.InputSource; + +public class Java { + public static void main(String[] args) { + UsedB b = new UsedB(); + InputSource inputSource = new InputSource(); + Paths.get("dir"); + } +} \ No newline at end of file diff --git a/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean new file mode 100644 index 0000000000..2466bb93fc --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/experimentalEditorConfigOverride.ktlintOfficial.clean @@ -0,0 +1,6 @@ +fun main() { + val list = + listOf( + "hello", + ) +} diff --git a/testlib/src/main/resources/kotlin/ktlint/intellij_idea/.editorconfig b/testlib/src/main/resources/kotlin/ktlint/intellij_idea/.editorconfig new file mode 100644 index 0000000000..9efc62a854 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/intellij_idea/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*.{kt,kts}] +ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = true +ktlint_code_style = intellij_idea diff --git a/testlib/src/main/resources/kotlin/ktlint/ktlint_official/.editorconfig b/testlib/src/main/resources/kotlin/ktlint/ktlint_official/.editorconfig new file mode 100644 index 0000000000..93a01f2e59 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/ktlint_official/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*.{kt,kts}] +ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = true +ktlint_code_style = ktlint_official diff --git a/testlib/src/main/resources/kotlin/ktlint/listScreen.dirty b/testlib/src/main/resources/kotlin/ktlint/listScreen.dirty new file mode 100644 index 0000000000..14c06d6d43 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/listScreen.dirty @@ -0,0 +1,6 @@ +import androidx.compose.runtime.Composable + +@Composable +fun listScreen() { + val list: List = mutableListOf() +} diff --git a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java index df08c483df..f8766d7c6f 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java @@ -119,6 +119,19 @@ void behaviorWithCustomGroupArtifact() throws Exception { .testResource("java/googlejavaformat/JavaCodeWithPackageUnformatted.test", "java/googlejavaformat/JavaCodeWithPackageFormatted.test"); } + @Test + void behaviorWithReorderImports() throws Exception { + FormatterStep enabled = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), GoogleJavaFormatStep.defaultVersion(), "AOSP", TestProvisioner.mavenCentral(), GoogleJavaFormatStep.defaultReflowLongStrings(), true); + FormatterStep disabled = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), GoogleJavaFormatStep.defaultVersion(), "AOSP", TestProvisioner.mavenCentral(), GoogleJavaFormatStep.defaultReflowLongStrings(), false); + String unformatted = "java/googlejavaformat/JavaWithReorderImportsUnformatted.test"; + try (StepHarness step = StepHarness.forStep(enabled)) { + step.testResource(unformatted, "java/googlejavaformat/JavaWithReorderImportsEnabledFormatted.test"); + } + try (StepHarness step = StepHarness.forStep(disabled)) { + step.testResource(unformatted, "java/googlejavaformat/JavaWithReorderImportsDisabledFormatted.test"); + } + } + @Test void equality() throws Exception { new SerializableEqualityTester() {