Skip to content

Fix for Missed opportunity to use Where - #1

Merged
Alcheri merged 1 commit into
mainfrom
finding-autofix-2
Aug 11, 2026
Merged

Alcheri merged 1 commit into
mainfrom
finding-autofix-2

Conversation

@Alcheri

@Alcheri Alcheri commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

To fix this, move the validation predicate from inside the loop into the sequence itself using .Where(...), so the foreach iterates only valid targets. This preserves behavior while matching the CodeQL rule intent.

In example.csharp.greeter/GreeterPlugin.cs, update the LoadTargets() method around lines 124–131:

  • Change the foreach source from settings?.Targets ?? [] to (settings?.Targets ?? []).Where(...).
  • Remove the inner if guard and keep only the assignment in the loop body.
  • Add using System.Linq; at the top of the file (if not already present), since Where is a LINQ extension method.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Alcheri <barry.suridge@gmail.com>
@Alcheri
Alcheri marked this pull request as ready for review August 11, 2026 10:43
Copilot AI lite review requested due to automatic review settings August 11, 2026 10:43
@Alcheri
Alcheri merged commit 23306af into main Aug 11, 2026
4 checks passed
@Alcheri
Alcheri deleted the finding-autofix-2 branch August 11, 2026 10:43

Copilot AI left a comment

Copy link
Copy Markdown

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 updates the C# Greeter plugin’s LoadTargets() logic to satisfy a CodeQL recommendation by moving per-item validation from inside the loop into the enumerable pipeline.

Changes:

  • Refactors LoadTargets() to iterate only valid targets via .Where(...) rather than guarding with an if inside the foreach.
  • Adds an explicit using System.Linq; directive to support LINQ extension usage (though the project already enables implicit usings).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1 to 3
using System.Linq;
using System.Reflection;
using System.Text.Json;
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