Skip to content

chore: eliminate CA2024 warnings and enforce TreatWarningsAsErrors#225

Merged
tylerkron merged 1 commit into
mainfrom
chore/treat-warnings-as-errors
May 23, 2026
Merged

chore: eliminate CA2024 warnings and enforce TreatWarningsAsErrors#225
tylerkron merged 1 commit into
mainfrom
chore/treat-warnings-as-errors

Conversation

@tylerkron
Copy link
Copy Markdown
Contributor

Closes #220.

Summary

  • Fix the two CA2024 warnings (SdCardJsonFileParser.cs:45, SdCardCsvFileParser.cs:53) by driving the read loop off ReadLineAsync's null return instead of the synchronous EndOfStream property.
  • Enable <TreatWarningsAsErrors>true</TreatWarningsAsErrors> in both Daqifi.Core.csproj and Daqifi.Core.Tests.csproj so new warnings fail the build instead of accumulating.

Behavior note

Cancellation surfaces from ReadLineAsync(ct) as TaskCanceledException (a subclass of OperationCanceledException), where the old loop threw OperationCanceledException directly via ct.ThrowIfCancellationRequested(). Callers using catch (OperationCanceledException) are unaffected. The two cancellation tests were updated to use Assert.ThrowsAnyAsync<OperationCanceledException> so they accept either type.

Test plan

  • dotnet build -c Release --no-incremental0 Warning(s), 0 Error(s) on both net9.0 and net10.0.
  • dotnet test -c Release → 993 passed / 0 failed / 2 skipped on both target frameworks.
  • Sanity-checked locally by dropping a file with CS0414 (private field assigned but never used) — build correctly failed with error CS0414 instead of a warning. Probe file then removed.
  • CI passes.

🤖 Generated with Claude Code

…loses #220)

- Drive the SD-card JSON and CSV read loops off ReadLineAsync's null
  return rather than the synchronous EndOfStream property, resolving
  the two CA2024 warnings emitted on net10.0.
- Enable <TreatWarningsAsErrors>true</TreatWarningsAsErrors> in both
  Daqifi.Core and Daqifi.Core.Tests so any new warning fails the
  build instead of accumulating.
- Cancellation now surfaces from ReadLineAsync(ct) as TaskCanceledException
  (a subclass of OperationCanceledException). The two cancellation
  tests now use Assert.ThrowsAnyAsync<OperationCanceledException> to
  accept either type. External callers using `catch (OperationCanceledException)`
  are unaffected.

Verified: dotnet build -c Release --no-incremental → 0 warnings on
net9.0 and net10.0; all 993 tests pass on both target frameworks; a
deliberate CS0414 probe confirmed the build now errors on warnings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tylerkron tylerkron requested a review from a team as a code owner May 23, 2026 21:28
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Eliminate CA2024 warnings and enforce TreatWarningsAsErrors

🐞 Bug fix ✨ Enhancement

Grey Divider

Walkthroughs

Description
• Eliminate CA2024 warnings by refactoring read loops to use ReadLineAsync null return
• Enable TreatWarningsAsErrors in both project files to prevent warning accumulation
• Update cancellation tests to accept TaskCanceledException from async read operations
• Improve code robustness by driving loop termination off async method return value
Diagram
flowchart LR
  A["Read Loop Pattern"] -->|"Replace EndOfStream"| B["Use ReadLineAsync null return"]
  B -->|"Refactor"| C["SdCardJsonFileParser.cs"]
  B -->|"Refactor"| D["SdCardCsvFileParser.cs"]
  E["Project Configuration"] -->|"Enable"| F["TreatWarningsAsErrors"]
  F -->|"Apply to"| G["Daqifi.Core.csproj"]
  F -->|"Apply to"| H["Daqifi.Core.Tests.csproj"]
  I["Cancellation Handling"] -->|"Update tests"| J["Use ThrowsAnyAsync"]
  J -->|"Accept"| K["OperationCanceledException subclasses"]

Loading

File Changes

1. src/Daqifi.Core/Device/SdCard/SdCardJsonFileParser.cs 🐞 Bug fix +2/-3

Refactor JSON parser read loop for CA2024 compliance

• Refactored read loop to drive off ReadLineAsync null return instead of EndOfStream property
• Removed explicit ct.ThrowIfCancellationRequested() call
• Eliminated CA2024 warning on net10.0 by using async-first loop termination

src/Daqifi.Core/Device/SdCard/SdCardJsonFileParser.cs


2. src/Daqifi.Core/Device/SdCard/SdCardCsvFileParser.cs 🐞 Bug fix +2/-3

Refactor CSV parser read loop for CA2024 compliance

• Refactored read loop to drive off ReadLineAsync null return instead of EndOfStream property
• Removed explicit ct.ThrowIfCancellationRequested() call
• Eliminated CA2024 warning on net10.0 by using async-first loop termination

src/Daqifi.Core/Device/SdCard/SdCardCsvFileParser.cs


3. src/Daqifi.Core/Daqifi.Core.csproj ⚙️ Configuration changes +1/-0

Enable TreatWarningsAsErrors in Core project

• Added true property to project configuration
• Enforces strict warning handling to prevent warning accumulation in builds

src/Daqifi.Core/Daqifi.Core.csproj


View more (3)
4. src/Daqifi.Core.Tests/Daqifi.Core.Tests.csproj ⚙️ Configuration changes +1/-0

Enable TreatWarningsAsErrors in Tests project

• Added true property to project configuration
• Enforces strict warning handling to prevent warning accumulation in test builds

src/Daqifi.Core.Tests/Daqifi.Core.Tests.csproj


5. src/Daqifi.Core.Tests/Device/SdCard/SdCardJsonFileParserTests.cs 🧪 Tests +3/-2

Update JSON parser cancellation test assertion

• Updated ParseAsync_CancellationToken_ThrowsOnCancel test to use Assert.ThrowsAnyAsync
• Added comment explaining that ReadLineAsync surfaces cancellation as TaskCanceledException
 subclass
• Ensures test accepts both OperationCanceledException and TaskCanceledException types

src/Daqifi.Core.Tests/Device/SdCard/SdCardJsonFileParserTests.cs


6. src/Daqifi.Core.Tests/Device/SdCard/SdCardCsvFileParserTests.cs 🧪 Tests +2/-1

Update CSV parser cancellation test assertion

• Updated ParseAsync_CancellationDuringRead_ThrowsOperationCanceled test to use
 Assert.ThrowsAnyAsync
• Added comment explaining that ReadLineAsync surfaces cancellation as TaskCanceledException
 subclass
• Ensures test accepts both OperationCanceledException and TaskCanceledException types

src/Daqifi.Core.Tests/Device/SdCard/SdCardCsvFileParserTests.cs


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented May 23, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@tylerkron tylerkron merged commit 257776f into main May 23, 2026
1 check passed
@tylerkron tylerkron deleted the chore/treat-warnings-as-errors branch May 23, 2026 21:34
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.

chore: eliminate build warnings and enforce TreatWarningsAsErrors

1 participant