Skip to content

[clang-format] unable to insert a space only for non-code block empty braces, not for empty parentheses #93635

@khei4

Description

@khei4

WebKit has its own .clang-format and clang-format has basedOnStyle: WebKit, but both of them are inconsistent with internal style checker script, at least for the empty initializers. WebKit bugzilla
For example, the following line, tweaked from WebKit source code, would be checked by the script

        toImpl(listenerRef)->use( {} );
$ python Tools/Scripts/check-webkit-style
ERROR: Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp:222:  Extra space after ( in function call  [whitespace/parens] [4]
ERROR: Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp:222:  Extra space before )  [whitespace/parens] [2]
ERROR: Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp:222:  Missing space inside { }.  [whitespace/braces] [5]

A space in empty braces is required, but one in (also for empty) parens isn't allowed.

Current clang-format could insert a space in empty parenthesis and block simultaneously by turning on SpacesInParensOptions.InEmptyParentheses, but formatting only braces couldn't be achieved.

So we want a way to insert a space only for braces by adding some options.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions