Skip to content

Fix CodeQL warnings: LINQ patterns, resource disposal, and redundant conditions#18

Merged
Malcolmnixon merged 2 commits intomainfrom
copilot/fix-codeql-issues
Feb 3, 2026
Merged

Fix CodeQL warnings: LINQ patterns, resource disposal, and redundant conditions#18
Malcolmnixon merged 2 commits intomainfrom
copilot/fix-codeql-issues

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

Pull Request

Description

Resolves CodeQL warnings by addressing code quality issues in repository connector logic and test code. Updated CodeQL configuration to suppress false positives from generated code and justified exception handlers.

Changes

  • CodeQL Configuration: Added query-filters to exclude warnings from obj/**/generated/** paths and generic catch clauses in Context.cs, Program.cs, and ProcessRunner.cs
  • LINQ Refactoring (GitHubRepoConnector.cs):
    • Replaced imperative foreach loops with .Select() and .SelectMany() chains for PR number extraction and label-to-type mapping
    • Simplified null-check chain using null-forgiving operator where compiler cannot infer non-null
  • Resource Management (ContextTests.cs): Added using declarations for 6 StringWriter instances in console output capture tests

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 static analysis warnings from CodeQL scan.

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

All 106 tests pass across net8.0, net9.0, and net10.0 targets. CodeQL security scan reports zero alerts.

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: /usr/local/bin/node node install.js /home/REDACTED/work/BuildMark/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (http block)

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

Original prompt

This section details on the original issue you should resolve

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

CodeQL is reporting numerous issues

Proposed Solution

Fix the following CodeQL issues:

src/DemaConsulting.BuildMark/BuildInformation.cs(168): 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.BuildMark/RepoConnectors/GitHubRepoConnector.cs(146): 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.BuildMark/RepoConnectors/GitHubRepoConnector.cs(212): warning [cs/linq/missed-select] This foreach loop immediately [maps its iteration variable to another variable](1) - consider mapping the sequence explicitly using '.Select(...)'.  
test/DemaConsulting.BuildMark.Tests/ContextTests.cs(465): warning [cs/local-not-disposed] Disposable 'StringWriter' is created but not disposed.  
test/DemaConsulting.BuildMark.Tests/ContextTests.cs(493): warning [cs/local-not-disposed] Disposable 'StringWriter' is created but not disposed.  
test/DemaConsulting.BuildMark.Tests/ContextTests.cs(552): warning [cs/local-not-disposed] Disposable 'StringWriter' is created but not disposed.  
test/DemaConsulting.BuildMark.Tests/ContextTests.cs(580): warning [cs/local-not-disposed] Disposable 'StringWriter' is created but not disposed.  
test/DemaConsulting.BuildMark.Tests/ContextTests.cs(642): warning [cs/local-not-disposed] Disposable 'StringWriter' is created but not disposed.  
test/DemaConsulting.BuildMark.Tests/ContextTests.cs(670): warning [cs/local-not-disposed] Disposable 'StringWriter' is created but not disposed.  
src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs(116): warning [cs/constant-condition] Condition is always true because of [call to operator ==](1).  
src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs(121): warning [cs/constant-condition] Condition is always true because of [call to operator ==](1).  
src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs(129): warning [cs/constant-condition] Condition is always false because of [call to operator ==](1).  
src/DemaConsulting.BuildMark/obj/Release/net10.0/generated/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs(934): warning [cs/useless-assignment-to-local] This assignment to [timeout](1) is useless, since its value is never read.  
src/DemaConsulting.BuildMark/obj/Release/net8.0/generated/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs(985): warning [cs/useless-assignment-to-local] This assignment to [timeout](1) is useless, since its value is never read.  
src/DemaConsulting.BuildMark/obj/Release/net9.0/generated/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs(985): warning [cs/useless-assignment-to-local] This assignment to [timeout](1) is useless, since its value is never read.  
src/DemaConsulting.BuildMark/obj/Release/net10.0/generated/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs(203): warning [cs/useless-assignment-to-local] This assignment to [slice](1) is useless, since its value is never read.  
src/DemaConsulting.BuildMark/obj/Release/net10.0/generated/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs(311): warning [cs/useless-assignment-to-local] This assignment to [slice](1) is useless, since its value is never read.  
src/DemaConsulting.BuildMark/obj/Release/net10.0/generated/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs(456): warning [cs/useless-assignment-to-local] This assignment to [slice](1) is useless, since its value is never read.  
src/DemaConsulting.BuildMark/obj/Release/net8.0/generated/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs(205): warning [cs/useless-assignment-to-local] This assignment to [slice](1) is useless, since its value is never read.  
src/DemaConsulting.BuildMark/obj/Release/net8.0/generated/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs(313): warning [cs/useless-assignment-to-local] This assignment to [slice](1) is useless, since its value is never read.  
src/DemaConsulting.BuildMark/obj/Release/net8.0/generated/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs(458): warning [cs/useless-assignment-...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes demaconsulting/BuildMark#17

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

…onditions, and fix disposals

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CodeQL reported code issues Fix CodeQL warnings: LINQ patterns, resource disposal, and redundant conditions Feb 3, 2026
Copilot AI requested a review from Malcolmnixon February 3, 2026 16:39
@Malcolmnixon Malcolmnixon marked this pull request as ready for review February 3, 2026 16:44
@Malcolmnixon Malcolmnixon merged commit 4c686c4 into main Feb 3, 2026
@Malcolmnixon Malcolmnixon deleted the copilot/fix-codeql-issues branch February 3, 2026 16:45
@Malcolmnixon Malcolmnixon mentioned this pull request Feb 3, 2026
3 tasks
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.

2 participants