diff --git a/compose-lint-checks/src/main/java/slack/lint/compose/MutableParametersDetector.kt b/compose-lint-checks/src/main/java/slack/lint/compose/MutableParametersDetector.kt index dc7722b9..1763b7ec 100644 --- a/compose-lint-checks/src/main/java/slack/lint/compose/MutableParametersDetector.kt +++ b/compose-lint-checks/src/main/java/slack/lint/compose/MutableParametersDetector.kt @@ -24,7 +24,7 @@ class MutableParametersDetector : ComposableFunctionDetector(), SourceCodeScanne """ Using mutable objects as state in Compose will cause your users to see incorrect or stale data in your app. Mutable objects that are not observable, such as `ArrayList` or a mutable data class, cannot be observed by Compose to trigger recomposition when they change. - See https://slackhq.github.io/compose-lints/rules/#when-should-i-expose-modifier-parameters for more information. + See https://slackhq.github.io/compose-lints/rules/#do-not-use-inherently-mutable-types-as-parameters for more information. """, category = Category.PRODUCTIVITY, priority = Priorities.NORMAL, @@ -36,11 +36,11 @@ class MutableParametersDetector : ComposableFunctionDetector(), SourceCodeScanne override fun visitComposable(context: JavaContext, function: KtFunction) { function.valueParameters .filter { it.isTypeMutable } - .forEach { + .forEach { parameter -> context.report( ISSUE, - function, - context.getNameLocation(function), + parameter.typeReference, + context.getLocation(parameter.typeReference), ISSUE.getExplanation(TextFormat.TEXT) ) } diff --git a/compose-lint-checks/src/main/java/slack/lint/compose/util/KtCallableDeclarations.kt b/compose-lint-checks/src/main/java/slack/lint/compose/util/KtCallableDeclarations.kt index a66a695c..50a304b3 100644 --- a/compose-lint-checks/src/main/java/slack/lint/compose/util/KtCallableDeclarations.kt +++ b/compose-lint-checks/src/main/java/slack/lint/compose/util/KtCallableDeclarations.kt @@ -29,7 +29,6 @@ val KnownMutableCommonTypesRegex = "Hashtable<.*>\\??", // Compose "MutableState<.*>\\??", - "SnapshotStateList<.*>\\??", // Flow "MutableStateFlow<.*>\\??", "MutableSharedFlow<.*>\\??", diff --git a/compose-lint-checks/src/test/java/slack/lint/compose/MutableParametersDetectorTest.kt b/compose-lint-checks/src/test/java/slack/lint/compose/MutableParametersDetectorTest.kt index 29e351e3..643835e6 100644 --- a/compose-lint-checks/src/test/java/slack/lint/compose/MutableParametersDetectorTest.kt +++ b/compose-lint-checks/src/test/java/slack/lint/compose/MutableParametersDetectorTest.kt @@ -47,24 +47,24 @@ class MutableParametersDetectorTest : BaseSlackLintTest() { """ src/test.kt:2: Error: Using mutable objects as state in Compose will cause your users to see incorrect or stale data in your app. Mutable objects that are not observable, such as ArrayList or a mutable data class, cannot be observed by Compose to trigger recomposition when they change. - See https://slackhq.github.io/compose-lints/rules/#when-should-i-expose-modifier-parameters for more information. [ComposeMutableParameters] + See https://slackhq.github.io/compose-lints/rules/#do-not-use-inherently-mutable-types-as-parameters for more information. [ComposeMutableParameters] fun Something(a: MutableState) {} - ~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~ src/test.kt:4: Error: Using mutable objects as state in Compose will cause your users to see incorrect or stale data in your app. Mutable objects that are not observable, such as ArrayList or a mutable data class, cannot be observed by Compose to trigger recomposition when they change. - See https://slackhq.github.io/compose-lints/rules/#when-should-i-expose-modifier-parameters for more information. [ComposeMutableParameters] + See https://slackhq.github.io/compose-lints/rules/#do-not-use-inherently-mutable-types-as-parameters for more information. [ComposeMutableParameters] fun Something(a: ArrayList) {} - ~~~~~~~~~ + ~~~~~~~~~~~~~~~~~ src/test.kt:6: Error: Using mutable objects as state in Compose will cause your users to see incorrect or stale data in your app. Mutable objects that are not observable, such as ArrayList or a mutable data class, cannot be observed by Compose to trigger recomposition when they change. - See https://slackhq.github.io/compose-lints/rules/#when-should-i-expose-modifier-parameters for more information. [ComposeMutableParameters] + See https://slackhq.github.io/compose-lints/rules/#do-not-use-inherently-mutable-types-as-parameters for more information. [ComposeMutableParameters] fun Something(a: HashSet) {} - ~~~~~~~~~ + ~~~~~~~~~~~~~~~ src/test.kt:8: Error: Using mutable objects as state in Compose will cause your users to see incorrect or stale data in your app. Mutable objects that are not observable, such as ArrayList or a mutable data class, cannot be observed by Compose to trigger recomposition when they change. - See https://slackhq.github.io/compose-lints/rules/#when-should-i-expose-modifier-parameters for more information. [ComposeMutableParameters] + See https://slackhq.github.io/compose-lints/rules/#do-not-use-inherently-mutable-types-as-parameters for more information. [ComposeMutableParameters] fun Something(a: MutableMap) {} - ~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 errors, 0 warnings """ .trimIndent()