Skip to content

Fix CodeQL warnings: Convert foreach loops to LINQ Select#85

Merged
Malcolmnixon merged 2 commits intomainfrom
copilot/fix-codeql-findings
Jan 27, 2026
Merged

Fix CodeQL warnings: Convert foreach loops to LINQ Select#85
Malcolmnixon merged 2 commits intomainfrom
copilot/fix-codeql-findings

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Pull Request

Description

CodeQL flagged 5 foreach loops that immediately map iteration variables via method calls. Refactored to use LINQ .Select() for more idiomatic C#.

Changes:

  • JUnitSerializer.cs (3 locations): Serialization/deserialization of test suites and test cases
  • TrxSerializer.cs (2 locations): Serialization/deserialization of test results

Example refactoring:

// Before
foreach (var test in testResults)
{
    var resultElement = CreateUnitTestResultElement(test);
    resultsElement.Add(resultElement);
}

// After
resultsElement.Add(testResults.Select(CreateUnitTestResultElement));

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

Related Issues

Addresses CodeQL code quality findings.

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 tests pass: dotnet test --configuration Release
  • 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 '**/*.{yml,yaml}'

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

Pure refactoring with no functional changes. Reduces code by 23 lines while improving readability.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: CodeQL Cleanup</issue_title>
<issue_description>### Problem Statement

CodeQL is reporting a few findings that should be fixed

Proposed Solution

Fix the following CodeQL findings:

src/DemaConsulting.TestResults/IO/JUnitSerializer.cs(69): warning [cs/linq/missed-select] This foreach loop immediately [maps its iteration variable to another variable](1) - consider mapping the sequence explicitly using '.Select(...)'.  
src/DemaConsulting.TestResults/IO/JUnitSerializer.cs(101): warning [cs/linq/missed-select] This foreach loop immediately [maps its iteration variable to another variable](1) - consider mapping the sequence explicitly using '.Select(...)'.  
src/DemaConsulting.TestResults/IO/JUnitSerializer.cs(243): warning [cs/linq/missed-select] This foreach loop immediately [maps its iteration variable to another variable](1) - consider mapping the sequence explicitly using '.Select(...)'.  
src/DemaConsulting.TestResults/IO/TrxSerializer.cs(131): warning [cs/linq/missed-select] This foreach loop immediately [maps its iteration variable to another variable](1) - consider mapping the sequence explicitly using '.Select(...)'.  
src/DemaConsulting.TestResults/IO/TrxSerializer.cs(355): warning [cs/linq/missed-select] This foreach loop immediately [maps its iteration variable to another variable](1) - consider mapping the sequence explicitly using '.Select(...)'.  

Alternatives Considered

No response

Usage Examples

Benefits

Code Quality

Priority

Low - Nice to have

Willingness to Contribute

Yes, I can submit a pull request

Additional Context

No response

Checklist

  • I have searched existing issues to ensure this is not a duplicate
  • I have provided a clear description of the feature
  • I have explained why this feature would be useful</issue_description>

Comments on the Issue (you are @copilot in this section)


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

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CodeQL findings in JUnitSerializer Fix CodeQL warnings: Convert foreach loops to LINQ Select Jan 27, 2026
Copilot AI requested a review from Malcolmnixon January 27, 2026 01:37
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.

[Feature]: CodeQL Cleanup

2 participants