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

Incorrect indentation on a multi-line statement split by comments #968

Closed
Tyrrrz opened this issue Sep 30, 2023 · 1 comment · Fixed by #1105
Closed

Incorrect indentation on a multi-line statement split by comments #968

Tyrrrz opened this issue Sep 30, 2023 · 1 comment · Fixed by #1105
Milestone

Comments

@Tyrrrz
Copy link
Contributor

Tyrrrz commented Sep 30, 2023

Hello.

I have the following snippet. It has the expected formatting already:

var delay =
    // Adding a small buffer to the reset time reduces the chance of getting
    // rate limited again, because it allows for more requests to be released.
    (resetAfterDelay.Value + TimeSpan.FromSeconds(1))
    // Sometimes Discord returns an absurdly high value for the reset time, which
    // is not actually enforced by the server. So we cap it at a reasonable value.
    .Clamp(TimeSpan.Zero, TimeSpan.FromSeconds(60));

As you can see, it's an assignment statement that's split over multiple lines with comments in the middle.

CSharpier formats it like so (indentation is lost):

var delay =
// Adding a small buffer to the reset time reduces the chance of getting
// rate limited again, because it allows for more requests to be released.
(resetAfterDelay.Value + TimeSpan.FromSeconds(1))
// Sometimes Discord returns an absurdly high value for the reset time, which
// is not actually enforced by the server. So we cap it at a reasonable value.
.Clamp(TimeSpan.Zero, TimeSpan.FromSeconds(60));

I do think it's a bug because all lines except the first should be indented. I suspect the issue may be in the presence of comments, but I can't test it because if I remove the comments then the lines get reformatted in a completely different way:

var delay = (resetAfterDelay.Value + TimeSpan.FromSeconds(1)).Clamp(
    TimeSpan.Zero,
    TimeSpan.FromSeconds(60)
);
@belav
Copy link
Owner

belav commented Oct 5, 2023

I'm not clear why both lines end up with no indentation, a similar case is only missing the indentation on the first line... although this case is a chain of method calls, while yours is just a single method call.

var delay =
// Adding a small buffer to the reset time reduces the chance of getting
// rate limited again, because it allows for more requests to be released.
CallSomeMethod(resetAfterDelay.Value + TimeSpan.FromSeconds(1))
    // Sometimes Discord returns an absurdly high value for the reset time, which
    // is not actually enforced by the server. So we cap it at a reasonable value.
    .Clamp(TimeSpan.Zero, TimeSpan.FromSeconds(60));

In case you weren't aware, you can bypass the formatting with

// csharpier-ignore
var delay =
    // Adding a small buffer to the reset time reduces the chance of getting
    // rate limited again, because it allows for more requests to be released.
    (resetAfterDelay.Value + TimeSpan.FromSeconds(1))
    // Sometimes Discord returns an absurdly high value for the reset time, which
    // is not actually enforced by the server. So we cap it at a reasonable value.
    .Clamp(TimeSpan.Zero, TimeSpan.FromSeconds(60));

@belav belav added this to the 0.27.0 milestone Oct 5, 2023
shocklateboy92 added a commit that referenced this issue Jan 9, 2024
* fixing an edge case with comments on variable declarations

closes #968

* self code review

---------

Co-authored-by: Lasath Fernando <devel@lasath.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants