microsoft / microsoft/terminal
Use AlignAfterOpenBracket BlockIndent for clang-format
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
This makes you wonder if you scared your code, because it's trying to flee from your screen:
```cpp
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):
```cpp
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:
```cpp
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:
```cpp
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(-)
```
Contributor guide
Research direction
Start with the repository's .clang-format and compare the two formatting examples using clang-format with AlignAfterOpenBracket set to BlockIndent. Review the proposed regex replacement for currently broken argument indentation, then assess the reported 523-file formatting change. Done means the configuration and affected source formatting match the requested block-indented style.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100