Using Clang-Format
Starting from version 2017.2, in C++ files (and partly in JavaScript and TypeScript files) ReSharper supports formatting styles defined in Clang-Format. By default, Clang-Format configuration files get automatically used as a source of formatting style settings.
What is Clang-Format and how does ReSharper support it?
Clang-Format is a widely-used C++ code formatter. As it provides an option to define code style options in YAML-formatted files — named .clang-format or _clang-format — these files often become a part of your project where you keep all code style rules. To see the full list of Clang-Format style options and examples of configuration files, check out the Clang-Format documentation.
If your project happens to have its code styles configured in Clang-Format files, ReSharper's code formatting engine will automatically use most of these styles for formatting C++ files, and some of them in JavaScript and TypeScript files.
Clang-Format in your solution
By default, Clang-Format properties are enabled; they will override preferences defined in ReSharper and Visual Studio options as well as EditorConfig styles. If you want ReSharper to ignore Clang-Format styles for code formatting and code syntax, clear the corresponding checkbox on the page of ReSharper options.
When Clang-Format support is enabled and there are .clang-format or _clang-format files that affect the current file, ReSharper will help you understand which Clang-Format styles are applied and where these settings come from:
On ReSharper formatting options pages for C++, JavaScript, and TypeScript, you will see a yellow warning if at least one preference on the page is overridden by Clang-Format styles for the current file, each overridden preference will also be highlighted with yellow. For example:
In the File Formatting Info window, you can see and study all .clang-format and _clang-format files that affect the current file:
Supported Clang-Format Options
Option | Supported in languages |
---|---|
BasedOnStyle | C++ |
AlignConsecutiveAssignments | C++ |
AlignConsecutiveDeclarations | C++ |
AlignAfterOpenBracket | C++ |
AlignOperands | C++ |
AlignTrailingComments | C++ |
AllowShortCaseLabelsOnASingleLine | C++ |
AlwaysBreakAfterDefinitionReturnType | C++ |
AlwaysBreakAfterReturnType | C++ |
AlwaysBreakTemplateDeclarations | C++ |
BinPackArguments | C++ |
BinPackParameters | C++ |
| C++ |
BreakBeforeTernaryOperators | C++ |
BreakConstructorInitializersBeforeComma | C++ |
ColumnLimit | |
ConstructorInitializerAllOnOneLineOrOnePerLine | C++ |
IndentCaseLabels | C++ |
IndentWidth | |
IndentWrappedFunctionNames | C++ |
MaxEmptyLinesToKeep | C++ |
NamespaceIndentation | C++ |
PointerAlignment | C++ |
SpaceAfterCStyleCast | C++ |
SpaceAfterTemplateKeyword | C++ |
SpaceBeforeParens | C++ |
SpacesInAngles | C++ |
SpacesInParentheses | C++ |
SpacesInSquareBrackets | C++ |
TabWidth | |
UseTab |
This feature is supported in the following languages and technologies: