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

Add spotless code formatter #6630

Merged
merged 10 commits into from Feb 6, 2023
Merged

Add spotless code formatter #6630

merged 10 commits into from Feb 6, 2023

Conversation

wmontwe
Copy link
Collaborator

@wmontwe wmontwe commented Feb 6, 2023

This changes the ktlint plugin to the Spotless Gradle plugin with ktlint support. Spotless also allows to run other formatters, so this comes with Markdown, KTS and misc rules configured.

This spares the Java formatter due to it's massive changeset. A simple rule matching most of current Java code style is:

spotless {
    java {
        googleJavaFormat().aosp()
        target("**/*.java")
        targetExclude("plugins/openpgp-api-lib/", "ui-utils/")
    }
}

Due to some issues with ktlint 0.48.x it is still using 0.47.1. Problems expected to be fixed in ktlint 0.49.0

Closes #6605

@wmontwe wmontwe requested a review from cketti February 6, 2023 10:56
@wmontwe wmontwe self-assigned this Feb 6, 2023
Copy link
Member

@cketti cketti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pull_request_template.md needs to be updated. Otherwise LGTM 👍

@wmontwe wmontwe requested a review from cketti February 6, 2023 11:16
@wmontwe wmontwe merged commit e252532 into main Feb 6, 2023
@wmontwe wmontwe deleted the add_spotless_code_formatter branch February 6, 2023 11:37
spotless {
kotlin {
ktlint(libs.versions.ktlint.get())
.setEditorConfigPath("$projectDir/.editorconfig")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary override, it's the default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'll create a follow up change

.setEditorConfigPath("$projectDir/.editorconfig")
target("**/*.kt")
targetExclude("**/build/", "**/resources/", "plugins/openpgp-api-lib/")
endWithNewline()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule had been covered by insert_final_newline in .editorconfig.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'll create a follow up change

@@ -38,7 +39,7 @@ ksp = "com.google.devtools.ksp:1.8.0-1.0.8"
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ktlint = "org.jlleitschuh.gradle.ktlint:11.0.0"
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just inline this version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate Ktlint plugin to Kotlinter
3 participants