Skip to content

Use AlignAfterOpenBracket BlockIndent for clang-format #15112

@lhecker

Description

@lhecker

This makes you wonder if you scared your code, because it's trying to flee from your screen:

bool ControlCore::SendMouseEvent(const til::point viewportPos,
                                 const unsigned int uiButton,
                                 const ControlKeyStates states,
                                 const short wheelDelta,
                                 const TerminalInput::MouseButtonState state)
{
    return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state);
}

This on the other hand is the one true way, no exceptions (sample size = 1, myself):

bool ControlCore::SendMouseEvent(
    const til::point viewportPos,
    const unsigned int uiButton,
    const ControlKeyStates states,
    const short wheelDelta,
    const TerminalInput::MouseButtonState state
) {
    return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state);
}

We can get this behavior by setting AlignAfterOpenBracket: BlockIndent in .clang-format. The problems:

  • Code like the former example, will not be formatted like the latter example even if we set that option, because the former isn't actually block indented to begin with! It's just line breaks after the first argument and so clang-format turns it into:
    bool ControlCore::SendMouseEvent(const til::point viewportPos, const unsigned int uiButton, const ControlKeyStates states, const short wheelDelta, const TerminalInput::MouseButtonState state)
    {
        return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state);
    }
    Most of our code looks like that unfortunately. This would be correct from the POV of clang-format:
    bool ControlCore::SendMouseEvent(
        const til::point viewportPos,
        const unsigned int uiButton,
        const ControlKeyStates states,
        const short wheelDelta,
        const TerminalInput::MouseButtonState state)
    {
        return _terminal->SendMouseEvent(viewportPos, uiButton, states, wheelDelta, state);
    }
    This can be mostly fixed with this regex replacement: ((?!\s|::)\w+\()([^{}()]+,$) -> $1\n$2
  • Oww:
    523 files changed, 15819 insertions(+), 13065 deletions(-)
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CodeHealthIssues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc.Issue-TaskIt's a feature request, but it doesn't really need a major design.Product-TerminalThe new Windows Terminal.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions