Skip to content

False positive: Missed opportunity to use Select with C# #21707

Description

@christiannagel

Description of the false positive

Note from code scanning:

Missed opportunity to use Select
This foreach loop immediately maps its iteration variable to another variable

  • consider mapping the sequence explicitly using '.Select(...)'.

However, the LINQ Select method cannot be used when the value is received via an async method, such as this code from a Playwright test:

Code samples or links to source code

        var hasContactOption = false;
        foreach (var locator in contactSelectors.Select(s => Page.Locator(s)))
        {
            var elements = await locator.CountAsync();
            if (elements > 0)
            {
                hasContactOption = true;
                break;
            }
        }

URL to the alert on GitHub code scanning (optional)

https://github.com/CNinnovation/cninnovationweb/security/code-scanning/284

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions