CodeQL 7: refactor: tighten foreach-to-LINQ where it improves the call site#195
CodeQL 7: refactor: tighten foreach-to-LINQ where it improves the call site#195rlorenzo wants to merge 1 commit into
Conversation
Bundle ReportBundle size has no change ✅ |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #195 +/- ##
=======================================
Coverage 42.96% 42.97%
=======================================
Files 877 877
Lines 51468 51452 -16
Branches 4802 4794 -8
=======================================
- Hits 22113 22111 -2
+ Misses 28831 28817 -14
Partials 524 524
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughFive methods across role management, course/session transformations, and assessment processing were rewritten from imperative foreach/if patterns to LINQ expressions (Select, GroupBy, Where, Any) with no public API or behavioral changes. ChangesRefactoring to LINQ Expressions
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
Summary
Closes 6 of 34
cs/linq/missed-*alerts where theforeach-to-LINQ conversion makes the intent clearer:UserHelper.IsInRole- claim-search loop →claims.Any(c => c.Type == ClaimTypes.Role && c.Value == roleName)(also collapses the surrounding null guard).CrestCourseService.CourseSessionOfferingsToCourses/…Sessions- staging-list + foreach-Add pattern →csos.GroupBy(...).Select(g => new Course/Session(...)).ToList().AssessmentController.GetAssessmentsForStudent- build-and-mutate loop →assessmentsList.Select(a => { … }).ToList().RoleTemplatesController.Apply-foreach (... in preview.Roles) { if (!UserHasRole) … }→foreach (... in preview.Roles.Where(r => !r.UserHasRole)).RoleViewsdelete loop - compoundiffilter hoisted into theforeach … in roleMembers.Where(...).Also fixed two stray tab-indented lines in
RoleViews.csthatdotnet formatflagged.Why 28 alerts are not addressed
The remaining 28
cs/linq/missed-selectalerts all live in PDF/Excel cell-generation loops in the Effort report services -TeachingActivityService,MeritReportService,SchoolSummaryService,DeptSummaryService,MeritMultiYearService,EvaluationReportService,MeritSummaryService. Pattern is:The
var val = …is what CodeQL identifies as a "mapping", but the surrounding body isQuestPDF.table.Cell()…/ClosedXML.ws.Cell()…side effects, not collection-building. Forcing aSelecthere would just add a tuple-deconstructionforeachover a.Select(t => (Type: t, Val: …))with the same side-effectful body - more code, same behavior, lower readability. These are dismissible as wontfix-by-design on the CodeQL dashboard.Context
Seventh in the
CodeQL N:cleanup series (after #189, #190, #191, #192, #193, #194).Test plan
npm run test:backend- 1946 tests passingnpm run verify:build- clean (0 errors)