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

Add single_indent option #535

Merged
merged 1 commit into from
Oct 22, 2021
Merged

Add single_indent option #535

merged 1 commit into from
Oct 22, 2021

Conversation

belka-ew
Copy link
Collaborator

Since the DStyle proposal to indent continuation lines by two tabs instead of
one was rejected (see dlang/dlang.org#2766), and it is
the only behaviour dfmt supports, I suggest to add an option to indent
everything with a single tab. So the option changes the indentation inside the
parens.

Double indentation is useful to visually emphasize a code block after an
argument list or if-, while-conditions and so on. For example

if (true
  && true)
  doSomething();

vs

if (true
        & true)
    doSomething();

The indentation in the second case makes it clear where the condition ends.

Some style guides enforce:

  • curly braces even in single line if-statements
  • curly braces on the new line

In the case of a such style guide, the problem disappears because there is
always a new line between the condition and the code block:

if (true
    && true)
{
    doSomething();
}

It also eliminates the need to think about aligning the code with mixed parens,
brackets and braces (e.g. ([])), just indent everything with one tab.

@belka-ew belka-ew requested a review from WebFreak001 May 28, 2021 08:28
@WebFreak001 WebFreak001 requested a review from Hackerpilot May 28, 2021 11:05
@WebFreak001
Copy link
Member

requesting additional review from Hackerpilot because the indentation engine is black magic to me

@belka-ew
Copy link
Collaborator Author

Can we get this futher? Last week I've tested this option on a bunch of Funkwerk projects, hundreds of thousands of lines of code, and it works as expected with a few exceptions caused by existing indentation bugs.

@RazvanN7 RazvanN7 merged commit 2beb819 into master Oct 22, 2021
@PetarKirov PetarKirov deleted the single-indent branch October 24, 2021 07:19
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.

3 participants