Fix Detekt TooManyFunctions and LargeClass findings (99 issues — 1 class per PR)
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
- Delete the matching
<ID>...lines fromapp/detekt-baseline.xml. - Run
./gradlew :app:detektto see the exact file and line locations of each violation. - Fix the violations in code. Submit 1 class per PR by extracting cohesive helper/delegate classes and verifying unit tests pass.
- 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.
- Run
./gradlew :app:ktlintCheck :app:detekt testBetaDebugUnitTestand verify all checks pass. - Create a pull request with these changes.
@nicolas-raoul I will like to work on this issue. Please can you assign it to me ?
@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
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 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 ?
Ah, I think I understand now. A few questions:
- How long do you think it would take to fix all classes?
- Would one issue/PR per class be too much overhead?
- How about 10 classes of your choice per PR? (and this issue would be assigned to one person at a time)
- 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
- At the pace of the
CategoriesModelpull 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 asNearbyParentFragmentandMediaDetailFragment. - 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 frommainfor that reason. - 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.
- I would not wait for #7051. That comment is about
FunctionNamingon@Composablefunctions, which is a different Detekt rule. TheTooManyFunctionsclasses here are mostly activities, fragments, Dagger modules, and Room or API types. Waiting on that issue would not clear this list.
Thanks for the research!
Would you mind writing here "buckets" of classes that you think would be reasonably sized? If you have time :-)
Alright, sure. I am doing that now
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!
Nice @devendrachoudharycodes I will review #7104 and leave my feeback soon.
Thank you
concerning the buckets you asked about @nicolas-raoul
Here are the buckets I would use. Each one is a separate pull request.
- Dagger screen bindings:
ActivityBuilderModule,FragmentBuilderModule,CommonsApplicationComponent - Dagger provider modules:
CommonsApplicationModule,NetworkingModule - Room:
AppDatabase,ContributionDao,Converters - Small interfaces and their store:
KeyValueStore,BasicKvStore,MediaInterface - MVP contracts:
CategoriesContract,DepictsContract(both nested types),ExploreMapContract,UploadContract,UploadMediaDetailsContract(both nested types) - Data holders:
ExtMetadata,ImageInfo,MwQueryPage,MwQueryResult,NearbyResultItem,PageTitle,WikiSite
A few related classes per pull request.
- Gesture detectors:
MultiGestureListener,MultiPointerGestureDetector,TransformGestureDetector - Zoom base types:
ZoomableController,AbstractAnimatedZoomableController - Explore shells:
BasePagingFragment,ExploreListRootFragment,ExploreMapRootFragment,ExploreMapPresenter,SearchActivity - Bookmarks:
BookmarkListRootFragment,BookmarkPicturesFragment - Nearby helpers:
CommonPlaceClickActions,LocationServiceManager - Upload category step:
UploadCategoriesFragment,CategoriesPresenter,MediaLicenseFragment - Depicts step:
DepictsFragment,DepictsPresenter - Upload model and presenter:
UploadModel,UploadRepository,UploadMediaPresenter - Contributions storage:
ContributionsLocalDataSource,ContributionsRepository - Smaller API clients:
MediaClient,WikidataEditService - File picking:
FilePicker,PickedFiles - Custom selector pieces:
ImageAdapter,ImageFragment - Edit overlay views:
CropOverlayView,BlurOverlayView - Profile screens:
AboutActivity,ProfileActivity,LeaderboardFragment - Other smaller screens:
NotificationActivity,ReviewActivity,MoreBottomSheetFragment,DescriptionEditActivity,CategoryDetailsActivity,WikidataItemDetailsActivity - 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.
NearbyParentFragmentNearbyParentFragmentPresenterMediaDetailFragmentMediaDetailPagerFragmentMediaDetailFragmentUnitTestsExploreMapFragmentContributionsFragmentContributionsListFragmentContributionControllerMainActivityUploadActivityUploadMediaDetailFragmentUploadWorkerOkHttpJsonApiClientEditActivityCustomSelectorActivityLocationPickerActivityLoginActivityZoomableActivityDefaultZoomableControllerZoomableDraweeViewSettingsFragmentAchievementsFragment
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.
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.
okayy, sure. I will do that, and let you know
@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
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 I think we can close this issue. However, I don't have permission to close this issue
"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! :-)
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
@nicolas-raoul I have removed the user of "helpers" from the neccessary issues linked to this one as requested. Proposed something better