Skip to content

Detekt - Resolve/Suppress All Baseline Warnings - Long methods warnings_ MediaPickerActivity - #17278

Closed
Hoossayn wants to merge 12 commits into
wordpress-mobile:trunkfrom
Hoossayn:17010-Detekt_Resolve/Suppress_All_Baseline_Warnings_long_method_media_picker
Closed

Detekt - Resolve/Suppress All Baseline Warnings - Long methods warnings_ MediaPickerActivity#17278
Hoossayn wants to merge 12 commits into
wordpress-mobile:trunkfrom
Hoossayn:17010-Detekt_Resolve/Suppress_All_Baseline_Warnings_long_method_media_picker

Conversation

@Hoossayn

@Hoossayn Hoossayn commented Oct 5, 2022

Copy link
Copy Markdown
Contributor

Parent: #17010

This PR resolved/suppress all complexity related LongMethod warnings for the WordPress module (see docs here):

1 x LongMethod (Resolve: e06b430 + 6086e9f)
To test:

  • There is nothing much to test here.

  • Verifying that all the CI checks are successful should be enough (especially the detekt check).

  • However, if you really want to be thorough, you could smoke test the WordPress and/or Jetpack apps to verify that everything works as expected on every screen that relates to these changes.
    STEPS

  • Go to the menu tab

  • click on media option

  • click on the upload media button or the (+) button at the top right corner

  • select choose from device

  • select an image

Regression Notes

  1. Potential unintended areas of impact
    can't think of any

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    See To test section above.

  3. What automated tests I added (or what prevented me from doing so)
    N/A

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@Hoossayn
Hoossayn marked this pull request as ready for review October 5, 2022 22:41
@ParaskP7 ParaskP7 self-assigned this Oct 6, 2022
@ParaskP7
ParaskP7 self-requested a review October 6, 2022 10:49
@ParaskP7 ParaskP7 added this to the Future milestone Oct 6, 2022

@ParaskP7 ParaskP7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👋 @Hoossayn !

Thank you so much for this PR. Your contributions are always welcome! 🎉

I did an initial quick review of this PR, along with triggering CI on it via a #17283 that I just pushed on the main repo.


Below, I am going to leave you a few notes that I would love for you could take a look at, think about them and update the PR and code accordingly, please take this as an opportunity to learn so that we get better with every PR that will follow:

  • PR Description Related:
    1. Suggestion (💡): You could be more specific about the commits you resolve, for example do this instead: 1 x LongMethod (Resolve: e06b430 + 6086e9f)
    2. Suggestion (💡): On your To test section (3rd bullet point) you specify that one would need to test every screen that related to these changes. Although this testing instruction is good, it is too vague. In this case, you could be more specific and give targeted instructions on how to test the screen associated with the MediaPickerActivity related screen. This way, you will give the reviewer an easy step-by-step guide on what to test and how. This will also increase the code reviewer's confidence that you took the time to do this testing as well.
    3. Suggestion (💡): For the regression notes, on the potential unintended areas of impact section, try to think about them and if you can't think of any of don't believe there are any, at least leave a N/A, just like you did for the automated tests section further below.
  • Commit Related:
    • Suggestion (💡): Try being as descriptive with your commits as possible. For example, instead of refactor for takeAPhoto you could write something like Refactor: Extract take a photo method for media picker activity (a max 72 chars per line). Note that I used the Refactor action to indicate what this commit is about (other kinds of actions could be Analysis, Build, Release, Feature, etc), but then, I was also specific about what kind of a refactor is that, in this case an extraction (other kinds of refactors could be a move, remoe, rename, optimize, etc).
  • Code Related:
    1. Warning (⚠️): The main goal of this PR is to resolve this specific baseline warning and as such removing it from the baseline.xml Detekt related file. As such, although you did resolve the warning by extracting the code into newly created methods, you didn't follow-up with removing that specific LongMethod:MediaPickerActivity line from it. Also, note that with this refactor that you did you also resolved the NestedBlockDepth:MediaPickerActivity. As such, this line can be removed as well, with one change, you solved another problem too, kudos.
    2. Suggestion (💡): Now that you extracted these code into newly created methods, you could also consider to further optimize this, by removing the extra braces from the when entries, thus leaving the code in an even better state than before. An extra commit like that will do:
            TAKE_PHOTO -> takeAPhoto()
            IMAGE_EDITOR_EDIT_IMAGE -> data?.let { editImageIntent(it) }
            else -> data

I hope the above will help you instead of overwhelm you, as this is not my intention here. 🙏 No matter, I apologize in advance if the above overwhelms you anyway. I just hope you now understand why I am insisting in taking this slow, making small changes and progress accordingly, that is, after we discuss and improve on the overall process.


PS: Note that this MediaPickerActivity.onActivityResult(...) method got slightly updated already, on trunk, and via another refactor that happened few days ago (by me). This change added the @Suppress("DEPRECATION", "LongMethod", "NestedBlockDepth") and removed these violations from the baseline.xml that I specified in my above warning (⚠️) comment to you. Thus, after you merge your changes with trunk, you would need to update the suppress annotation to @Suppress("DEPRECATION") instead of removing the no longer existing (in current trunk) baseline lines. Does that help you? 😊

@Hoossayn
Hoossayn requested a review from ParaskP7 October 11, 2022 09:54
@Hoossayn

Copy link
Copy Markdown
Contributor Author

👋 @Hoossayn !

Thank you so much for this PR. Your contributions are always welcome! 🎉

I did an initial quick review of this PR, along with triggering CI on it via a #17283 that I just pushed on the main repo.

Below, I am going to leave you a few notes that I would love for you could take a look at, think about them and update the PR and code accordingly, please take this as an opportunity to learn so that we get better with every PR that will follow:

  • PR Description Related:

    1. Suggestion (💡): You could be more specific about the commits you resolve, for example do this instead: 1 x LongMethod (Resolve: e06b430 + 6086e9f)
    2. Suggestion (💡): On your To test section (3rd bullet point) you specify that one would need to test every screen that related to these changes. Although this testing instruction is good, it is too vague. In this case, you could be more specific and give targeted instructions on how to test the screen associated with the MediaPickerActivity related screen. This way, you will give the reviewer an easy step-by-step guide on what to test and how. This will also increase the code reviewer's confidence that you took the time to do this testing as well.
    3. Suggestion (💡): For the regression notes, on the potential unintended areas of impact section, try to think about them and if you can't think of any of don't believe there are any, at least leave a N/A, just like you did for the automated tests section further below.
  • Commit Related:

    • Suggestion (💡): Try being as descriptive with your commits as possible. For example, instead of refactor for takeAPhoto you could write something like Refactor: Extract take a photo method for media picker activity (a max 72 chars per line). Note that I used the Refactor action to indicate what this commit is about (other kinds of actions could be Analysis, Build, Release, Feature, etc), but then, I was also specific about what kind of a refactor is that, in this case an extraction (other kinds of refactors could be a move, remoe, rename, optimize, etc).
  • Code Related:

    1. Warning (⚠️): The main goal of this PR is to resolve this specific baseline warning and as such removing it from the baseline.xml Detekt related file. As such, although you did resolve the warning by extracting the code into newly created methods, you didn't follow-up with removing that specific LongMethod:MediaPickerActivity line from it. Also, note that with this refactor that you did you also resolved the NestedBlockDepth:MediaPickerActivity. As such, this line can be removed as well, with one change, you solved another problem too, kudos.
    2. Suggestion (💡): Now that you extracted these code into newly created methods, you could also consider to further optimize this, by removing the extra braces from the when entries, thus leaving the code in an even better state than before. An extra commit like that will do:
            TAKE_PHOTO -> takeAPhoto()
            IMAGE_EDITOR_EDIT_IMAGE -> data?.let { editImageIntent(it) }
            else -> data

I hope the above will help you instead of overwhelm you, as this is not my intention here. 🙏 No matter, I apologize in advance if the above overwhelms you anyway. I just hope you now understand why I am insisting in taking this slow, making small changes and progress accordingly, that is, after we discuss and improve on the overall process.

PS: Note that this MediaPickerActivity.onActivityResult(...) method got slightly updated already, on trunk, and via another refactor that happened few days ago (by me). This change added the @Suppress("DEPRECATION", "LongMethod", "NestedBlockDepth") and removed these violations from the baseline.xml that I specified in my above warning (⚠️) comment to you. Thus, after you merge your changes with trunk, you would need to update the suppress annotation to @Suppress("DEPRECATION") instead of removing the no longer existing (in current trunk) baseline lines. Does that help you? 😊

👋🏾 @ParaskP7 thank you once again for documenting your observation and suggestion.
Also you last point about making changes to MediaPickerActivity.onActivityResult(...) in the trunk. Did pulled the branch and there was no changes. or maybe perhaps i did't understand you properly

@ParaskP7 ParaskP7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👋 @Hoossayn !

👋🏾 @ParaskP7 thank you once again for documenting your observation and suggestion.

Again, thank YOU for helping us, I am merely here to support you on your journey and help you become productive with us. 🙇

I reviewed your update and everything LGTM, I just left a minor (🔍) for you to consider, but apart from that, which is optional anyway, everything looks okay and ready to be merged, I'll go ahead and approve this PR now. 🎉

Also you last point about making changes to MediaPickerActivity.onActivityResult(...) in the trunk. Did pulled the branch and there was no changes. or maybe perhaps i did't understand you properly

So, what I was trying to explain is the fact that the version of MediaPickerActivity.onActivityResult(...) in this PR is now different to the version currently on trunk, which has this set of extra suppressions by now:

@Suppress("DEPRECATION", "LongMethod", "NestedBlockDepth")

That, and the fact that this PR has now conflicts (see config/detekt/baseline.xml), means that it might be better for you to update this PR with the latest trunk and resolve any potential conflicts. Then, we will be able to re-trigger CI on it and eventually merge it.

Does that makes sense? 🙏

TAKE_PHOTO -> takeAPhoto()
IMAGE_EDITOR_EDIT_IMAGE -> data?.let { editImageIntent(it) }
else -> data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor (🔍): Consider removing the extra empty line here.

@ParaskP7 ParaskP7 Oct 12, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, this is actually failing CheckStyle as well (see here and here).

Error Description Line
Empty line not allowed before brace 195

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ParaskP7 fix this lint error, also think i should mention that i am usually unable to see whatever you're trying to show me with the buildkite link 🫣, probably some set up i haven't done 👀

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👋 @Hoossayn and thank you for this fix! 👍

...think i should mention that i am usually unable to see whatever you're trying to show me with the buildkite link 🫣, probably some set up i haven't done 👀

Ah, probably you don't (and maybe can't) access Buildkite on your side, I'll confirm that and get back to you.

As such, and until then, I suggest you do the following, observe the CI checks and see what is failing, then try to run in on your side to observe the failure locally as well. For example, when you see CheckStyle failing you could run ./gradlew checkstyle locally and see it's output. You can also check the .buildkit/pipeline.yml file for all the other checks and how you could trigger them locally.

Another tip I can recommend for you to be doing before pushing any code, is to at least run these check locally first:

  • CheckStyle: ./gradlew checkstyle
  • Detekt: ./gradlew detekt
  • Lint: ./gradlew lintWordPressWasabiDebug
  • Test: ./gradlew testWordPressWasabiDebugUnitTest

The above local checks will get you to almost 99% confidence, that is, in terms of the fact that our CI checks will also succeed afterwards and thus help you avoid this ping-pong that is happening atm.

Let me know if the above is helpful to you. 🙏

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👋🏾 @ParaskP7 Above check builds successfully except the last one, which i checked against trunk and was falling too

@Hoossayn

Copy link
Copy Markdown
Contributor Author

👋 @Hoossayn !

👋🏾 @ParaskP7 thank you once again for documenting your observation and suggestion.

Again, thank YOU for helping us, I am merely here to support you on your journey and help you become productive with us. 🙇

I reviewed your update and everything LGTM, I just left a minor (🔍) for you to consider, but apart from that, which is optional anyway, everything looks okay and ready to be merged, I'll go ahead and approve this PR now. 🎉

Also you last point about making changes to MediaPickerActivity.onActivityResult(...) in the trunk. Did pulled the branch and there was no changes. or maybe perhaps i did't understand you properly

So, what I was trying to explain is the fact that the version of MediaPickerActivity.onActivityResult(...) in this PR is now different to the version currently on trunk, which has this set of extra suppressions by now:

@Suppress("DEPRECATION", "LongMethod", "NestedBlockDepth")

That, and the fact that this PR has now conflicts (see config/detekt/baseline.xml), means that it might be better for you to update this PR with the latest trunk and resolve any potential conflicts. Then, we will be able to re-trigger CI on it and eventually merge it.

Does that makes sense? 🙏

MediaPickerActivity.onActivityResult(...) in this PR is now different to the version currently on trunk
This part i understood, Also i'm not sure as to why i don't get the updated version of trunk when i pull trunk to my PR, always says All file are up-to-date 🙃

@ParaskP7

Copy link
Copy Markdown
Contributor

👋 @Hoossayn !

This part i understood, Also i'm not sure as to why i don't get the updated version of trunk when i pull trunk to my PR, always says All file are up-to-date 🙃

Ok, I got the issue here. You need to update your forked repo trunk, that is, sync your fork with us to update your local trunk branch, then, when you try to pull the changes from your local trunk, to your PR, you will indeed notice all those new files, you will not longer see that All files are up-to-date as there are lots of changes since you first forked our repo.

Let me know if the above helps you. 🙏

@Hoossayn

Copy link
Copy Markdown
Contributor Author

👋 @Hoossayn !

This part i understood, Also i'm not sure as to why i don't get the updated version of trunk when i pull trunk to my PR, always says All file are up-to-date 🙃

Ok, I got the issue here. You need to update your forked repo trunk, that is, sync your fork with us to update your local trunk branch, then, when you try to pull the changes from your local trunk, to your PR, you will indeed notice all those new files, you will not longer see that All files are up-to-date as there are lots of changes since you first forked our repo.

Let me know if the above helps you. 🙏

👋🏾 @ParaskP7
Been relying heavily on the IDE GUI (as i'm not a fan of terminal 😑)for it. tried using terminal and seems i have been able to get it to work. kindly take a look again at your convenience

…Warnings_long_method_media_picker

# Conflicts:
#	WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActivity.kt
@ParaskP7

Copy link
Copy Markdown
Contributor

👋 @Hoossayn !

Been relying heavily on the IDE GUI (as i'm not a fan of terminal 😑)for it.

Yea, using the terminal can be doubting. However, FYI, if you are not comfortable, you can also run these checks from your IDE as well, just check the Gradle tab (usually on your right).

Tried using terminal and seems i have been able to get it to work.

Good to know. 👍

kindly take a look again at your convenience

I did take another look and I am afraid, as you will see from your changes, that the merging with the trunk that you did, wasn't quite successful. See the extra .idea/codeStyles/Project.xml change (like last time).

I also saw that you probably resolved the onActivityResult(...) annotation conflict by removing the annotation, which isn't quite right. You should have kept the annotation, but just removed the "LongMethod", "NestedBlockDepth" from it, final result would have looked like this: @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION").

Just like my suggest with our previous such PR, I recommend we start again with a fresh PR, close this one, that is, after you update you fork version of trunk, just like my suggestion above. Wdyt?

@Hoossayn

Copy link
Copy Markdown
Contributor Author
  • Refactor: Extract take a photo method for media picker activity

👋🏾 @ParaskP7
result would have looked like this: @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION").
Any reason we're adding OVERRIDE_DEPRECATION? don't think it was there before

I recommend we start again with a fresh PR,
starting a new PR, i noticed that LongMethod: MediaPickerActivity from baseline.xml is not longer in the trunk, is this correct ?

@ParaskP7

Copy link
Copy Markdown
Contributor

👋 @Hoossayn !

Any reason we're adding OVERRIDE_DEPRECATION? don't think it was there before

Yes, you are right, it wasn't there before, but the codebase is alive and keeps being updated/improving with every day passing by, that's the beauty of it! 😃

You can always try to figure out why a specific changed happened using git blame, or else git annotate, in order to figure out what commit cause what change. Then, you can copy the revision number and search for that. For example, me doing that revealed that this change was part of this PR and this is the actual commit responsible for it. By reading the PR and commit description you will probably find some more details on the why of that change.

Now, if you are wonder why I moved the LongMethod and NestedBlockDepth suppression from the Detekt's baseline.xml file, then you can again apply this trick from above and find that PR and commit responsible for that change. From the commit description you will notice that it is preferable to suppress the warning closer to source, for multiple reasons, but in this specific case, just because the lines on those classes got changed and thus one would either need to update Detekt's baseline.xml, which is not recommended, or just suppress those right there.

I hope the above clarifies things for you, let me know if you need additional clarification. 🙏

starting a new PR, i noticed that LongMethod: MediaPickerActivity from baseline.xml is not longer in the trunk, is this correct ?

Yes, this is correct, as per my above answer, that PR and commit was responsible for that change. So, now, when you create a new PR that will again resolves these LongMethod and NestedBlockDepth issues, you would then just need to remove those specific suppressions from the list of suppressions within that @Suppress annotation, leaving it as @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") in the end.

Does this help? 🙏

@Hoossayn Hoossayn closed this Oct 19, 2022
@Hoossayn

Copy link
Copy Markdown
Contributor Author

New Pull Request here -> #17355

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants