HomePhabricator

[clang-format] restore indent in conditionals when AlignOperands is DontAlign

Authored by krasimir on Jun 24 2020, 3:55 AM.

Description

[clang-format] restore indent in conditionals when AlignOperands is DontAlign

Summary:
After D50078, we're experiencing unexpected un-indent using a style combining AlignOperands: DontAlign with BreakBeforeTernaryOperators: false, such as Google's JavaScript style:

% bin/clang-format -style=google ~/test.js
aaaaaaaaaaa = bbbbbbbb ? cccccccccccccccccc() :
dddddddddd             ? eeeeeeeeeeeeee :
                         fffff;

The issue lies with the interaction of AlignOperands: DontAlign and the edited code section in ContinuationIndenter.cpp, which de-dents the intent by Style.ContinuationIndentWidth. From the documentation of AlignOperands: DontAlign:

The wrapped lines are indented ContinuationIndentWidth spaces from the start of the line.

So the de-dent effectively erases the necessary ContinuationIndentWidth in that case.

This patch restores the AlignOperands: DontAlign behavior, producing:

% bin/clang-format -style=google ~/test.js
aaaaaaaaaaa = bbbbbbbb ? cccccccccccccccccc() :
    dddddddddd         ? eeeeeeeeeeeeee :
                         fffff;

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82199