CodeQL 7: refactor: tighten foreach-to-LINQ where it improves the call site#195
Open
rlorenzo wants to merge 1 commit into
Open
CodeQL 7: refactor: tighten foreach-to-LINQ where it improves the call site#195rlorenzo wants to merge 1 commit into
rlorenzo 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. |
Contributor
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)