Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix spotless being slow #8395

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Please ensure that your pull request meets the following requirements - thanks!
- Does not contain merge commits. Rebase instead.
- Contains commits with descriptive titles.
- New code is written in Kotlin whenever possible.
- Follows our existing codestyle (`gradlew spotlessCheck` to check and `gradlew spotlessFormat` to format your source code; will be checked by CI).
- Follows our existing codestyle (`gradlew spotlessCheck` to check and `gradlew spotlessApply` to format your source code; will be checked by CI).
- Does not break any unit tests (`gradlew testDebugUnitTest`; will be checked by CI).
- Uses a descriptive title; don't put issue numbers in there.
- Contains a reference to the issue that it fixes (e.g. _Closes #XXX_ or _Fixes #XXX_) in the body text.
Expand Down
67 changes: 67 additions & 0 deletions build-plugin/src/main/kotlin/SpotlessExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import com.diffplug.gradle.spotless.SpotlessExtension
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project

fun SpotlessExtension.configureKotlinCheck(
targets: List<String>,
project: Project,
libs: LibrariesForLibs,
) {
kotlin {
ktlint(libs.versions.ktlint.get())
.setEditorConfigPath("${project.rootProject.projectDir}/.editorconfig")
.editorConfigOverride(kotlinEditorConfigOverride)
target(targets)
targetExclude(
"**/build/",
)
}
}

fun SpotlessExtension.configureKotlinGradleCheck(
targets: List<String>,
project: Project,
libs: LibrariesForLibs,
) {
kotlinGradle {
ktlint(libs.versions.ktlint.get())
.setEditorConfigPath("${project.rootProject.projectDir}/.editorconfig")
.editorConfigOverride(
mapOf(
"ktlint_standard_function-signature" to "disabled",
)
)
target(targets)
targetExclude("**/build/")
}
}

fun SpotlessExtension.configureMarkdownCheck(
targets: List<String>,
) {
format("markdown") {
prettier()
target(targets)
targetExclude(
"**/build/",
)
}
}

fun SpotlessExtension.configureMiscCheck() {
format("misc") {
target(
"*.gradle",
".gitignore",
)
trimTrailingWhitespace()
}
}

val kotlinEditorConfigOverride = mapOf(
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
"ktlint_standard_property-naming" to "disabled",
"ktlint_standard_function-signature" to "disabled",
"ktlint_standard_parameter-list-spacing" to "disabled",
"ktlint_ignore_back_ticked_identifier" to "true",
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("thunderbird.app.android")
id("org.jetbrains.kotlin.plugin.compose")
id("thunderbird.quality.detekt.typed")
id("thunderbird.quality.spotless")
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("thunderbird.quality.detekt.typed")
id("thunderbird.quality.spotless")
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("application")
id("org.jetbrains.kotlin.jvm")
id("thunderbird.quality.detekt.typed")
id("thunderbird.quality.spotless")
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("org.jetbrains.kotlin.plugin.compose")
id("org.jetbrains.kotlin.plugin.serialization")
id("thunderbird.quality.detekt.typed")
id("thunderbird.quality.spotless")
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("thunderbird.quality.detekt.typed")
id("thunderbird.quality.spotless")
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
`java-library`
id("org.jetbrains.kotlin.jvm")
id("thunderbird.quality.detekt.typed")
id("thunderbird.quality.spotless")
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,27 @@ plugins {
}

configure<SpotlessExtension> {
kotlin {
ktlint(libs.versions.ktlint.get())
.setEditorConfigPath("$projectDir/.editorconfig")
.editorConfigOverride(editorConfigOverride)
target("**/*.kt")
targetExclude(
"**/build/",
"**/resources/",
"plugins/openpgp-api-lib/",
"ui-utils/ItemTouchHelper/",
"ui-utils/LinearLayoutManager/",
)
}
kotlinGradle {
ktlint(libs.versions.ktlint.get())
.setEditorConfigPath("$projectDir/.editorconfig")
.editorConfigOverride(editorConfigOverride)
target("**/*.gradle.kts")
targetExclude("**/build/")
}
format("markdown") {
prettier()
target("**/*.md")
targetExclude(
"plugins/openpgp-api-lib/",
"app-k9mail/fastlane/README.md",
"**/build/",
)
}
format("misc") {
target("**/*.gradle", "**/.gitignore")
trimTrailingWhitespace()
targetExclude("app-k9mail/dependencies/**")
}
}
configureKotlinCheck(
targets = listOf(
"*.kt",
),
project = project,
libs = libs,
)

configureKotlinGradleCheck(
targets = listOf(
"*.gradle.kts",
),
project = project,
libs = libs,
)

val editorConfigOverride = mapOf(
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
"ktlint_standard_property-naming" to "disabled",
"ktlint_standard_function-signature" to "disabled",
"ktlint_standard_parameter-list-spacing" to "disabled",
"ktlint_ignore_back_ticked_identifier" to "true",
)
configureMarkdownCheck(
listOf(
"*.md",
),
)

configureMiscCheck()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import com.diffplug.gradle.spotless.SpotlessExtension

plugins {
id("com.diffplug.spotless")
}

configure<SpotlessExtension> {
configureKotlinGradleCheck(
targets = listOf(
"*.gradle.kts",
"build-plugin/**/*.gradle.kts",
),
project = project,
libs = libs,
)

configureMarkdownCheck(
targets = listOf(
"*.md",
),
)

configureMiscCheck()
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.ksp) apply false

id("thunderbird.quality.spotless")
id("thunderbird.quality.spotless.root")
id("thunderbird.dependency.check")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
import android.content.IntentSender
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import androidx.fragment.app.Fragment

/**
Expand All @@ -21,10 +20,14 @@ object OpenPgpIntentStarter {

activity.startIntentSender(
intentSender,
/* fillInIntent = */ null,
/* flagsMask = */ 0,
/* flagsValues = */ 0,
/* extraFlags = */ 0,
/* fillInIntent = */
null,
/* flagsMask = */
0,
/* flagsValues = */
0,
/* extraFlags = */
0,
options,
)
}
Expand All @@ -37,10 +40,14 @@ object OpenPgpIntentStarter {
activity.startIntentSenderForResult(
intentSender,
requestCode,
/* fillInIntent = */ null,
/* flagsMask = */ 0,
/* flagsValues = */ 0,
/* extraFlags = */ 0,
/* fillInIntent = */
null,
/* flagsMask = */
0,
/* flagsValues = */
0,
/* extraFlags = */
0,
options,
)
}
Expand All @@ -54,10 +61,14 @@ object OpenPgpIntentStarter {
fragment.startIntentSenderForResult(
intentSender,
requestCode,
/* fillInIntent = */ null,
/* flagsMask = */ 0,
/* flagsValues = */ 0,
/* extraFlags = */ 0,
/* fillInIntent = */
null,
/* flagsMask = */
0,
/* flagsValues = */
0,
/* extraFlags = */
0,
options,
)
}
Expand Down