Skip to content

CodeQL 13: chore: additional style fixes (ternary, complex-block, implicit-conversion)#199

Open
rlorenzo wants to merge 1 commit into
mainfrom
codeql/13-final-sweep
Open

CodeQL 13: chore: additional style fixes (ternary, complex-block, implicit-conversion)#199
rlorenzo wants to merge 1 commit into
mainfrom
codeql/13-final-sweep

Conversation

@rlorenzo
Copy link
Copy Markdown
Contributor

@rlorenzo rlorenzo commented May 13, 2026

Summary

Final sweep of CodeQL style alerts that earlier PRs left as wontfix:

  • js/implicit-operand-conversion (2): course-import-dialog.test.ts:72,96 - narrow the union check by combining typeof === 'object' with instanceof Error, then explicit as Error cast on the truthy branch.
  • cs/complex-block (1): MeritMultiYearService.CalculateMedian - five for-loops appending to a List collapsed into chained Enumerable.Repeat(...).Concat(...).
  • cs/missed-ternary-operator (5) that were deferred:
    • GradYearClassLevel.cs:63 - case-4 if-else assignment
    • RotationsController.cs:63 - serviceId.HasValue ? GetRotationsByServiceAsync : GetRotationsAsync
    • UinformService.cs:247 - response.IsSuccessStatusCode ? Deserialize : new ErrorResponse
    • EffortAuditService.cs:605 - termCode-keyed IQueryable selection
    • Also picks up the earlier useless-tostring fix on GradYearClassLevel.cs:57,60,69 (no-op vs PR CodeQL 12: chore: style sweep for remaining CodeQL alerts #198 which has the same change).

Context

Thirteenth 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

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f9b4c695-8113-4f71-ad7e-01d9f09939ac

📥 Commits

Reviewing files that changed from the base of the PR and between f45f6b7 and 9a6e6c1.

📒 Files selected for processing (4)
  • VueApp/src/Effort/__tests__/course-import-dialog.test.ts
  • web/Areas/ClinicalScheduler/Controllers/RotationsController.cs
  • web/Areas/Effort/Services/EffortAuditService.cs
  • web/Areas/Effort/Services/MeritMultiYearService.cs

📝 Walkthrough

Walkthrough

Four files across test suites and services are refactored to use ternary expressions and LINQ pipelines. Test error handling now validates object types before instanceof checks. Service methods consolidate conditional branches into single assignments with ternary operators or LINQ chains, removing nested if/else blocks without changing behavior.

Changes

Code simplification refactoring

Layer / File(s) Summary
Test error type checking refinement
VueApp/src/Effort/__tests__/course-import-dialog.test.ts
Course import dialog tests now use stricter instanceof Error type checks combined with object type validation via a computed isError boolean, replacing inline conditionals in both import and search error tests.
Service control flow simplification
web/Areas/ClinicalScheduler/Controllers/RotationsController.cs, web/Areas/Effort/Services/EffortAuditService.cs, web/Areas/Effort/Services/MeritMultiYearService.cs
Three services replace if/else blocks with ternary expressions and convert explicit loops to LINQ. RotationsController uses a ternary for async method selection; EffortAuditService builds courseIds with conditional term-scoped query logic; MeritMultiYearService clamps response counts and refactors median response collection with LINQ Repeat/Concat.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • bsedwards
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning PR changes are unrelated to linked issue #39, which requires upgrading System.Linq.Dynamic.Core package and verifying compatibility changes. This PR fixes CodeQL style issues but does not address the package upgrade or security fix CVE-2024-51417. Issue #39 requires a separate PR with package.csproj updates and compatibility verification.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately describes the PR's main focus: CodeQL style fixes for ternary operators, complex blocks, and implicit conversions across multiple files.
Description check ✅ Passed Description clearly explains the CodeQL alerts being fixed with specific file locations and the refactoring approaches applied to each.
Out of Scope Changes check ✅ Passed All code changes align with stated CodeQL style cleanup objectives; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codeql/13-final-sweep

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 15.78947% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.02%. Comparing base (f45f6b7) to head (9a6e6c1).

Files with missing lines Patch % Lines
web/Areas/Effort/Services/MeritMultiYearService.cs 0.00% 12 Missing ⚠️
web/Areas/Effort/Services/EffortAuditService.cs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #199      +/-   ##
==========================================
- Coverage   43.02%   43.02%   -0.01%     
==========================================
  Files         881      881              
  Lines       51436    51432       -4     
  Branches     4812     4807       -5     
==========================================
- Hits        22131    22127       -4     
  Misses      28779    28779              
  Partials      526      526              
Flag Coverage Δ
backend 43.09% <15.78%> (-0.01%) ⬇️
frontend 41.47% <ø> (ø)

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.

@rlorenzo
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/Areas/Effort/Services/MeritMultiYearService.cs`:
- Around line 868-875: The code builds the responses list using
Enumerable.Repeat with n1..n5 but doesn't validate those counts; negative counts
will throw ArgumentOutOfRangeException. Before calling Enumerable.Repeat (the
block that constructs responses), clamp or sanitize the n1, n2, n3, n4, n5
values to a non-negative integer (e.g., Math.Max(0, nX) or a small helper
NormalizeCount) and then use those sanitized variables when creating responses
so Enumerable.Repeat(...) never receives a negative count.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 079a90be-124e-4667-b457-197ab51abdda

📥 Commits

Reviewing files that changed from the base of the PR and between 38de1ad and 8fc03de.

📒 Files selected for processing (6)
  • VueApp/src/Effort/__tests__/course-import-dialog.test.ts
  • web/Areas/ClinicalScheduler/Controllers/RotationsController.cs
  • web/Areas/Effort/Services/EffortAuditService.cs
  • web/Areas/Effort/Services/MeritMultiYearService.cs
  • web/Areas/RAPS/Services/UinformService.cs
  • web/Areas/Students/Services/GradYearClassLevel.cs

Comment thread web/Areas/Effort/Services/MeritMultiYearService.cs
@rlorenzo rlorenzo force-pushed the codeql/13-final-sweep branch from e9d677a to 9a6e6c1 Compare May 21, 2026 07:55
@rlorenzo
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR performs a small CodeQL style cleanup across backend C# and frontend test code without changing the intended application behavior.

Changes:

  • Rewrites median response list construction using LINQ while handling negative counts safely.
  • Converts simple conditional assignments to ternary expressions.
  • Narrows test-side unknown error checks before accessing Error.message.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
web/Areas/Effort/Services/MeritMultiYearService.cs Refactors median response list construction with Enumerable.Repeat/Concat.
web/Areas/Effort/Services/EffortAuditService.cs Collapses conditional audit course query selection into a ternary assignment.
web/Areas/ClinicalScheduler/Controllers/RotationsController.cs Simplifies service-based rotation loading with a ternary assignment.
VueApp/src/Effort/__tests__/course-import-dialog.test.ts Adds explicit object narrowing before instanceof Error checks in tests.

@rlorenzo
Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

✅ Actions performed

Full review triggered.

@rlorenzo rlorenzo requested a review from bsedwards May 28, 2026 00:06
@rlorenzo
Copy link
Copy Markdown
Contributor Author

@bsedwards On TEST. Mainly cosmetic style changes reported by CodeQL.

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.

3 participants