Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S6802 FN: Lambdas in loop without a direct block are not reported #8394

Open
sebastien-marichal opened this issue Nov 22, 2023 · 0 comments
Labels
Area: C# C# rules related issues. Type: False Negative Rule is NOT triggered when it should be.

Comments

@sebastien-marichal
Copy link
Contributor

Lambdas inside a loop without a direct block as a child are not reported by S6802:

@foreach (var item in Buttons.Where(x => x.Id == "idToFind"))
    @if (item.Id == "idToFind")
    {
        <button @onclick="(e) => Reset(e)">Reset #3</button> @* False Negative *@
    }

This is due to the implementation checking if the lambda is inside a direct descendant block of the loop:

private static bool IsWithinLoopBody(SyntaxNode node) =>
    node.AncestorsAndSelf().Any(x => x is BlockSyntax && x.Parent is ForStatementSyntax or ForEachStatementSyntax or WhileStatementSyntax or DoStatementSyntax);

Repros have been added in #8387.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Projects
None yet
Development

No branches or pull requests

1 participant