diff --git a/.editorconfig b/.editorconfig index fc0fba97..16a2af5c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,4 +8,6 @@ trim_trailing_whitespace = true insert_final_newline = true [*.{kt,kts}] -kotlin_imports_layout = ascii +ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = true +ij_kotlin_imports_layout = * diff --git a/build.gradle b/build.gradle index 159eecb3..aaf8f409 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { dependencies { classpath deps.kotlinGradlePlugin classpath "org.jetbrains.kotlin:kotlin-serialization:${versions.kotlin}" - classpath 'com.diffplug.spotless:spotless-plugin-gradle:5.1.0' + classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.8.0' classpath 'com.vanniktech:gradle-maven-publish-plugin:0.14.2' classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.7.0' classpath 'de.undercouch:gradle-download-task:5.1.0' @@ -132,10 +132,13 @@ spotless { target('**/*.kt') licenseHeaderFile(rootProject.file('gradle/license-header.txt')) // Spotless doesn't read .editorconfig yet: https://github.com/diffplug/spotless/issues/142 - ktlint('0.41.0').userData([ - 'insert_final_newline': 'true', + ktlint('0.46.1').editorConfigOverride([ + 'disabled_rules': 'filename', 'end_of_line': 'lf', 'indent_size': '2', + 'ij_kotlin_allow_trailing_comma': 'true', + 'ij_kotlin_allow_trailing_comma_on_call_site': 'true', + 'ij_kotlin_imports_layout': '*', ]) } } diff --git a/src/main/kotlin/app/cash/licensee/dependencyGraph.kt b/src/main/kotlin/app/cash/licensee/dependencyGraph.kt index ea75f41f..c0f99787 100644 --- a/src/main/kotlin/app/cash/licensee/dependencyGraph.kt +++ b/src/main/kotlin/app/cash/licensee/dependencyGraph.kt @@ -15,6 +15,9 @@ */ package app.cash.licensee +import java.io.File +import java.io.Serializable +import javax.xml.parsers.DocumentBuilderFactory import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.LenientConfiguration @@ -28,9 +31,6 @@ import org.gradle.api.attributes.Attribute import org.gradle.api.logging.Logger import org.w3c.dom.Node import org.w3c.dom.NodeList -import java.io.File -import java.io.Serializable -import javax.xml.parsers.DocumentBuilderFactory internal data class DependencyConfig( val ignoredGroupIds: Map, @@ -139,7 +139,7 @@ private fun loadDependencyCoordinates( if (ignoreSuffix != null) { append(ignoreSuffix) } - } + }, ) } @@ -149,7 +149,14 @@ private fun loadDependencyCoordinates( val selected = dependency.selected if (seen.add(selected.id)) { loadDependencyCoordinates( - logger, selected, config, unusedGroupIds, unusedCoordinates, destination, seen, depth + 1 + logger, + selected, + config, + unusedGroupIds, + unusedCoordinates, + destination, + seen, + depth + 1, ) } } @@ -299,7 +306,7 @@ internal fun loadPomInfo( logger = logger, id = DependencyCoordinates(group, artifact, version), variants = variants, - depth = depth + 1 + depth = depth + 1, ) if (licenses.isEmpty()) { licenses += parentPomInfo.licenses diff --git a/src/main/kotlin/app/cash/licensee/licenseValidation.kt b/src/main/kotlin/app/cash/licensee/licenseValidation.kt index 908dbea5..732469de 100644 --- a/src/main/kotlin/app/cash/licensee/licenseValidation.kt +++ b/src/main/kotlin/app/cash/licensee/licenseValidation.kt @@ -54,7 +54,7 @@ internal fun validateArtifacts( if (spdxLicense.identifier in validationConfig.allowedIdentifiers) { unusedAllowedIdentifiers -= spdxLicense.identifier artifactResults += ValidationResult.Info( - "SPDX identifier '${spdxLicense.identifier}' allowed" + "SPDX identifier '${spdxLicense.identifier}' allowed", ) validated = true break @@ -62,7 +62,7 @@ internal fun validateArtifacts( if (spdxLicense.url in validationConfig.allowedUrls) { unusedAllowedUrls -= spdxLicense.url artifactResults += ValidationResult.Warning( - "License URL '${spdxLicense.url}' was allowed but could use SPDX identifier '${spdxLicense.identifier}'" + "License URL '${spdxLicense.url}' was allowed but could use SPDX identifier '${spdxLicense.identifier}'", ) validated = true break @@ -83,7 +83,7 @@ internal fun validateArtifacts( if (!validated) { for (spdxLicense in artifact.spdxLicenses) { artifactResults += ValidationResult.Error( - "SPDX identifier '${spdxLicense.identifier}' is NOT allowed" + "SPDX identifier '${spdxLicense.identifier}' is NOT allowed", ) } for (unknownLicense in artifact.unknownLicenses) { @@ -92,7 +92,7 @@ internal fun validateArtifacts( "Unknown license name '${unknownLicense.name}' with no URL is NOT allowed" } else { "Unknown license URL '${unknownLicense.url}' is NOT allowed" - } + }, ) } if (artifact.spdxLicenses.isEmpty() && artifact.unknownLicenses.isEmpty()) { @@ -113,7 +113,7 @@ internal fun validateArtifacts( append(" because ") append(reason) } - } + }, ) // Downgrade errors to info. @@ -127,7 +127,7 @@ internal fun validateArtifacts( .firstOrNull { it.group == artifact.groupId && it.artifact == artifact.artifactId } if (candidate != null) { artifactResults += ValidationResult.Warning( - "Coordinates match an allowed dependency but version does not match (${candidate.version} != ${artifact.version})" + "Coordinates match an allowed dependency but version does not match (${candidate.version} != ${artifact.version})", ) } } diff --git a/src/main/kotlin/app/cash/licensee/licenses.kt b/src/main/kotlin/app/cash/licensee/licenses.kt index 46fab1fc..0f059426 100644 --- a/src/main/kotlin/app/cash/licensee/licenses.kt +++ b/src/main/kotlin/app/cash/licensee/licenses.kt @@ -38,7 +38,7 @@ internal fun normalizeLicenseInfo( pomInfo.name, spdxLicenses, unknownLicenses, - pomInfo.scm?.url?.let(::ArtifactScm) + pomInfo.scm?.url?.let(::ArtifactScm), ) } diff --git a/src/main/kotlin/app/cash/licensee/licensesSpdx.kt b/src/main/kotlin/app/cash/licensee/licensesSpdx.kt index 4ddd0155..8c54846b 100644 --- a/src/main/kotlin/app/cash/licensee/licensesSpdx.kt +++ b/src/main/kotlin/app/cash/licensee/licensesSpdx.kt @@ -15,10 +15,10 @@ */ package app.cash.licensee +import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json -import kotlin.LazyThreadSafetyMode.PUBLICATION internal class SpdxLicenses( private val identifierToLicense: Map, diff --git a/src/main/kotlin/app/cash/licensee/plugin.kt b/src/main/kotlin/app/cash/licensee/plugin.kt index efcbd48c..2738e102 100644 --- a/src/main/kotlin/app/cash/licensee/plugin.kt +++ b/src/main/kotlin/app/cash/licensee/plugin.kt @@ -18,6 +18,8 @@ package app.cash.licensee import com.android.build.gradle.AppExtension import com.android.build.gradle.LibraryExtension import com.android.build.gradle.internal.publishing.AndroidArtifacts.ArtifactType.CLASSES +import java.io.File +import java.util.Locale.ROOT import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task @@ -28,8 +30,6 @@ import org.gradle.api.tasks.TaskProvider import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.androidJvm import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.common -import java.io.File -import java.util.Locale.ROOT private const val baseTaskName = "licensee" private const val reportFolder = "licensee" @@ -75,7 +75,7 @@ class LicenseePlugin : Plugin { "project ${project.path}" } throw IllegalStateException( - "'app.cash.licensee' requires compatible language/platform plugin to be applied ($name)" + "'app.cash.licensee' requires compatible language/platform plugin to be applied ($name)", ) } diff --git a/src/main/kotlin/app/cash/licensee/pluginExtension.kt b/src/main/kotlin/app/cash/licensee/pluginExtension.kt index b4225819..7e1e4905 100644 --- a/src/main/kotlin/app/cash/licensee/pluginExtension.kt +++ b/src/main/kotlin/app/cash/licensee/pluginExtension.kt @@ -245,11 +245,13 @@ internal class MutableLicenseeExtension : LicenseeExtension { options: Action, ) { var setReason: String? = null - options.execute(object : AllowDependencyOptions { - override fun because(reason: String) { - setReason = reason - } - }) + options.execute( + object : AllowDependencyOptions { + override fun because(reason: String) { + setReason = reason + } + }, + ) allowedDependencies[DependencyCoordinates(groupId, artifactId, version)] = setReason } @@ -260,17 +262,19 @@ internal class MutableLicenseeExtension : LicenseeExtension { ) { var setReason: String? = null var setTransitive = false - options.execute(object : IgnoreDependencyOptions { - override fun because(reason: String) { - setReason = reason - } - - override var transitive: Boolean - get() = setTransitive - set(value) { - setTransitive = value + options.execute( + object : IgnoreDependencyOptions { + override fun because(reason: String) { + setReason = reason } - }) + + override var transitive: Boolean + get() = setTransitive + set(value) { + setTransitive = value + } + }, + ) if (setTransitive && setReason == null) { throw RuntimeException( @@ -282,7 +286,7 @@ internal class MutableLicenseeExtension : LicenseeExtension { append(artifactId) } append("' is dangerous and requires a reason string") - } + }, ) } diff --git a/src/main/kotlin/app/cash/licensee/task.kt b/src/main/kotlin/app/cash/licensee/task.kt index d088ab8f..e898b6e2 100644 --- a/src/main/kotlin/app/cash/licensee/task.kt +++ b/src/main/kotlin/app/cash/licensee/task.kt @@ -17,6 +17,8 @@ package app.cash.licensee import app.cash.licensee.ViolationAction.FAIL import app.cash.licensee.ViolationAction.IGNORE +import java.io.File +import kotlin.properties.Delegates import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.Json import org.gradle.api.DefaultTask @@ -35,8 +37,6 @@ import org.gradle.api.tasks.Input import org.gradle.api.tasks.Internal import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction -import java.io.File -import kotlin.properties.Delegates internal open class LicenseeTask : DefaultTask() { @get:Input @@ -96,7 +96,7 @@ internal open class LicenseeTask : DefaultTask() { append(" because ") append(ignoreData.reason) } - } + }, ) } for ((groupId, artifactIds) in dependencyConfig.ignoredCoordinates) { @@ -114,7 +114,7 @@ internal open class LicenseeTask : DefaultTask() { append(" because ") append(ignoreData.reason) } - } + }, ) } } @@ -155,7 +155,7 @@ internal open class LicenseeTask : DefaultTask() { append(artifactDetail.spdxLicenses) append(' ') append(artifactDetail.unknownLicenses) - } + }, ) } } @@ -176,7 +176,7 @@ internal open class LicenseeTask : DefaultTask() { logger.info("") logger.info("Allowed identifiers:") logger.info( - validationConfig.allowedIdentifiers.ifEmpty { listOf("None") }.joinToString(prefix = " ") + validationConfig.allowedIdentifiers.ifEmpty { listOf("None") }.joinToString(prefix = " "), ) logger.info("Allowed URLs:") if (validationConfig.allowedUrls.isEmpty()) { @@ -203,7 +203,7 @@ internal open class LicenseeTask : DefaultTask() { append(" because ") append(reason) } - } + }, ) } } diff --git a/src/test/kotlin/app/cash/licensee/LicenseePluginFixtureTest.kt b/src/test/kotlin/app/cash/licensee/LicenseePluginFixtureTest.kt index 540321bf..0c8fe301 100644 --- a/src/test/kotlin/app/cash/licensee/LicenseePluginFixtureTest.kt +++ b/src/test/kotlin/app/cash/licensee/LicenseePluginFixtureTest.kt @@ -18,12 +18,12 @@ package app.cash.licensee import com.google.common.truth.Truth.assertThat import com.google.testing.junit.testparameterinjector.TestParameter import com.google.testing.junit.testparameterinjector.TestParameterInjector +import java.io.File import org.gradle.testkit.runner.GradleRunner import org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import java.io.File @RunWith(TestParameterInjector::class) class LicenseePluginFixtureTest { @@ -145,7 +145,7 @@ class LicenseePluginFixtureTest { val fixtureDir = File(fixturesDir, fixtureName) val result = createRunner(fixtureDir).buildAndFail() assertThat(result.output).containsMatch( - "Transitive dependency ignore on 'com\\.example(:example)?' is dangerous and requires a reason string" + "Transitive dependency ignore on 'com\\.example(:example)?' is dangerous and requires a reason string", ) } @@ -155,7 +155,7 @@ class LicenseePluginFixtureTest { val fixtureDir = File(fixturesDir, fixtureName) val result = createRunner(fixtureDir).buildAndFail() assertThat(result.output).contains( - "'app.cash.licensee' requires compatible language/platform plugin to be applied (root project)" + "'app.cash.licensee' requires compatible language/platform plugin to be applied (root project)", ) } @@ -165,7 +165,7 @@ class LicenseePluginFixtureTest { val fixtureDir = File(fixturesDir, fixtureName) val result = createRunner(fixtureDir).buildAndFail() assertThat(result.output).contains( - "'app.cash.licensee' requires compatible language/platform plugin to be applied (project :some:thing)" + "'app.cash.licensee' requires compatible language/platform plugin to be applied (project :some:thing)", ) } @@ -182,7 +182,8 @@ class LicenseePluginFixtureTest { """ |com.example:example:1.0.0 | - ERROR: SPDX identifier 'Apache-2.0' is NOT allowed - |""".trimMargin() + | + """.trimMargin(), ) } @@ -199,7 +200,8 @@ class LicenseePluginFixtureTest { """ |com.example:example:1.0.0 | - ERROR: SPDX identifier 'Apache-2.0' is NOT allowed - |""".trimMargin() + | + """.trimMargin(), ) } diff --git a/src/test/kotlin/app/cash/licensee/SpdxLicensesTest.kt b/src/test/kotlin/app/cash/licensee/SpdxLicensesTest.kt index bd8dd3d1..90177bfa 100644 --- a/src/test/kotlin/app/cash/licensee/SpdxLicensesTest.kt +++ b/src/test/kotlin/app/cash/licensee/SpdxLicensesTest.kt @@ -23,7 +23,7 @@ class SpdxLicensesTest { @Test fun embeddedDatabaseLitmusTest() { assertEquals( SpdxLicense("MIT-0", "MIT No Attribution", "https://github.com/aws/mit-0"), - SpdxLicenses.embedded.findByIdentifier("MIT-0") + SpdxLicenses.embedded.findByIdentifier("MIT-0"), ) } @@ -63,15 +63,16 @@ class SpdxLicensesTest { | ] | } |]} - |""".trimMargin() + | + """.trimMargin() val spdxLicenses = SpdxLicenses.parseJson(json) assertEquals( SpdxLicense("FOO-1.0", "Foo License", "https://example.com/foo"), - spdxLicenses.findByUrl("http://example.com/foo") + spdxLicenses.findByUrl("http://example.com/foo"), ) assertEquals( SpdxLicense("BAR-1.0", "Bar License", "https://example.com/bar"), - spdxLicenses.findByUrl("http://example.com/bar") + spdxLicenses.findByUrl("http://example.com/bar"), ) } @@ -95,20 +96,21 @@ class SpdxLicensesTest { | ] | } |]} - |""".trimMargin() + | + """.trimMargin() val spdxLicenses = SpdxLicenses.parseJson(json) assertEquals( SpdxLicense("FOO-1.0", "Foo License", "https://example.com/foo"), - spdxLicenses.findByUrl("http://example.com/foo") + spdxLicenses.findByUrl("http://example.com/foo"), ) assertEquals( SpdxLicense("FOO-1.0", "Foo License", "https://example.com/foo"), - spdxLicenses.findByUrl("https://example.com/foo") + spdxLicenses.findByUrl("https://example.com/foo"), ) assertNull(spdxLicenses.findByUrl("http://example.com/bar")) assertEquals( SpdxLicense("BAR-1.0", "Bar License", "https://example.com/bar"), - spdxLicenses.findByUrl("https://example.com/bar") + spdxLicenses.findByUrl("https://example.com/bar"), ) } @@ -124,15 +126,16 @@ class SpdxLicensesTest { | ] | } |]} - |""".trimMargin() + | + """.trimMargin() val spdxLicenses = SpdxLicenses.parseJson(json) assertEquals( SpdxLicense("FOO-1.0", "Foo License", "https://example.com/foo"), - spdxLicenses.findByUrl("http://example.com/foo") + spdxLicenses.findByUrl("http://example.com/foo"), ) assertEquals( SpdxLicense("FOO-1.0", "Foo License", "https://example.com/foo"), - spdxLicenses.findByUrl("https://spdx.org/licenses/FOO-1.0.html") + spdxLicenses.findByUrl("https://spdx.org/licenses/FOO-1.0.html"), ) } @@ -154,15 +157,16 @@ class SpdxLicensesTest { | ] | } |]} - |""".trimMargin() + | + """.trimMargin() val spdxLicenses = SpdxLicenses.parseJson(json) assertEquals( SpdxLicense("FOO-1.0", "Foo License", "https://spdx.org/licenses/FOO-1.0.html"), - spdxLicenses.findByIdentifier("FOO-1.0") + spdxLicenses.findByIdentifier("FOO-1.0"), ) assertEquals( SpdxLicense("BAR-1.0", "Bar License", "https://example.com/bar"), - spdxLicenses.findByIdentifier("BAR-1.0") + spdxLicenses.findByIdentifier("BAR-1.0"), ) } }