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 formatting when making an accessor readonly #76054

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

CyrusNajmabadi
Copy link
Member

Fixes #69876

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 23, 2024
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review November 23, 2024 17:22
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner November 23, 2024 17:22
@@ -40,7 +40,6 @@ class {|FixAllInContainingType:Program|}

var expected = """
Console.WriteLine("Hello, World!");

Copy link
Member Author

Choose a reason for hiding this comment

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

this result is better. the final formatting matches the initial formatting.

@@ -114,7 +114,6 @@ public event Action e5 { add { } remove { } }
event Action I.e6 { add { } remove { } }

static C() { }

Copy link
Member Author

Choose a reason for hiding this comment

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

this result is better. the final formatting matches the initial formatting.

{
void M()
{
int x;{{leadingTrivia}}
Copy link
Member Author

Choose a reason for hiding this comment

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

this result is better. the final formatting matches the initial formatting.

Copy link
Member Author

Choose a reason for hiding this comment

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

same for the rest of the results.

using System;

class C
{
void M()
{
bool otherFunction() => true;

Copy link
Member Author

Choose a reason for hiding this comment

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

this result is better. the final formatting matches the initial formatting.

static object P { get; set; }

Copy link
Member Author

Choose a reason for hiding this comment

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

this result is better. the final formatting matches the initial formatting.

@@ -53,7 +53,6 @@ static void Main(string[] args)

var expected = """
using System;

Copy link
Member Author

Choose a reason for hiding this comment

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

this result is better. the final formatting matches the initial formatting.

// adding/removing/modifying modifiers does not mean we want the parent construct to change its formatting
// respective to what's around it.
if (!withLeadingElasticMarker)
list[i] = list[i].WithoutLeadingTrivia();
Copy link
Member Author

Choose a reason for hiding this comment

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

the crux of the fix. we do not want elastic trivia at teh start of a member by default, and especially not if we're just mutating modifiers. We want the modifiers to just be inertly placed into the member, leaving the formatting the same as how it started.

callers can choose if they do want leading elastic trivia added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fixer for IDE0251 results in poorly formatted code
1 participant