-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ViewModelInjectionDetector to support a lint option #53
Update ViewModelInjectionDetector to support a lint option #53
Conversation
24a815e
to
2906193
Compare
@WhosNickDoglio this is still in draft, did you want to ping us when it's ready for review? |
@ZacSweers Yeah sorry, I threw something together quick and was going to spend some time on it this weekend but got busy, I plan to finish it tomorrow and will ping you when it's ready 👍 |
2906193
to
3064b71
Compare
compose-lint-checks/src/main/java/slack/lint/compose/ViewModelInjectionDetector.kt
Outdated
Show resolved
Hide resolved
@ZacSweers This is ready for review whenever you have time! |
compose-lint-checks/src/main/java/slack/lint/compose/ViewModelInjectionDetector.kt
Outdated
Show resolved
Hide resolved
compose-lint-checks/src/main/java/slack/lint/compose/ViewModelInjectionDetector.kt
Outdated
Show resolved
Hide resolved
KnownViewModelFactories.contains(it.calleeExpression?.text) || | ||
allowedNames.value.contains(it.calleeExpression?.text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge the known and allowed factories into one set to avoid double checks. Let's also use the in
operator
40e94b6
to
9419761
Compare
@@ -8,15 +8,28 @@ import com.android.tools.lint.detector.api.Issue | |||
import com.android.tools.lint.detector.api.JavaContext | |||
import com.android.tools.lint.detector.api.Severity | |||
import com.android.tools.lint.detector.api.SourceCodeScanner | |||
import com.android.tools.lint.detector.api.StringOption | |||
import org.jetbrains.kotlin.psi.KtCallExpression | |||
import org.jetbrains.kotlin.psi.KtFunction | |||
import org.jetbrains.kotlin.psi.KtProperty | |||
import slack.lint.compose.util.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note for myself - we shouldn't have star imports, wonder why spotless isn't catching this 🤔
@@ -57,7 +71,10 @@ class ViewModelInjectionDetector : ComposableFunctionDetector(), SourceCodeScann | |||
.flatMap { property -> | |||
property | |||
.findDirectChildrenByClass<KtCallExpression>() | |||
.filter { KnownViewModelFactories.contains(it.calleeExpression?.text) } | |||
.filter { | |||
val allFactoryNames = KnownViewModelFactories + allowedNames.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this higher up? Doesn't need to be re-computed on each call
…InjectionDetector.kt Co-authored-by: Zac Sweers <pandanomic@gmail.com>
37ba043
to
bf8422e
Compare
|
||
internal val ALLOW_LIST = | ||
StringOption( | ||
"allowed-viewmodel-injection", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since it's not really an allow-list, let's improve the semantics. Maybe USER_FACTORIES
and viewmodel-factories
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@WhosNickDoglio Do you have example how user can set this parameter? I'm trying to find some way to pass custom option to lint but i think i'm missing something |
In your <issue id="ComposeViewModelInjection">
<option name="viewmodel-factories" value="ViewModelFactory1,ViewModelFactory2, etc" />
</issue> |
@WhosNickDoglio Thanks! |
Replaces #46