Skip to content

Commit

Permalink
Fix code modifier config (#2359) (#2360)
Browse files Browse the repository at this point in the history
* Fix code modifier config

* Trim statements when checking if they exist
  • Loading branch information
zahalzel authored Mar 27, 2023
1 parent 7b6fcaf commit 2eceb43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@
}
},
{
"MultiLineBlock": [
"var policy = new AuthorizationPolicyBuilder()",
"\t.RequireAuthenticatedUser()",
"\t.Build()"
],
"Block": "var policy = new AuthorizationPolicyBuilder()\r\n .RequireAuthenticatedUser()\r\n .Build()",
"Parent": "WebApplication.CreateBuilder.Services.AddControllersWithViews",
"CodeChangeType": "Lambda",
"Parameter": "options",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,13 @@ internal static bool StatementExists(IEnumerable<SyntaxNode> nodes, string state
return nodes.Any(n => StatementExists(n, statement));
}

internal static bool StatementExists(SyntaxNode node, string statement) => node.ToString().Contains(statement.Trim(), StringComparison.Ordinal);
internal static bool StatementExists(SyntaxNode node, string statement)
{
var existingBlock = TrimStatement(node.ToString());
var statementToCheck = TrimStatement(statement);

return existingBlock.Contains(statementToCheck);
}

// Filter out CodeSnippets that are invalid using FilterOptions
internal static CodeSnippet[] FilterCodeSnippets(CodeSnippet[] codeSnippets, CodeChangeOptions options) => codeSnippets.Where(cs => FilterOptions(cs.Options, options)).ToArray();
Expand Down

0 comments on commit 2eceb43

Please sign in to comment.