Conversation
|
/deploy |
There was a problem hiding this comment.
Pull request overview
This PR extends the existing KUK0006 analyzer/code-fix (multiline closing parenthesis alignment) from method invocations to also cover object creation expressions, and adds a new .editorconfig option (dotnet_diagnostic.KUK0006.target_syntax) to control which syntax kinds are analyzed.
Changes:
- Extend
Kuk0006MultilineClosingParenthesisAnalyzerto analyzeObjectCreationExpressionin addition toInvocationExpression, gated by a new.editorconfigoption. - Add
Kuk0006TargetSyntaxOptionoption metadata + parsing utility inKuker.Core. - Update KUK0006 code-fix behavior and expand analyzer/code-fix test coverage for object creation scenarios and option combinations.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Kuker.CodeFixes.Tests/CodeFixProviders/Kuk0006MultilineClosingParenthesisCodeFixProviderTests.cs | Adds code-fix test cases for object creation and mixed fix-all coverage. |
| tests/Kuker.Analyzers.Tests/Rules/Kuk0006MultilineClosingParenthesisAnalyzerTests.cs | Adds extensive analyzer test coverage for object creation + .editorconfig target syntax behaviors. |
| src/Kuker.Core/Options/Kuk0006TargetSyntaxOption.cs | Introduces shared option key/constants and parsing for dotnet_diagnostic.KUK0006.target_syntax. |
| src/Kuker.CodeFixes/CodeFixProviders/Kuk0006MultilineClosingParenthesisCodeFixProvider.cs | Broadens code-fix alignment to work from ArgumentListSyntax (supports invocation + object creation). |
| src/Kuker.Analyzers/Rules/Kuk0006MultilineClosingParenthesisAnalyzer.cs | Adds object creation analysis, option handling, and invalid-config diagnostic behavior. |
Suppressed comments (1)
src/Kuker.Analyzers/Rules/Kuk0006MultilineClosingParenthesisAnalyzer.cs:181
- This special-case return suppresses KUK0006 for nested object creations used as an argument when the parent invocationβs closing paren immediately follows on the same line (the common
))case). That leaves the inner multiline object-creation closing parenthesis violation unreported/unfixed (the outer invocation fix will move only the outer)to a new line).
if (targetSyntax == Kuk0006TargetSyntaxOption.OBJECT_CREATION &&
node.Parent is ArgumentSyntax &&
node.Parent.Parent is ArgumentListSyntax parentArgumentList &&
parentArgumentList.Parent is InvocationExpressionSyntax parentInvocation)
{
π‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
Suppressed comments (4)
src/Kuker.Analyzers/Rules/Kuk0006MultilineClosingParenthesisAnalyzer.cs:57
s_invalidConfigRulereuses the same diagnostic ID (KUK0006) as the formatting rule. That makes it hard to independently configure severity/suppressions for βinvalid configurationβ vs βcode formatting violationβ, and can confuse tooling (e.g., code fixes are keyed only by ID). Consider introducing a dedicated diagnostic ID for the config error (e.g.,KUK0006CFG) and updating tests/docs accordingly.
private static readonly DiagnosticDescriptor s_invalidConfigRule = new DiagnosticDescriptor(
id: DiagnosticIdContant.KUK0006,
title: s_invalidConfigTitle,
messageFormat: s_invalidConfigMessageFormat,
category: CategoryConstant.ALL_RULES,
src/Kuker.Analyzers/Rules/Kuk0006MultilineClosingParenthesisAnalyzer.cs:186
- Invalid
dotnet_diagnostic.KUK0006.syntax_kindsis only reported after the code is already detected as misaligned (the method returns early when the placement is correct). This means an invalid option value can remain unnoticed in correctly formatted code. If the goal is to surface config problems reliably, consider validating/reporting the option earlier (before placement checks) and early-exiting by configured syntax kinds to avoid unnecessary placement computation when a kind is disabled.
HashSet<string> targetSyntaxes;
AnalyzerConfigOptions options = context.Options.AnalyzerConfigOptionsProvider.GetOptions(node.SyntaxTree);
if (options.TryGetValue(Kuk0006TargetSyntaxOption.KEY, out string configuredTargetSyntax))
{
if (!Kuk0006TargetSyntaxOption.TryParse(configuredTargetSyntax, out targetSyntaxes))
{
Diagnostic configDiagnostic = Diagnostic.Create(
s_invalidConfigRule,
closeParen.GetLocation(),
configuredTargetSyntax.Trim());
context.ReportDiagnostic(configDiagnostic);
return;
}
tests/Kuker.Analyzers.Tests/Kuker.Analyzers.Tests.csproj:1
- The project file now starts with a UTF-8 BOM (invisible character before
<Project>). This often creates noisy diffs and can break some tooling/parsers; please re-save without BOM.
ο»Ώ<Project Sdk="Microsoft.NET.Sdk">
src/Kuker.Core/Options/Kuk0006TargetSyntaxOption.cs:68
TryParseuses LINQ (Select) in a hot path (called by the analyzer/code-fix for every candidate). This adds avoidable allocations; a simpleSplit+ trim loop keeps the same behavior without LINQ.
foreach (string token in value.Trim().Split(',').Select(token => token.Trim()))
{
if (token.Length == 0)
{
return false;
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/Kuker.Analyzers/Rules/Kuk0006MultilineClosingParenthesisAnalyzer.cs:176
- The .editorconfig option is parsed/validated only after several early returns (e.g., when the closing paren is already aligned). As a result, an invalid
dotnet_diagnostic.KUK0006.syntax_kindsvalue can go completely unreported in files where KUK0006 formatting is otherwise correct, and the analyzer also computes placement/alignment before it even knows whether the current syntax kind is enabled. Consider moving option parsing +targetSyntaxes.Contains(targetSyntax)filtering earlier (right after the multiline check) so invalid configs are surfaced consistently and excluded syntax kinds short-circuit before doing placement work.
HashSet<string> targetSyntaxes;
AnalyzerConfigOptions options = context.Options.AnalyzerConfigOptionsProvider.GetOptions(node.SyntaxTree);
if (options.TryGetValue(Kuk0006TargetSyntaxOption.KEY, out string configuredTargetSyntax))
{
|
/deploy |
|
π NuGet package has been published! You now have early access to the latest changes and can test them before they reach production. Please try this version in your project(s) and let us know if you encounter any issues. If everything works as expected, we'd also appreciate your confirmation. Thank you for your feedback β€οΈ π Package link: π» Add a dependency to your csproj: <PackageReference Include="kurnakovv.kuker-pr" Version="0.0.2-pr-101">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>β° Note: Please allow a few minutes for NuGet.org to validate and deploy the package. If the link returns a 404 error, the package is still being processed - just wait a little and try again. |
Issue: #100