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

Ignore composables that emit content in their own window. #110

Merged
merged 3 commits into from
Nov 9, 2022
Merged

Ignore composables that emit content in their own window. #110

merged 3 commits into from
Nov 9, 2022

Conversation

PaulWoitaschek
Copy link
Contributor

@PaulWoitaschek PaulWoitaschek commented Nov 3, 2022

Fixes #109

@CLAassistant
Copy link

CLAassistant commented Nov 3, 2022

CLA assistant check
All committers have signed the CLA.

@PaulWoitaschek PaulWoitaschek changed the title Ignore composables that emit content in their own window. Fixes #109 Ignore composables that emit content in their own window. Nov 3, 2022
@github-actions
Copy link

github-actions bot commented Nov 3, 2022

CLA Assistant Lite bot All Contributors have signed the CLA. If the commit check is not passing, a maintainer must go the Checks tab of this PR and rerun the GitHub Action.

Copy link
Contributor

@kenyee kenyee left a comment

Choose a reason for hiding this comment

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

one minor nit...rest looks good

@kenyee
Copy link
Contributor

kenyee commented Nov 6, 2022

****

@PaulWoitaschek could you reply w/ a comment with the above text. We actually have two CLA bots, weirdly enough...

@PaulWoitaschek
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

get() {
return if (isComposable) {
sequence {
suspend fun SequenceScope<KtCallExpression>.scan(current: PsiElement) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be made tailrec? if not, then using a queue to make it iterative?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would that be necessary? This runs on user written code and I don't see where it could produce a stack overflow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Twitter for Android has several million LOC, and thousands of modules. It is the main target for us to run these rules. We've seen that not being conservative with memory causes heap to overflow our CI in the past, so any savings we can do here are worthwhile for us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but ktlint runs only on a single file. So even if you had very bad code standards and one function referencing 100 composables, that still would be premature optimization.

Copy link
Contributor

@mrmans0n mrmans0n Nov 9, 2022

Choose a reason for hiding this comment

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

If you count that it is filtering by KtCallExpressions (so not only constrained to Composables), from experience (e.g. very, very similar code to this that had to be changed, and it was targeting individual files too) this can be problematic, even if it sounds like premature optimization. Some of these files are insanely big, and we don't have the numbers now after last Friday to address the necessary refactors anymore.

Not trying to be obtuse here, just cautious 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All righty, even though I think it's premature optimization, here comes the tailrec magic 🧙‍♀️

if (klass.isInstance(current)) {
yield(current as T)
if (current is T) {
yield(current)
}
queue.addAll(current.children)
}
}

inline fun <reified T : PsiElement> PsiElement.findDirectFirstChildByClass(): T? {
Copy link
Contributor

Choose a reason for hiding this comment

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

will this need to be reified then? (same for the others)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes else the is check can not work due to type erasure.

@mrmans0n
Copy link
Contributor

mrmans0n commented Nov 7, 2022

Looks very nice, left a couple of comments, happy to re-review later

@mrmans0n mrmans0n merged commit 1199971 into twitter:main Nov 9, 2022
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.

modifier-missing-check: Wrong report for fake content emitters
4 participants