Skip to content

πŸ’‘ Extend KUK0006 to support object creation expressions with configurable target syntax via .editorconfig #100 - #101

Open
kurnakovv wants to merge 20 commits into
devfrom
k-100
Open

πŸ’‘ Extend KUK0006 to support object creation expressions with configurable target syntax via .editorconfig #100#101
kurnakovv wants to merge 20 commits into
devfrom
k-100

Conversation

@kurnakovv

Copy link
Copy Markdown
Owner

Issue: #100

Comment thread src/Kuker.Core/Options/Kuk0006TargetSyntaxOption.cs Fixed
@kurnakovv

Copy link
Copy Markdown
Owner Author

/deploy

@kurnakovv kurnakovv changed the title Settings πŸ’‘ Extend KUK0006 to support object creation expressions with configurable target syntax via .editorconfig #100 πŸ’‘ Extend KUK0006 to support object creation expressions with configurable target syntax via .editorconfig #100 Jul 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 Kuk0006MultilineClosingParenthesisAnalyzer to analyze ObjectCreationExpression in addition to InvocationExpression, gated by a new .editorconfig option.
  • Add Kuk0006TargetSyntaxOption option metadata + parsing utility in Kuker.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.

Comment thread src/Kuker.Analyzers/Rules/Kuk0006MultilineClosingParenthesisAnalyzer.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_invalidConfigRule reuses 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_kinds is 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

  • TryParse uses LINQ (Select) in a hot path (called by the analyzer/code-fix for every candidate). This adds avoidable allocations; a simple Split + 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;

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_kinds value 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))
            {

@kurnakovv

Copy link
Copy Markdown
Owner Author

/deploy

@github-actions

Copy link
Copy Markdown

πŸš€ 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:
https://www.nuget.org/packages/kurnakovv.kuker-pr/0.0.2-pr-101

πŸ’» 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.

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.

πŸ’‘ Extend KUK0006 to support object creation expressions with configurable target syntax via .editorconfig

3 participants