Skip to content

CodeQL 14: refactor: convert foreach-add patterns to LINQ Select#200

Open
rlorenzo wants to merge 2 commits into
mainfrom
codeql/14-effort-pdf-select
Open

CodeQL 14: refactor: convert foreach-add patterns to LINQ Select#200
rlorenzo wants to merge 2 commits into
mainfrom
codeql/14-effort-pdf-select

Conversation

@rlorenzo
Copy link
Copy Markdown
Contributor

@rlorenzo rlorenzo commented May 13, 2026

Summary

Closes 3 of the 28 cs/linq/missed-select alerts where the foreach body is a simple build-and-add into a context/list:

  • CourseController.AddSessionCompetency (line 227) - foreach (var levelId in LevelIds) { var x = new SessionCompetency(...); context.Add(x); }context.AddRange(LevelIds.Select(levelId => new SessionCompetency(...))).
  • CourseController.UpdateSessionCompetency (line 273, same pattern).
  • IndividualSearchResult (line 130) - foreach (var r in results) { EmailHost = r.Split("@")[^1]; }Select(...) to materialize the list, then guard on count before assigning the last entry. Semantically identical.

Not addressed (still open)

The remaining 25 cs/linq/missed-select alerts are all in PDF/Excel cell-generation loops in Effort report services where the foreach body calls side-effectful QuestPDF.table.Cell()…Text(…) or ClosedXML.ws.Cell()…Value. Forcing those into Select just renames a single local without removing the iteration or its side effects, so the resulting code is the same length with worse readability. Those should be dismissed at the dashboard.

Context

Fourteenth in the CodeQL N: cleanup series.

Test plan

  • npm run test:backend - 1946 tests passing
  • Pre-commit lint+test+verify all passed

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • review-ready

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 00434691-f5b5-45f8-a915-3f88b8034b83

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codeql/14-effort-pdf-select

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 13, 2026

Codecov Report

❌ Patch coverage is 0% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.96%. Comparing base (38de1ad) to head (768fba1).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
web/Areas/CTS/Controllers/CourseController.cs 0.00% 15 Missing ⚠️
...b/Areas/Directory/Models/IndividualSearchResult.cs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #200   +/-   ##
=======================================
  Coverage   42.96%   42.96%           
=======================================
  Files         877      877           
  Lines       51468    51462    -6     
  Branches     4802     4800    -2     
=======================================
  Hits        22113    22113           
+ Misses      28831    28825    -6     
  Partials      524      524           
Flag Coverage Δ
backend 43.04% <0.00%> (+<0.01%) ⬆️
frontend 41.34% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

S2971: SqlQueryRaw().ToList().Select(...) materializes the entire
result set into a List just to throw it away. Replace with
AsEnumerable() — same effect of switching to LINQ-to-objects so the
Split isn't translated to SQL, without the extra allocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants