Skip to content

Fix LINQ missed-where warnings, cognitive complexity violations, Assert.IsTrue code smells, and linter design doc#137

Merged
Malcolmnixon merged 4 commits intomainfrom
copilot/fix-linq-missed-where-issues
Mar 28, 2026
Merged

Fix LINQ missed-where warnings, cognitive complexity violations, Assert.IsTrue code smells, and linter design doc#137
Malcolmnixon merged 4 commits intomainfrom
copilot/fix-linq-missed-where-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 28, 2026

Addresses four categories of static analysis violations in Linter.cs and IntegrationTests.cs: implicit sequence filtering in foreach loops, cognitive complexity exceeding the S3776 threshold, and use of Assert.IsTrue(x.Contains(y)) instead of Assert.Contains. Also updates the linter unit design documentation to match the refactored method structure, and improves error message context for duplicate requirement IDs.

Description

IntegrationTests.cs — MSTEST0037

  • Replaced Assert.IsTrue(x.Contains(y)) with Assert.Contains(y, x) on 4 assertions, consistent with existing patterns in the test suite.

Linter.cscs/linq/missed-where (lines 454, 469, 528, 615)

  • Replaced implicit if filters inside foreach with explicit .OfType<>().Where().Select() chains.
  • Simplified GetStringList to a single LINQ expression eliminating the loop entirely.

Linter.cs — S3776 Cognitive Complexity

Extracted 7 focused helper methods to bring all four violating methods within the limit of 15:

Method Before After Extracted helpers
LintFile 16 ≤15 LintIncludes
LintDocumentRoot 17 ≤15 LintDocumentSections, LintDocumentMappings
LintSection 20 ≤15 LintSectionRequirements, LintSectionChildren
LintRequirement 27 ≤15 LintRequirementId, LintRequirementTitle

Linter.csLintRequirementId duplicate-ID error context

  • LintRequirementId now returns reqId (instead of null) in the duplicate-ID case. The ID is still not added to seenIds, and the issue count is still incremented. This allows LintRequirementTitle to produce the more actionable "requirement 'REQ-123' missing required field 'title'" message rather than the generic fallback, with no cascading side effects.

docs/design/linter.md — Design documentation update

The linter unit design document previously referenced three method names (LintSections, LintRequirements, LintMappings) that were aspirational design names and never existed in the code. Updated to reflect the actual implementation:

  • Removed the three non-existent method sections.
  • Added accurate entries for all 7 new helper methods: LintIncludes, LintDocumentSections, LintDocumentMappings, LintSectionRequirements, LintSectionChildren, LintRequirementId, and LintRequirementTitle.
  • Updated LintFile, LintDocumentRoot, LintSection, LintRequirement, and LintMapping to correctly describe their delegation to the new helpers.
  • Updated LintRequirementId step 3 to reflect the corrected reqId return in the duplicate case.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code quality improvement

Pre-Submission Checklist

Before submitting this pull request, ensure you have completed the following:

Build and Test

  • Code builds successfully: dotnet build --configuration Release
  • All unit tests pass: dotnet test --configuration Release
  • Self-validation tests pass:
    dotnet run --project src/DemaConsulting.ReqStream --configuration Release --framework net10.0
    --no-build -- --validate
  • Code produces zero warnings

Code Quality

  • Code formatting is correct: dotnet format --verify-no-changes
  • New code has appropriate XML documentation comments
  • Static analyzer warnings have been addressed

Quality Checks

Please run the following checks before submitting:

  • Spell checker passes: cspell "**/*.{md,cs}"
  • Markdown linter passes: markdownlint "**/*.md"
  • YAML linter passes: yamllint .

Testing

  • Added unit tests for new functionality
  • Updated existing tests if behavior changed
  • All tests follow the AAA (Arrange, Act, Assert) pattern
  • Test coverage is maintained or improved

Documentation

  • Updated README.md (if applicable)
  • Updated ARCHITECTURE.md (if applicable)
  • Added code examples for new features (if applicable)
  • Updated requirements.yaml (if applicable)

Additional Notes

All 170 tests pass across .NET 8, 9, and 10. CodeQL scan shows 0 alerts. Spell check and markdown lint pass on the updated design document.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…mells

Agent-Logs-Url: https://github.com/demaconsulting/ReqStream/sessions/b1924eda-db55-4fc3-bdec-bae61fed401d

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missed where warnings in Linq usage Fix LINQ missed-where warnings, cognitive complexity violations, and Assert.IsTrue code smells Mar 28, 2026
Copilot AI requested a review from Malcolmnixon March 28, 2026 02:19
@Malcolmnixon Malcolmnixon marked this pull request as ready for review March 28, 2026 02:19
Copilot AI review requested due to automatic review settings March 28, 2026 02:19
@Malcolmnixon
Copy link
Copy Markdown
Member

@copilot Is the linter design documentation still good, or does it need updates?

Copy link
Copy Markdown
Contributor

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 improves code quality by addressing static analysis findings in the linter and test suite, primarily around LINQ filtering patterns, cognitive complexity thresholds, and MSTest assertion usage.

Changes:

  • Updated integration tests to use Assert.Contains(...) instead of Assert.IsTrue(x.Contains(y)).
  • Refactored Linter.cs to reduce cognitive complexity by extracting helper methods (includes, document sections/mappings, section requirements/children, requirement id/title).
  • Replaced implicit filtering inside foreach loops with explicit LINQ pipelines and simplified GetStringList into a single LINQ expression.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/DemaConsulting.ReqStream.Tests/IntegrationTests.cs Replaces Assert.IsTrue(...Contains...) assertions with Assert.Contains(...) for analyzer compliance and consistency.
src/DemaConsulting.ReqStream/Linter.cs Extracts helper methods to reduce cognitive complexity and adjusts iteration/filtering patterns to satisfy LINQ analyzers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Agent-Logs-Url: https://github.com/demaconsulting/ReqStream/sessions/b496bf5d-4f9f-456f-a5a3-e9c5e2fd1f0c

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 28, 2026

@copilot Is the linter design documentation still good, or does it need updates?

The doc needed updates — it referenced three methods (LintSections, LintRequirements, LintMappings) that never existed in the code and were aspirational names from the design phase. The refactoring made the actual helper methods explicit, so the doc now diverged clearly.

Updated in 93ce05b:

  • Removed the three non-existent method sections
  • Added accurate entries for all 7 new helpers: LintIncludes, LintDocumentSections, LintDocumentMappings, LintSectionRequirements, LintSectionChildren, LintRequirementId, LintRequirementTitle
  • Updated LintFile, LintDocumentRoot, LintSection, LintRequirement, and LintMapping to reflect the delegation to their respective helpers

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1108766/chrome-linux.zip
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node install.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Fix LINQ missed-where warnings, cognitive complexity violations, and Assert.IsTrue code smells Fix LINQ missed-where warnings, cognitive complexity violations, Assert.IsTrue code smells, and linter design doc Mar 28, 2026
… message context

Agent-Logs-Url: https://github.com/demaconsulting/ReqStream/sessions/6c19a1b4-bf3c-471d-9c55-8f0172f73063

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
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