Skip to content
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

Implement M2ApiDetector #75

Merged
merged 8 commits into from
Mar 7, 2023
Merged

Implement M2ApiDetector #75

merged 8 commits into from
Mar 7, 2023

Conversation

ZacSweers
Copy link
Collaborator

This implements an opt-in check that can be used to error against use of M2 APIs. This is intended to be useful for apps that have completed their M3 migrations or baseline existing M2 usages while completing their migrations.

This implements an opt-in check that can be used to error against use of M2 APIs. This is intended to be useful for apps that have completed their M3 migrations or baseline existing M2 usages while completing their migrations.
@ZacSweers
Copy link
Collaborator Author

I haven't added tests yet as I want to get early feedback on the approach before I move ahead with those!

Copy link
Collaborator

@chrisbanes chrisbanes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall!

""",
category = CORRECTNESS,
priority = NORMAL,
severity = IGNORE,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

informational? I think it's worth highlighting even if devs don't want to make it an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I generally agree. Do you know if M2 is ever going to be fully deprecated?

Copy link
Collaborator

@chrisbanes chrisbanes Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point. We need to think about teams who are using M2 and don't want to migrate yet. We should probably add some docs to copy-pasta for changing the severity level?

Or maybe just link to https://developer.android.com/studio/write/lint#gradle

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


override fun createUastHandler(context: JavaContext) =
object : UElementHandler() {
override fun visitCallExpression(node: UCallExpression) = checkNode(node)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the call expression contain the package name? It wouldn't in ktlint, but I guess it will in Lint? If so, I say we don't check the imports.

Having this handle imports means that devs have to use @file:SuppressLint to suppress the import warnings, and they're annoying 😆

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you call resolve on the UCallExpression, it returns the called function and we check the package name of that function.

Agreed on imports. May be a no-go since I don't think you can use file site target with @SuppressLint 🤔. I'll check

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can for Kotlin @Suppress but I don't think I've ever tried it for SuppressLint

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah you can't since it's in the android jar itself. Remove imports 88b5bf1

docs/rules.md Outdated Show resolved Hide resolved
docs/rules.md Outdated

Material 3 (M3) reached stable in October 2022. In apps that have migrated to M3, there may be `androidx.compose.material` (M2) APIs still remaining on the classpath from libraries or dependencies that can cause confusing imports due to the many similar or colliding Composable names in the two libraries. The `ComposeM2Api` can be enabled + set to `ERROR` to prevent these from being used.

Note that this rule is set to `IGNORE` by default and is opt-in.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto severity comment above

@ZacSweers
Copy link
Collaborator Author

@chrisbanes should be ready to go now, added tests and spruced up docs more

Copy link
Collaborator

@chrisbanes chrisbanes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: great work!

@ZacSweers ZacSweers added this pull request to the merge queue Mar 7, 2023
Merged via the queue into main with commit 0bdba39 Mar 7, 2023
@ZacSweers ZacSweers deleted the z/m2ApiDetector branch March 7, 2023 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants