Skip to content

Commit

Permalink
Update ktlint and dependencies (#116)
Browse files Browse the repository at this point in the history
Ktlint was updated to 0.48.x, which had some breaking changes.
  • Loading branch information
mrmans0n authored Jan 30, 2023
1 parent 39ea27a commit 0f43116
Show file tree
Hide file tree
Showing 66 changed files with 225 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private val KtCallExpression.containsComposablesWithModifiers: Boolean
*/
private val ComposableNonEmittersList = setOf(
"AlertDialog",
"ModalBottomSheetLayout"
"ModalBottomSheetLayout",
)

/**
Expand Down Expand Up @@ -136,26 +136,26 @@ private val ComposableEmittersList by lazy {
"TopAppBarSurface",
"VerticalPager",
"VerticalPagerIndicator",
"WebView"
"WebView",
)
}

val ComposableEmittersListRegex by lazy {
Regex(
listOf(
"Spacer\\d*" // Spacer() + SpacerNUM()
"Spacer\\d*", // Spacer() + SpacerNUM()
).joinToString(
separator = "|",
prefix = "(",
postfix = ")"
)
postfix = ")",
),
)
}

val ModifierNames by lazy(LazyThreadSafetyMode.NONE) {
setOf(
"Modifier",
"GlanceModifier"
"GlanceModifier",
)
}

Expand All @@ -176,13 +176,13 @@ val KtProperty.declaresCompositionLocal: Boolean
hasInitializer() &&
initializer is KtCallExpression &&
CompositionLocalReferenceExpressions.contains(
(initializer as KtCallExpression).referenceExpression()?.text
(initializer as KtCallExpression).referenceExpression()?.text,
)

private val CompositionLocalReferenceExpressions by lazy(LazyThreadSafetyMode.NONE) {
setOf(
"staticCompositionLocalOf",
"compositionLocalOf"
"compositionLocalOf",
)
}

Expand All @@ -194,6 +194,6 @@ private val RestartableEffects by lazy(LazyThreadSafetyMode.NONE) {
setOf(
"LaunchedEffect",
"produceState",
"DisposableEffect"
"DisposableEffect",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fun String.toCamelCase() = split('_').joinToString(
separator = "",
transform = { original ->
original.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
}
},
)

fun String.toSnakeCase() = replace(humps, "_").lowercase(Locale.getDefault())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ val KnownMutableCommonTypesRegex = sequenceOf(
"ReplaySubject<.*>\\??",
"PublishRelay<.*>\\??",
"BehaviorRelay<.*>\\??",
"ReplayRelay<.*>\\??"
"ReplayRelay<.*>\\??",
).map { Regex(it) }

val KtCallableDeclaration.isTypeUnstableCollection: Boolean
Expand All @@ -46,5 +46,5 @@ val KtCallableDeclaration.isTypeUnstableCollection: Boolean
val KnownUnstableCollectionTypesRegex = sequenceOf(
"Set<.*>\\??",
"List<.*>\\??",
"Map<.*>\\??"
"Map<.*>\\??",
).map { Regex(it) }
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.gitlab.arturbosch.detekt.api.internal.valueOrDefaultCommaSeparated
* during the lifetime of a rule.
*/
internal class DetektComposeKtConfig(
private val config: Config
private val config: Config,
) : ComposeKtConfig {
private val cache = mutableMapOf<String, Any?>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.utils.addToStdlib.cast

abstract class TwitterDetektRule(
config: Config = Config.empty
config: Config = Config.empty,
) : Rule(config), ComposeKtVisitor {

private val config: ComposeKtConfig by lazy { DetektComposeKtConfig(this) }
Expand All @@ -38,13 +38,13 @@ abstract class TwitterDetektRule(
issue = issue,
entity = Entity.from(finalElement, Location.from(finalElement)),
message = message,
autoCorrectEnabled = autoCorrect
autoCorrectEnabled = autoCorrect,
)

else -> CodeSmell(
issue = issue,
entity = Entity.from(finalElement, Location.from(finalElement)),
message = message
message = message,
)
}
report(finding)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.twitter.rules.core.util.toSnakeCase
* Results will be memoized as well, as config shouldn't be changing during the lifetime of a rule.
*/
internal class KtlintComposeKtConfig(
private val properties: EditorConfigProperties
private val properties: EditorConfigProperties,
) : ComposeKtConfig {
private val cache = mutableMapOf<String, Any?>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ abstract class TwitterKtlintRule(id: String) : Rule(id), ComposeKtVisitor {

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

@Suppress("DEPRECATION")
final override fun beforeVisitChildNodes(
node: ASTNode,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
) {
val psi = node.psi
when (node.elementType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class KtlintComposeKtConfigTest {
when (this) {
true -> PropertyType.PropertyValue.valid("true", true)
false -> PropertyType.PropertyValue.valid("false", false)
}
},
)
.build()
}
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[versions]
kotlin = "1.7.21"
ktlint = "0.47.1"
kotlin = "1.8.0"
ktlint = "0.48.2"
detekt = "1.22.0"
junit = "5.9.1"
junit = "5.9.2"

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

[plugins]
spotless = { id = "com.diffplug.spotless", version = "6.11.0" }
spotless = { id = "com.diffplug.spotless", version = "6.13.0" }
shadowJar = { id = "com.github.johnrengelman.shadow", version = "7.1.2" }
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ComposeModifierReused : ComposeKtVisitor {
addAll(
current.siblings()
.filterIsInstance<KtCallExpression>()
.filter { it.isUsingModifiers(modifierNames) }
.filter { it.isUsingModifiers(modifierNames) },
)
current = current.parent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ComposeParameterOrder : ComposeKtVisitor {
// As ComposeModifierMissingCheck will catch modifiers without a Modifier default, we don't have to care
// about that case. We will sort the params with defaults so that the modifier(s) go first.
val sortedWithDefaults = withDefaults.sortedWith(
compareByDescending<KtParameter> { it.isModifier }.thenByDescending { it.name == "modifier" }
compareByDescending<KtParameter> { it.isModifier }.thenByDescending { it.name == "modifier" },
)

// We create our ideal ordering of params for the ideal composable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ComposeRememberMissing : ComposeKtVisitor {
companion object {
private val MethodsThatNeedRemembering = setOf(
"derivedStateOf",
"mutableStateOf"
"mutableStateOf",
)
val DerivedStateOfNotRemembered = errorMessage("derivedStateOf")
val MutableStateOfNotRemembered = errorMessage("mutableStateOf")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ComposeUnstableCollections : ComposeKtVisitor {
val message = createErrorMessage(
type = type,
rawType = type.replace(DiamondRegex, ""),
variable = variableName
variable = variableName,
)
emitter.report(param.typeReference ?: param, message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ComposeViewModelInjection : ComposeKtVisitor {
"weaverViewModel", // Weaver
"hiltViewModel", // Hilt
"injectedViewModel", // Whetstone
"mavericksViewModel" // Mavericks
"mavericksViewModel", // Mavericks
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class ComposeCompositionLocalAllowlistCheck(config: Config) :
id = "CompositionLocalAllowlist",
severity = Severity.CodeSmell,
description = ComposeCompositionLocalAllowlist.CompositionLocalNotInAllowlist,
debt = Debt.FIVE_MINS
debt = Debt.FIVE_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class ComposeCompositionLocalNamingCheck(config: Config) :
id = "CompositionLocalNaming",
severity = Severity.CodeSmell,
description = ComposeCompositionLocalNaming.CompositionLocalNeedsLocalPrefix,
debt = Debt.FIVE_MINS
debt = Debt.FIVE_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class ComposeContentEmitterReturningValuesCheck(config: Config) :
id = "ContentEmitterReturningValues",
severity = Severity.Defect,
description = ComposeContentEmitterReturningValues.ContentEmitterReturningValuesToo,
debt = Debt.TWENTY_MINS
debt = Debt.TWENTY_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ComposeModifierComposableCheck(config: Config) :
id = "ModifierComposable",
severity = Severity.Performance,
description = ComposeModifierComposable.ComposableModifier,
debt = Debt.TEN_MINS
debt = Debt.TEN_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ComposeModifierMissingCheck(config: Config) :
id = "ModifierMissing",
severity = Severity.Defect,
description = ComposeModifierMissing.MissingModifierContentComposable,
debt = Debt.TEN_MINS
debt = Debt.TEN_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ComposeModifierReusedCheck(config: Config) :
id = "ModifierReused",
severity = Severity.Defect,
description = ComposeModifierReused.ModifierShouldBeUsedOnceOnly,
debt = Debt.TWENTY_MINS
debt = Debt.TWENTY_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class ComposeModifierWithoutDefaultCheck(config: Config) :
id = "ModifierWithoutDefault",
severity = Severity.CodeSmell,
description = ComposeModifierWithoutDefault.MissingModifierDefaultParam,
debt = Debt.FIVE_MINS
debt = Debt.FIVE_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class ComposeMultipleContentEmittersCheck(config: Config) :
id = "MultipleEmitters",
severity = Severity.Defect,
description = ComposeMultipleContentEmitters.MultipleContentEmittersDetected,
debt = Debt.TWENTY_MINS
debt = Debt.TWENTY_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ComposeMutableParametersCheck(config: Config) :
id = "MutableParams",
severity = Severity.Defect,
description = ComposeMutableParameters.MutableParameterInCompose,
debt = Debt.TWENTY_MINS
debt = Debt.TWENTY_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class ComposeNamingCheck(config: Config) :
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
""".trimIndent(),
debt = Debt.TEN_MINS
debt = Debt.TEN_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class ComposeParameterOrderCheck(config: Config) :
description = "Parameters in a composable function should be ordered following this pattern: " +
"params without defaults, modifiers, params with defaults and optionally, " +
"a trailing function that might not have a default param.",
debt = Debt.TEN_MINS
debt = Debt.TEN_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class ComposePreviewNamingCheck(config: Config) :
id = "PreviewNaming",
severity = Severity.CodeSmell,
description = "Multipreview annotations should end with the `Previews` suffix",
debt = Debt.FIVE_MINS
debt = Debt.FIVE_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class ComposePreviewPublicCheck(config: Config) :
id = "PreviewPublic",
severity = Severity.CodeSmell,
description = ComposePreviewPublic.ComposablesPreviewShouldNotBePublic,
debt = Debt.FIVE_MINS
debt = Debt.FIVE_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class ComposeRememberMissingCheck(config: Config) :
Using mutableStateOf/derivedStateOf in a @Composable function without it being inside of a remember function.
If you don't remember the state instance, a new state instance will be created when the function is recomposed.
""".trimIndent(),
debt = Debt.FIVE_MINS
debt = Debt.FIVE_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class ComposeUnstableCollectionsCheck(config: Config) :
See https://twitter.github.io/compose-rules/rules/#avoid-using-unstable-collections for more information.
""".trimIndent(),
debt = Debt.TWENTY_MINS
debt = Debt.TWENTY_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ComposeViewModelForwardingCheck(config: Config) :
id = "ViewModelForwarding",
severity = Severity.CodeSmell,
description = ComposeViewModelForwarding.AvoidViewModelForwarding,
debt = Debt.TWENTY_MINS
debt = Debt.TWENTY_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class ComposeViewModelInjectionCheck(config: Config) :
Acquiring a ViewModel should be done in composable default parameters, so that it is more testable and flexible.
""".trimIndent(),
debt = Debt.TEN_MINS
debt = Debt.TEN_MINS,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class TwitterComposeRuleSetProvider : RuleSetProvider {
ComposeRememberMissingCheck(config),
ComposeUnstableCollectionsCheck(config),
ComposeViewModelForwardingCheck(config),
ComposeViewModelInjectionCheck(config)
)
ComposeViewModelInjectionCheck(config),
),
)

private companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.junit.jupiter.api.Test
class ComposeCompositionLocalAllowlistCheckTest {

private val testConfig = TestConfig(
"allowedCompositionLocals" to listOf("LocalBanana", "LocalPotato")
"allowedCompositionLocals" to listOf("LocalBanana", "LocalPotato"),
)
private val rule = ComposeCompositionLocalAllowlistCheck(testConfig)

Expand All @@ -33,7 +33,7 @@ class ComposeCompositionLocalAllowlistCheckTest {
SourceLocation(1, 13),
SourceLocation(2, 14),
SourceLocation(3, 5),
SourceLocation(4, 13)
SourceLocation(4, 13),
)
for (error in errors) {
assertThat(error).hasMessage(ComposeCompositionLocalAllowlist.CompositionLocalNotInAllowlist)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ComposeCompositionLocalNamingCheckTest {
assertThat(errors)
.hasStartSourceLocations(
SourceLocation(1, 5),
SourceLocation(2, 5)
SourceLocation(2, 5),
)
for (error in errors) {
assertThat(error).hasMessage(ComposeCompositionLocalNaming.CompositionLocalNeedsLocalPrefix)
Expand Down
Loading

0 comments on commit 0f43116

Please sign in to comment.