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

Nested loops without brackets may be not indented #867

Closed
Rudomitori opened this issue Apr 9, 2023 · 3 comments · Fixed by #920
Closed

Nested loops without brackets may be not indented #867

Rudomitori opened this issue Apr 9, 2023 · 3 comments · Fixed by #920
Milestone

Comments

@Rudomitori
Copy link
Contributor

// With CSharpier 23
foreach(var subsequnce in sequance)
    foreach(var item in subsequance)
        item.DoSomething();

// How it might look like 
// and how Rider 2023 formats it
foreach(var subsequnce in sequance)
foreach(var item in subsequance)
    item.DoSomething();
// With CSharpier 23
foreach(var subsequnce in sequance)
    foreach(var item in subsequance) {
        item.DoSomething();
        item.DoSomething();
    }

// How it might look like 
// and how Rider 2023 formats it
foreach(var subsequnce in sequance)
foreach(var item in subsequance) {
    item.DoSomething();
    item.DoSomething();
}

The same for await foreach, while and for loops;

The second variant removes one indentation level
and look pretty for me.

Also, CSharpier already use the second variant for using statements
and if the same will be done for loops it will be more consistent.

using (var fileStream1 = File.OpenRead("SomeFile"))
using (var fileStream2 = File.OpenRead("OtherFile"))
{
    Console.WriteLine("Hello");
    Console.WriteLine("World");
}
@belav
Copy link
Owner

belav commented Apr 10, 2023

I hadn't seen this before, but it makes sense to me and does keep things consistent with using. I'll want to do a bit of digging into how often each variation shows up before I commit to doing it. But Rider formatting things that way by default makes me think it's more common than I initially though.

@belav belav added this to the 0.24.0 milestone Apr 10, 2023
@belav belav modified the milestones: 0.24.0, 0.25.0 Apr 26, 2023
@loraderon
Copy link
Contributor

I don't think that this is a good idea.

The case with using statments is the outlier and will probably be used less and less in the future because of the realtive new using var = ..

@shocklateboy92
Copy link
Collaborator

Thinking about this, it makes sense to go with this route.

It's pretty easy to opt out by putting braces around the foreach. Since most IDEs auto add the braces by default, the two loops must be super tightly related for the user to explicitly choose to remove the braces.

shocklateboy92 added a commit that referenced this issue Jul 6, 2023
* Reduce indentations for nested loops

closes #867

* Keep indention for nested loops of mixed types

---------

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants