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

Set csharp_indent_case_contents_when_block to false #103091

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

tannergooding
Copy link
Member

The VS default and therefore our default is csharp_indent_case_contents_when_block = true which is that way for historical reasons:

// csharp_indent_case_contents_when_block = true
case 0:
    {
        Console.WriteLine("Hello");
        break;
    }

// csharp_indent_case_contents_when_block = false
case 0:
{
    Console.WriteLine("Hello");
    break;
}

But this default is inconsistent with the indentation used for block expressions given if, else, for, foreach, do, while, switch itself, etc. So this makes case consistent with all other scenarios, makes the code more readable, and avoids devs needing to fight formatting with VS.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 5, 2024
@tannergooding
Copy link
Member Author

CC. @stephentoub

@sharwell
Copy link
Member

sharwell commented Jun 13, 2024

The VS default and therefore our default

This is a bit misleading. The previous .editorconfig included a definition for this item, so the VS default would never be used. The VS default is also never used if EnforceCodeStyleInBuild is set to true (we fall back to the Roslyn option default if .editorconfig doesn't define it).

Are there plans to make a pass and ensure existing code is normalized to the new form? Changing an option without normalizing the code can produce a long tail of churn in pull requests.

@tannergooding
Copy link
Member Author

tannergooding commented Jun 13, 2024

This is a bit misleading. The previous .editorconfig included a definition for this item, so the VS default would never be used. The VS default is also never used if EnforceCodeStyleInBuild is set to true (we fall back to the Roslyn option default if .editorconfig doesn't define it).

I think you misunderstood the statement.

The statement was that we had our .editorconfig explicitly encode the defaults that exist provided no other overrides exist. That is, the Roslyn default (if no setting overrides it) matches the historical VS default (assuming default settings and no user customization of the behavior) and our .editorconfig explicitly encoded that to ensure that any user preferences would not be picked up, as is the recommended way to set up an .editorconfig file.

That historical default is largely undesirable, but one that we can't change due to backwards compatibility concerns across the entire .NET ecosystem.

Are there plans to make a pass and ensure existing code is normalized to the new form? Changing an option without normalizing the code can produce a long tail of churn in pull requests.

We typically don't do that.

We have millions of lines of code that have been built up over 20 years and it's already in a state where not all of it follows the code style conventions. We instead simply get new code in the correct format and sometimes fixup the code in existing files when we're doing larger refactorings.

This is a place where a lot of our code, especially new code, is already following the format covered by the change in the PR and it's simply helping to ensure that we aren't needing to fight the IDE when working in the code.

@am11 am11 added area-Infrastructure-libraries and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 13, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

@tannergooding tannergooding merged commit 0afabfb into dotnet:main Jun 13, 2024
146 of 148 checks passed
@tannergooding tannergooding deleted the editorconfig-switch-case branch June 13, 2024 21:14
@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants