@@ -13,6 +13,89 @@ plugins {
1313 alias(libs.plugins.kotlin.multiplatform) apply false
1414 alias(libs.plugins.android.kotlin.multiplatform.library) apply false
1515 alias(libs.plugins.android.lint) apply false
16+ alias(libs.plugins.spotless) apply false
17+ }
18+
19+ subprojects {
20+ apply (plugin = " com.diffplug.spotless" )
21+ extensions.configure< com.diffplug.gradle.spotless.SpotlessExtension > {
22+ kotlin {
23+ target(" **/*.kt" )
24+ targetExclude(" **/build/**/*.kt" )
25+
26+ val disabledRules = arrayOf(
27+ // These rules were introduced in ktlint 0.46.0 and should not be
28+ // enabled without further discussion. They are disabled for now.
29+ // See: https://github.com/pinterest/ktlint/releases/tag/0.46.0
30+ " filename" ,
31+ " annotation" ,
32+ " annotation-spacing" ,
33+ " argument-list-wrapping" ,
34+ " double-colon-spacing" ,
35+ " enum-entry-name-case" ,
36+ " multiline-if-else" ,
37+ " no-empty-first-line-in-method-block" ,
38+ " package-name" ,
39+ " trailing-comma" ,
40+ " spacing-around-angle-brackets" ,
41+ " spacing-between-declarations-with-annotations" ,
42+ " spacing-between-declarations-with-comments" ,
43+ " unary-op-spacing" ,
44+ " no-trailing-spaces" ,
45+ " max-line-length" ,
46+ // Disabled rules that were introduced or changed between 0.46.0 ~ 1.50.0
47+ " class-signature" ,
48+ " trailing-comma-on-call-site" ,
49+ " trailing-comma-on-declaration-site" ,
50+ " comment-wrapping" ,
51+ " function-literal" ,
52+ " function-signature" ,
53+ " function-expression-body" ,
54+ " function-start-of-body-spacing" ,
55+ " multiline-expression-wrapping" ,
56+ )
57+
58+ ktlint(libs.versions.ktlint.get()).editorConfigOverride(
59+ mapOf (
60+ " android" to " true" ,
61+ " ktlint_code_style" to " android_studio" ,
62+ " ij_kotlin_allow_trailing_comma" to " true" ,
63+ ) + disabledRules.map { Pair (" ktlint_standard_$it " , " disabled" ) }
64+ )
65+
66+ // ktlint 7.0.0 introduces lints, which existing snippets do not satisfy
67+ val kotlinSuppressLints = arrayOf(
68+ " standard:function-naming" ,
69+ " standard:property-naming" ,
70+ " standard:class-naming" ,
71+ " standard:max-line-length" ,
72+ " standard:comment-wrapping" ,
73+ " standard:import-ordering" ,
74+ " standard:filename" ,
75+ " standard:backing-property-naming" ,
76+ )
77+ for (lint in kotlinSuppressLints) {
78+ suppressLintsFor {
79+ step = " ktlint"
80+ shortCode = lint
81+ }
82+ }
83+
84+ licenseHeaderFile(rootProject.file(" spotless/copyright.kt" ))
85+ }
86+ kotlinGradle {
87+ target(" **/*.kts" )
88+ targetExclude(" **/build/**/*.kts" )
89+ // Look for the first line that doesn't have a block comment (assumed to be the license)
90+ licenseHeaderFile(rootProject.file(" spotless/copyright.kts" ), " (^(?![\\ / ]\\ *).*$)" )
91+ }
92+ format(" xml" ) {
93+ target(" **/*.xml" )
94+ targetExclude(" **/build/**/*.xml" )
95+ // Look for the root tag or a tag that is a snippet
96+ licenseHeaderFile(rootProject.file(" spotless/copyright.xml" ), " (<[a-zA-Z])|(<!--\\ s+(//\\ s*)?\\ [START)" ).skipLinesMatching(" .*START.*" )
97+ }
98+ }
1699}
17100
18101apply (" ${project.rootDir} /buildscripts/toml-updater-config.gradle" )
0 commit comments