(#) CompositionLocals are discouraged
!!! WARNING: CompositionLocals are discouraged
This is a warning.
Id
: `ComposeCompositionLocalUsage`
Summary
: CompositionLocals are discouraged
Severity
: Warning
Category
: Productivity
Platform
: Any
Vendor
: slack
Identifier
: com.slack.lint.compose:compose-lints
Feedback
: https://github.com/slackhq/compose-lints/issues
Min
: Lint 8.7+
Compiled
: Lint 8.7+
Artifact
: [com.slack.lint.compose:compose-lint-checks](com_slack_lint_compose_compose-lint-checks.md.html)
Since
: 1.0.0
Affects
: Kotlin and Java files and test sources
Editing
: This check runs on the fly in the IDE editor
Implementation
: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/main/java/slack/lint/compose/CompositionLocalUsageDetector.kt)
Tests
: [Source Code](https://github.com/slackhq/compose-lints/tree/main/compose-lint-checks/src/test/java/slack/lint/compose/CompositionLocalUsageDetectorTest.kt)
Copyright Year
: 2023
`CompositionLocal`s are implicit dependencies and creating new ones
should be avoided. See
https://slackhq.github.io/compose-lints/rules/#compositionlocals for
more information.
(##) Options
You can configure this lint checks using the following options:
(###) allowed-composition-locals
A comma-separated list of CompositionLocals that should be allowed.
This property should define a comma-separated list of `CompositionLocal`s that should be allowed.
Example `lint.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
<lint>
<issue id="ComposeCompositionLocalUsage">
<option name="allowed-composition-locals" value="some string" />
</issue>
</lint>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(##) Example
Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
src/test.kt:2:Warning: `CompositionLocal`s are implicit dependencies and
creating new ones should be avoided. See
https://slackhq.github.io/compose-lints/rules/#compositionlocals for
more information. [ComposeCompositionLocalUsage]
private val LocalApple = staticCompositionLocalOf<String> { "Apple" }
---------------------------------------------------------------------
src/test.kt:3:Warning: `CompositionLocal`s are implicit dependencies and
creating new ones should be avoided. See
https://slackhq.github.io/compose-lints/rules/#compositionlocals for
more information. [ComposeCompositionLocalUsage]
internal val LocalPlum: String = staticCompositionLocalOf { "Plum" }
--------------------------------------------------------------------
src/test.kt:4:Warning: `CompositionLocal`s are implicit dependencies and
creating new ones should be avoided. See
https://slackhq.github.io/compose-lints/rules/#compositionlocals for
more information. [ComposeCompositionLocalUsage]
val LocalPrune = compositionLocalOf { "Prune" }
-----------------------------------------------
src/test.kt:5:Warning: `CompositionLocal`s are implicit dependencies and
creating new ones should be avoided. See
https://slackhq.github.io/compose-lints/rules/#compositionlocals for
more information. [ComposeCompositionLocalUsage]
private val LocalKiwi: String = compositionLocalOf { "Kiwi" }
-------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is the source file referenced above:
`src/test.kt`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers
private val LocalApple = staticCompositionLocalOf