Skip to content

Commit 0f43116

Browse files
authored
Update ktlint and dependencies (#116)
Ktlint was updated to 0.48.x, which had some breaking changes.
1 parent 39ea27a commit 0f43116

File tree

66 files changed

+225
-261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+225
-261
lines changed

core-common/src/main/kotlin/com/twitter/rules/core/util/Composables.kt

+9-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private val KtCallExpression.containsComposablesWithModifiers: Boolean
6464
*/
6565
private val ComposableNonEmittersList = setOf(
6666
"AlertDialog",
67-
"ModalBottomSheetLayout"
67+
"ModalBottomSheetLayout",
6868
)
6969

7070
/**
@@ -136,26 +136,26 @@ private val ComposableEmittersList by lazy {
136136
"TopAppBarSurface",
137137
"VerticalPager",
138138
"VerticalPagerIndicator",
139-
"WebView"
139+
"WebView",
140140
)
141141
}
142142

143143
val ComposableEmittersListRegex by lazy {
144144
Regex(
145145
listOf(
146-
"Spacer\\d*" // Spacer() + SpacerNUM()
146+
"Spacer\\d*", // Spacer() + SpacerNUM()
147147
).joinToString(
148148
separator = "|",
149149
prefix = "(",
150-
postfix = ")"
151-
)
150+
postfix = ")",
151+
),
152152
)
153153
}
154154

155155
val ModifierNames by lazy(LazyThreadSafetyMode.NONE) {
156156
setOf(
157157
"Modifier",
158-
"GlanceModifier"
158+
"GlanceModifier",
159159
)
160160
}
161161

@@ -176,13 +176,13 @@ val KtProperty.declaresCompositionLocal: Boolean
176176
hasInitializer() &&
177177
initializer is KtCallExpression &&
178178
CompositionLocalReferenceExpressions.contains(
179-
(initializer as KtCallExpression).referenceExpression()?.text
179+
(initializer as KtCallExpression).referenceExpression()?.text,
180180
)
181181

182182
private val CompositionLocalReferenceExpressions by lazy(LazyThreadSafetyMode.NONE) {
183183
setOf(
184184
"staticCompositionLocalOf",
185-
"compositionLocalOf"
185+
"compositionLocalOf",
186186
)
187187
}
188188

@@ -194,6 +194,6 @@ private val RestartableEffects by lazy(LazyThreadSafetyMode.NONE) {
194194
setOf(
195195
"LaunchedEffect",
196196
"produceState",
197-
"DisposableEffect"
197+
"DisposableEffect",
198198
)
199199
}

core-common/src/main/kotlin/com/twitter/rules/core/util/KotlinUtils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fun String.toCamelCase() = split('_').joinToString(
1919
separator = "",
2020
transform = { original ->
2121
original.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
22-
}
22+
},
2323
)
2424

2525
fun String.toSnakeCase() = replace(humps, "_").lowercase(Locale.getDefault())

core-common/src/main/kotlin/com/twitter/rules/core/util/KtCallableDeclarations.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ val KnownMutableCommonTypesRegex = sequenceOf(
3737
"ReplaySubject<.*>\\??",
3838
"PublishRelay<.*>\\??",
3939
"BehaviorRelay<.*>\\??",
40-
"ReplayRelay<.*>\\??"
40+
"ReplayRelay<.*>\\??",
4141
).map { Regex(it) }
4242

4343
val KtCallableDeclaration.isTypeUnstableCollection: Boolean
@@ -46,5 +46,5 @@ val KtCallableDeclaration.isTypeUnstableCollection: Boolean
4646
val KnownUnstableCollectionTypesRegex = sequenceOf(
4747
"Set<.*>\\??",
4848
"List<.*>\\??",
49-
"Map<.*>\\??"
49+
"Map<.*>\\??",
5050
).map { Regex(it) }

core-detekt/src/main/kotlin/com/twitter/rules/core/detekt/DetektComposeKtConfig.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import io.gitlab.arturbosch.detekt.api.internal.valueOrDefaultCommaSeparated
1111
* during the lifetime of a rule.
1212
*/
1313
internal class DetektComposeKtConfig(
14-
private val config: Config
14+
private val config: Config,
1515
) : ComposeKtConfig {
1616
private val cache = mutableMapOf<String, Any?>()
1717

core-detekt/src/main/kotlin/com/twitter/rules/core/detekt/TwitterDetektRule.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
2323
import org.jetbrains.kotlin.utils.addToStdlib.cast
2424

2525
abstract class TwitterDetektRule(
26-
config: Config = Config.empty
26+
config: Config = Config.empty,
2727
) : Rule(config), ComposeKtVisitor {
2828

2929
private val config: ComposeKtConfig by lazy { DetektComposeKtConfig(this) }
@@ -38,13 +38,13 @@ abstract class TwitterDetektRule(
3838
issue = issue,
3939
entity = Entity.from(finalElement, Location.from(finalElement)),
4040
message = message,
41-
autoCorrectEnabled = autoCorrect
41+
autoCorrectEnabled = autoCorrect,
4242
)
4343

4444
else -> CodeSmell(
4545
issue = issue,
4646
entity = Entity.from(finalElement, Location.from(finalElement)),
47-
message = message
47+
message = message,
4848
)
4949
}
5050
report(finding)

core-ktlint/src/main/kotlin/com/twitter/rules/core/ktlint/KtlintComposeKtConfig.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.twitter.rules.core.util.toSnakeCase
1313
* Results will be memoized as well, as config shouldn't be changing during the lifetime of a rule.
1414
*/
1515
internal class KtlintComposeKtConfig(
16-
private val properties: EditorConfigProperties
16+
private val properties: EditorConfigProperties,
1717
) : ComposeKtConfig {
1818
private val cache = mutableMapOf<String, Any?>()
1919

core-ktlint/src/main/kotlin/com/twitter/rules/core/ktlint/TwitterKtlintRule.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ abstract class TwitterKtlintRule(id: String) : Rule(id), ComposeKtVisitor {
2727

2828
private val config: ComposeKtConfig by lazy { KtlintComposeKtConfig(properties) }
2929

30+
@Suppress("DEPRECATION")
3031
final override fun beforeVisitChildNodes(
3132
node: ASTNode,
3233
autoCorrect: Boolean,
33-
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
34+
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
3435
) {
3536
val psi = node.psi
3637
when (node.elementType) {

core-ktlint/src/test/kotlin/com/twitter/rules/core/ktlint/KtlintComposeKtConfigTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class KtlintComposeKtConfigTest {
9494
when (this) {
9595
true -> PropertyType.PropertyValue.valid("true", true)
9696
false -> PropertyType.PropertyValue.valid("false", false)
97-
}
97+
},
9898
)
9999
.build()
100100
}

gradle/libs.versions.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[versions]
2-
kotlin = "1.7.21"
3-
ktlint = "0.47.1"
2+
kotlin = "1.8.0"
3+
ktlint = "0.48.2"
44
detekt = "1.22.0"
5-
junit = "5.9.1"
5+
junit = "5.9.2"
66

77
[libraries]
88
ktlint-core = { module = "com.pinterest.ktlint:ktlint-core", version.ref = "ktlint" }
@@ -23,5 +23,5 @@ assertj = "org.assertj:assertj-core:3.23.1"
2323
reflections = "org.reflections:reflections:0.10.2"
2424

2525
[plugins]
26-
spotless = { id = "com.diffplug.spotless", version = "6.11.0" }
26+
spotless = { id = "com.diffplug.spotless", version = "6.13.0" }
2727
shadowJar = { id = "com.github.johnrengelman.shadow", version = "7.1.2" }

rules/common/src/main/kotlin/com/twitter/compose/rules/ComposeModifierReused.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ComposeModifierReused : ComposeKtVisitor {
4949
addAll(
5050
current.siblings()
5151
.filterIsInstance<KtCallExpression>()
52-
.filter { it.isUsingModifiers(modifierNames) }
52+
.filter { it.isUsingModifiers(modifierNames) },
5353
)
5454
current = current.parent
5555
}

rules/common/src/main/kotlin/com/twitter/compose/rules/ComposeParameterOrder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ComposeParameterOrder : ComposeKtVisitor {
3939
// As ComposeModifierMissingCheck will catch modifiers without a Modifier default, we don't have to care
4040
// about that case. We will sort the params with defaults so that the modifier(s) go first.
4141
val sortedWithDefaults = withDefaults.sortedWith(
42-
compareByDescending<KtParameter> { it.isModifier }.thenByDescending { it.name == "modifier" }
42+
compareByDescending<KtParameter> { it.isModifier }.thenByDescending { it.name == "modifier" },
4343
)
4444

4545
// We create our ideal ordering of params for the ideal composable.

rules/common/src/main/kotlin/com/twitter/compose/rules/ComposeRememberMissing.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ComposeRememberMissing : ComposeKtVisitor {
4141
companion object {
4242
private val MethodsThatNeedRemembering = setOf(
4343
"derivedStateOf",
44-
"mutableStateOf"
44+
"mutableStateOf",
4545
)
4646
val DerivedStateOfNotRemembered = errorMessage("derivedStateOf")
4747
val MutableStateOfNotRemembered = errorMessage("mutableStateOf")

rules/common/src/main/kotlin/com/twitter/compose/rules/ComposeUnstableCollections.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ComposeUnstableCollections : ComposeKtVisitor {
1818
val message = createErrorMessage(
1919
type = type,
2020
rawType = type.replace(DiamondRegex, ""),
21-
variable = variableName
21+
variable = variableName,
2222
)
2323
emitter.report(param.typeReference ?: param, message)
2424
}

rules/common/src/main/kotlin/com/twitter/compose/rules/ComposeViewModelInjection.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ComposeViewModelInjection : ComposeKtVisitor {
109109
"weaverViewModel", // Weaver
110110
"hiltViewModel", // Hilt
111111
"injectedViewModel", // Whetstone
112-
"mavericksViewModel" // Mavericks
112+
"mavericksViewModel", // Mavericks
113113
)
114114
}
115115

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeCompositionLocalAllowlistCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ class ComposeCompositionLocalAllowlistCheck(config: Config) :
1818
id = "CompositionLocalAllowlist",
1919
severity = Severity.CodeSmell,
2020
description = ComposeCompositionLocalAllowlist.CompositionLocalNotInAllowlist,
21-
debt = Debt.FIVE_MINS
21+
debt = Debt.FIVE_MINS,
2222
)
2323
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeCompositionLocalNamingCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ class ComposeCompositionLocalNamingCheck(config: Config) :
1818
id = "CompositionLocalNaming",
1919
severity = Severity.CodeSmell,
2020
description = ComposeCompositionLocalNaming.CompositionLocalNeedsLocalPrefix,
21-
debt = Debt.FIVE_MINS
21+
debt = Debt.FIVE_MINS,
2222
)
2323
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeContentEmitterReturningValuesCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ class ComposeContentEmitterReturningValuesCheck(config: Config) :
1818
id = "ContentEmitterReturningValues",
1919
severity = Severity.Defect,
2020
description = ComposeContentEmitterReturningValues.ContentEmitterReturningValuesToo,
21-
debt = Debt.TWENTY_MINS
21+
debt = Debt.TWENTY_MINS,
2222
)
2323
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeModifierComposableCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class ComposeModifierComposableCheck(config: Config) :
1717
id = "ModifierComposable",
1818
severity = Severity.Performance,
1919
description = ComposeModifierComposable.ComposableModifier,
20-
debt = Debt.TEN_MINS
20+
debt = Debt.TEN_MINS,
2121
)
2222
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeModifierMissingCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class ComposeModifierMissingCheck(config: Config) :
1717
id = "ModifierMissing",
1818
severity = Severity.Defect,
1919
description = ComposeModifierMissing.MissingModifierContentComposable,
20-
debt = Debt.TEN_MINS
20+
debt = Debt.TEN_MINS,
2121
)
2222
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeModifierReusedCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class ComposeModifierReusedCheck(config: Config) :
1717
id = "ModifierReused",
1818
severity = Severity.Defect,
1919
description = ComposeModifierReused.ModifierShouldBeUsedOnceOnly,
20-
debt = Debt.TWENTY_MINS
20+
debt = Debt.TWENTY_MINS,
2121
)
2222
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeModifierWithoutDefaultCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ class ComposeModifierWithoutDefaultCheck(config: Config) :
1818
id = "ModifierWithoutDefault",
1919
severity = Severity.CodeSmell,
2020
description = ComposeModifierWithoutDefault.MissingModifierDefaultParam,
21-
debt = Debt.FIVE_MINS
21+
debt = Debt.FIVE_MINS,
2222
)
2323
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeMultipleContentEmittersCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ class ComposeMultipleContentEmittersCheck(config: Config) :
1818
id = "MultipleEmitters",
1919
severity = Severity.Defect,
2020
description = ComposeMultipleContentEmitters.MultipleContentEmittersDetected,
21-
debt = Debt.TWENTY_MINS
21+
debt = Debt.TWENTY_MINS,
2222
)
2323
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeMutableParametersCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class ComposeMutableParametersCheck(config: Config) :
1717
id = "MutableParams",
1818
severity = Severity.Defect,
1919
description = ComposeMutableParameters.MutableParameterInCompose,
20-
debt = Debt.TWENTY_MINS
20+
debt = Debt.TWENTY_MINS,
2121
)
2222
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeNamingCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ class ComposeNamingCheck(config: Config) :
2121
2222
However, Composable functions that return a value should start with a lowercase letter instead. They should follow the standard Kotlin Coding Conventions for the naming of functions for any function annotated @Composable that returns a value other than Unit
2323
""".trimIndent(),
24-
debt = Debt.TEN_MINS
24+
debt = Debt.TEN_MINS,
2525
)
2626
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeParameterOrderCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class ComposeParameterOrderCheck(config: Config) :
1919
description = "Parameters in a composable function should be ordered following this pattern: " +
2020
"params without defaults, modifiers, params with defaults and optionally, " +
2121
"a trailing function that might not have a default param.",
22-
debt = Debt.TEN_MINS
22+
debt = Debt.TEN_MINS,
2323
)
2424
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposePreviewNamingCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ class ComposePreviewNamingCheck(config: Config) :
1818
id = "PreviewNaming",
1919
severity = Severity.CodeSmell,
2020
description = "Multipreview annotations should end with the `Previews` suffix",
21-
debt = Debt.FIVE_MINS
21+
debt = Debt.FIVE_MINS,
2222
)
2323
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposePreviewPublicCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ class ComposePreviewPublicCheck(config: Config) :
1818
id = "PreviewPublic",
1919
severity = Severity.CodeSmell,
2020
description = ComposePreviewPublic.ComposablesPreviewShouldNotBePublic,
21-
debt = Debt.FIVE_MINS
21+
debt = Debt.FIVE_MINS,
2222
)
2323
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeRememberMissingCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ class ComposeRememberMissingCheck(config: Config) :
2121
Using mutableStateOf/derivedStateOf in a @Composable function without it being inside of a remember function.
2222
If you don't remember the state instance, a new state instance will be created when the function is recomposed.
2323
""".trimIndent(),
24-
debt = Debt.FIVE_MINS
24+
debt = Debt.FIVE_MINS,
2525
)
2626
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeUnstableCollectionsCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ class ComposeUnstableCollectionsCheck(config: Config) :
2222
2323
See https://twitter.github.io/compose-rules/rules/#avoid-using-unstable-collections for more information.
2424
""".trimIndent(),
25-
debt = Debt.TWENTY_MINS
25+
debt = Debt.TWENTY_MINS,
2626
)
2727
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeViewModelForwardingCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class ComposeViewModelForwardingCheck(config: Config) :
1717
id = "ViewModelForwarding",
1818
severity = Severity.CodeSmell,
1919
description = ComposeViewModelForwarding.AvoidViewModelForwarding,
20-
debt = Debt.TWENTY_MINS
20+
debt = Debt.TWENTY_MINS,
2121
)
2222
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/ComposeViewModelInjectionCheck.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ class ComposeViewModelInjectionCheck(config: Config) :
2222
2323
Acquiring a ViewModel should be done in composable default parameters, so that it is more testable and flexible.
2424
""".trimIndent(),
25-
debt = Debt.TEN_MINS
25+
debt = Debt.TEN_MINS,
2626
)
2727
}

rules/detekt/src/main/kotlin/com/twitter/compose/rules/detekt/TwitterComposeRuleSetProvider.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class TwitterComposeRuleSetProvider : RuleSetProvider {
2828
ComposeRememberMissingCheck(config),
2929
ComposeUnstableCollectionsCheck(config),
3030
ComposeViewModelForwardingCheck(config),
31-
ComposeViewModelInjectionCheck(config)
32-
)
31+
ComposeViewModelInjectionCheck(config),
32+
),
3333
)
3434

3535
private companion object {

rules/detekt/src/test/kotlin/com/twitter/compose/rules/detekt/ComposeCompositionLocalAllowlistCheckTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.junit.jupiter.api.Test
1313
class ComposeCompositionLocalAllowlistCheckTest {
1414

1515
private val testConfig = TestConfig(
16-
"allowedCompositionLocals" to listOf("LocalBanana", "LocalPotato")
16+
"allowedCompositionLocals" to listOf("LocalBanana", "LocalPotato"),
1717
)
1818
private val rule = ComposeCompositionLocalAllowlistCheck(testConfig)
1919

@@ -33,7 +33,7 @@ class ComposeCompositionLocalAllowlistCheckTest {
3333
SourceLocation(1, 13),
3434
SourceLocation(2, 14),
3535
SourceLocation(3, 5),
36-
SourceLocation(4, 13)
36+
SourceLocation(4, 13),
3737
)
3838
for (error in errors) {
3939
assertThat(error).hasMessage(ComposeCompositionLocalAllowlist.CompositionLocalNotInAllowlist)

rules/detekt/src/test/kotlin/com/twitter/compose/rules/detekt/ComposeCompositionLocalNamingCheckTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ComposeCompositionLocalNamingCheckTest {
2626
assertThat(errors)
2727
.hasStartSourceLocations(
2828
SourceLocation(1, 5),
29-
SourceLocation(2, 5)
29+
SourceLocation(2, 5),
3030
)
3131
for (error in errors) {
3232
assertThat(error).hasMessage(ComposeCompositionLocalNaming.CompositionLocalNeedsLocalPrefix)

0 commit comments

Comments
 (0)