apps-android-commons icon indicating copy to clipboard operation
apps-android-commons copied to clipboard

Fix Detekt TooManyFunctions and LargeClass findings (99 issues — 1 class per PR)

Open nicolas-raoul opened this issue 1 month ago • 19 comments

Part of the post-#7020 Detekt static analysis cleanup.

Scope

Fix the following Detekt findings and remove their <ID> entries from app/detekt-baseline.xml:

  • TooManyFunctions (92 findings)
  • LargeClass (7 findings)

Steps

  1. Delete the matching <ID>... lines from app/detekt-baseline.xml.
  2. Run ./gradlew :app:detekt to see the exact file and line locations of each violation.
  3. Fix the violations in code. Submit 1 class per PR by extracting cohesive helper/delegate classes and verifying unit tests pass.
  4. Manually check that the changes are correct, sensible, and do not break the logic. Keeping some exceptions might make sense sometimes, in that case add a comment explaining why.
  5. Run ./gradlew :app:ktlintCheck :app:detekt testBetaDebugUnitTest and verify all checks pass.
  6. Create a pull request with these changes.

nicolas-raoul avatar Oct 21 '26 02:10 nicolas-raoul

@nicolas-raoul I will like to work on this issue. Please can you assign it to me ?

benndip avatar Oct 21 '26 04:10 benndip

@nicolas-raoul I just release a PR that links to Part of this issue. Please I want to understand something:

I am supposed to release the fix for one class at a time with a separate PR right ? and I release a new PR for the fix of a class only when the previous one is approved right ? or I just release them on the go ?

Also asking because I see about 92 classes to be resolved

benndip avatar Oct 22 '26 00:10 benndip

No need to wait for pull requests to be approved. In other words, you can ask to be assigned as soon as you have sent pull requests for all of your assigned issues. :-)

nicolas-raoul avatar Oct 22 '26 14:10 nicolas-raoul

@nicolas-raoul please I was asking that here, since I am supposed to open 1 class per PR, how should it be done ? do I just go ahead fixing each of the classes and opening PRs and linking them to this issue ?

benndip avatar Oct 23 '26 07:10 benndip

Ah, I think I understand now. A few questions:

  1. How long do you think it would take to fix all classes?
  2. Would one issue/PR per class be too much overhead?
  3. How about 10 classes of your choice per PR? (and this issue would be assigned to one person at a time)
  4. Many TooManyFunctions flags might be due to Compose, so maybe better wait for https://github.com/commons-app/apps-android-commons/issues/7051#issuecomment-6358642466 to be fixed first?

Thanks!

nicolas-raoul avatar Oct 23 '26 07:10 nicolas-raoul

@nicolas-raoul

  1. At the pace of the CategoriesModel pull request, all of the remaining classes would take many weeks. A lot of them are small and similar, so those can go much faster in batches. The slow ones are the very large screens, such as NearbyParentFragment and MediaDetailFragment.
  2. Yes. One pull request per class is a lot of overhead. Each one edits detekt-baseline.xml, so they also conflict with each other. #7077 already needed a merge from main for that reason.
  3. Ten classes per pull request works well when the classes are small and of the same kind, for example the Dagger modules, or the Room and Retrofit types. I would still keep each very large class in its own pull request, because those diffs are already big. One person at a time on this issue is fine, so the baseline edits do not collide.
  4. I would not wait for #7051. That comment is about FunctionNaming on @Composable functions, which is a different Detekt rule. The TooManyFunctions classes here are mostly activities, fragments, Dagger modules, and Room or API types. Waiting on that issue would not clear this list.

benndip avatar Oct 23 '26 09:10 benndip

Thanks for the research!

Would you mind writing here "buckets" of classes that you think would be reasonably sized? If you have time :-)

nicolas-raoul avatar Oct 23 '26 15:10 nicolas-raoul

Alright, sure. I am doing that now

benndip avatar Oct 23 '26 16:10 benndip

Hi @benndip and @nicolas-raoul,

I've created (https://github.com/commons-app/apps-android-commons/pull/7104) to address the Detekt naming convention findings in issue #7051.

The PR fixes the reported naming violations, updates the Detekt configuration for @Composable functions, and removes the resolved findings from the baseline. I've also run the required checks locally, and they passed.

Could you please review the PR when you have time? Thank you!

devendrachoudharycodes avatar Oct 23 '26 18:10 devendrachoudharycodes

Nice @devendrachoudharycodes I will review #7104 and leave my feeback soon.

Thank you

benndip avatar Oct 23 '26 18:10 benndip

concerning the buckets you asked about @nicolas-raoul

Here are the buckets I would use. Each one is a separate pull request.

  1. Dagger screen bindings: ActivityBuilderModule, FragmentBuilderModule, CommonsApplicationComponent
  2. Dagger provider modules: CommonsApplicationModule, NetworkingModule
  3. Room: AppDatabase, ContributionDao, Converters
  4. Small interfaces and their store: KeyValueStore, BasicKvStore, MediaInterface
  5. MVP contracts: CategoriesContract, DepictsContract (both nested types), ExploreMapContract, UploadContract, UploadMediaDetailsContract (both nested types)
  6. Data holders: ExtMetadata, ImageInfo, MwQueryPage, MwQueryResult, NearbyResultItem, PageTitle, WikiSite

A few related classes per pull request.

  1. Gesture detectors: MultiGestureListener, MultiPointerGestureDetector, TransformGestureDetector
  2. Zoom base types: ZoomableController, AbstractAnimatedZoomableController
  3. Explore shells: BasePagingFragment, ExploreListRootFragment, ExploreMapRootFragment, ExploreMapPresenter, SearchActivity
  4. Bookmarks: BookmarkListRootFragment, BookmarkPicturesFragment
  5. Nearby helpers: CommonPlaceClickActions, LocationServiceManager
  6. Upload category step: UploadCategoriesFragment, CategoriesPresenter, MediaLicenseFragment
  7. Depicts step: DepictsFragment, DepictsPresenter
  8. Upload model and presenter: UploadModel, UploadRepository, UploadMediaPresenter
  9. Contributions storage: ContributionsLocalDataSource, ContributionsRepository
  10. Smaller API clients: MediaClient, WikidataEditService
  11. File picking: FilePicker, PickedFiles
  12. Custom selector pieces: ImageAdapter, ImageFragment
  13. Edit overlay views: CropOverlayView, BlurOverlayView
  14. Profile screens: AboutActivity, ProfileActivity, LeaderboardFragment
  15. Other smaller screens: NotificationActivity, ReviewActivity, MoreBottomSheetFragment, DescriptionEditActivity, CategoryDetailsActivity, WikidataItemDetailsActivity
  16. Small utilities: AppLanguageLookUpTable, ImageUtils, RandomAccessFileExifWriter

One class per pull request. These files are already about 600 to 3,200 lines, so a batch would be too large to review.

  1. NearbyParentFragment
  2. NearbyParentFragmentPresenter
  3. MediaDetailFragment
  4. MediaDetailPagerFragment
  5. MediaDetailFragmentUnitTests
  6. ExploreMapFragment
  7. ContributionsFragment
  8. ContributionsListFragment
  9. ContributionController
  10. MainActivity
  11. UploadActivity
  12. UploadMediaDetailFragment
  13. UploadWorker
  14. OkHttpJsonApiClient
  15. EditActivity
  16. CustomSelectorActivity
  17. LocationPickerActivity
  18. LoginActivity
  19. ZoomableActivity
  20. DefaultZoomableController
  21. ZoomableDraweeView
  22. SettingsFragment
  23. AchievementsFragment

Buckets 1–6 are small reviews because the change is a comment, not a redesign. Buckets 23–45 stay alone because each file is already a large review on its own.

benndip avatar Oct 23 '26 18:10 benndip

Sounds good, thanks a lot! 🙂

If you have time, would you mind creating all of these issues using the GitHub API, with a helpful description of the steps to accomplish (for instance validating and removing exception lines)?

I recommend starting with a single exception at first, to make sure it is correctly created.

I will then mark these issues as beginner-friendly.

nicolas-raoul avatar Oct 24 '26 01:10 nicolas-raoul

okayy, sure. I will do that, and let you know

benndip avatar Oct 24 '26 03:10 benndip

@nicolas-raoul I have created all of the issues as you requested after creating the first one and making sure it was well created.

Now you can add the "good-first-issue" labels to them. They also have steps to fix

benndip avatar Oct 24 '26 14:10 benndip

Done, thanks

Feel free to close this issue if you think all remaining work is in the issues you created, and that there is nothing left to do here. :-)

nicolas-raoul avatar Oct 25 '26 10:10 nicolas-raoul

@nicolas-raoul I think we can close this issue. However, I don't have permission to close this issue

benndip avatar Oct 26 '26 09:10 benndip

"Move each chosen group into a new helper class in the same feature. The original class keeps its role and calls the helper."

Always using helpers sounds like an anti-pattern. Would you mind removing that sentence from the issues? Thanks! :-)

nicolas-raoul avatar Oct 27 '26 12:10 nicolas-raoul

24. > "Move each chosen group into a new helper class in the same feature. The original class keeps its role and calls the helper."

 Always using helpers sounds like an anti-pattern. Would you mind removing that sentence from the issues? Thanks! :-)

Okay, let me do that. I see the sentence from issue #7122 Will check others for any occurrences

benndip avatar Oct 27 '26 14:10 benndip

@nicolas-raoul I have removed the user of "helpers" from the neccessary issues linked to this one as requested. Proposed something better

benndip avatar Oct 29 '26 01:10 benndip