chore(codeql): readonly fields and TryGetValue cleanups#224
Open
rlorenzo wants to merge 1 commit into
Open
Conversation
Mark single-assignment static fields readonly (VMACSService.sharedClient, RolesTests SQLite connection/options) and replace ContainsKey + indexer double lookups with TryGetValue (RotationsController recent-clinicians map, EmergencyContact test). Resolves cs/missed-readonly-modifier and cs/inefficient-containskey.
Bundle ReportBundle size has no change ✅ |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #224 +/- ##
=======================================
Coverage 44.49% 44.49%
=======================================
Files 895 895
Lines 51655 51655
Branches 4812 4812
=======================================
Hits 22983 22983
Misses 28108 28108
Partials 564 564
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
Pull request overview
This PR applies small, behavior-preserving CodeQL cleanups across the web app and test suite by (1) marking single-assignment static fields as readonly and (2) replacing ContainsKey + indexer patterns with TryGetValue to avoid double lookups.
Changes:
- Marked static
HttpClientand SQLite test fixtures asreadonlywhere they are never reassigned. - Replaced
ContainsKey+ indexer withTryGetValueinRotationsControllerand an emergency-contact unit test to avoid redundant dictionary lookups.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| web/Areas/Directory/Services/VMACSService.cs | Marks the shared static HttpClient as readonly. |
| web/Areas/ClinicalScheduler/Controllers/RotationsController.cs | Uses TryGetValue for the recent-clinicians lookup to avoid double dictionary access. |
| test/Students/EmergencyContactControllerTests.cs | Uses TryGetValue for a single-lookup assertion on validation errors. |
| test/RAPS/RolesTests.cs | Marks static SQLite connection/options as readonly. |
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.
What
Five small CodeQL cleanups, behavior-preserving:
readonlyon single-assignment static fields (verified never reassigned):VMACSService.sharedClientRolesTests._sqlLiteConnection,_sqlLiteContextOptionsTryGetValueinstead ofContainsKey+ indexer (single lookup):RotationsController.BuildRecentCliniciansListrecent-clinicians map — usedTryGetValue(notGetValueOrDefault) to preserve exact behavior, sincePersonDisplayFullNameis nullableEmergencyContactControllerTestsphone-validation assertionResolves
cs/missed-readonly-modifier(#211, #212, #213) andcs/inefficient-containskey(#475, #479).Scope notes
Other alerts in the same batch were dismissed rather than changed:
cs/local-shadows-member×3 (idiomatic configure-setters) andcs/missed-ternary-operator×4 (subjective style / one not type-valid as a ternary).The agy review surfaced a separate pre-existing URL-encoding concern in
VMACSService.Search(DB-sourcedloginID, low exploitability) — left out of this PR to keep it scoped; tracked as a follow-up.