ReSharper 2019.2 Help

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 Code Editing | General Formatter Style 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:

    Code formatting options overridden by Clang-Format styles

  • In the File Formatting Info window, you can see and study all .clang-format and _clang-format files that affect the current file:

    ReSharper. File Formatting Info window

Supported Clang-Format Options


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++

BreakBeforeBraces (except for Custom and class definition in Linux)

BreakBeforeTernaryOperators C++
BreakConstructorInitializersBeforeComma C++

C++, JavaScript, TypeScript

ConstructorInitializerAllOnOneLineOrOnePerLine C++
IndentCaseLabels C++

C++, JavaScript, TypeScript

IndentWrappedFunctionNames C++
MaxEmptyLinesToKeep C++
NamespaceIndentation C++
PointerAlignment C++
SpaceAfterCStyleCast C++
SpaceAfterTemplateKeyword C++
SpaceBeforeParens C++
SpacesInAngles C++
SpacesInParentheses C++
SpacesInSquareBrackets C++

C++, JavaScript, TypeScript


C++, JavaScript, TypeScript

This feature is supported in the following languages and technologies:

Language: C# Language: VB.NET Language: C++ Language: HTML Language: ASP.NET Language: Razor Language: JavaScript Language: TypeScript Language: CSS Language: XML Language: XAML Language: Resx Language: Build Scripts Language: Protobuf Language: JSON
Feature is not available Feature is not available Feature is available Feature is not available Feature is not available Feature is not available Feature is available Feature is available Feature is not available Feature is not available Feature is not available Feature is not available Feature is not available Feature is not available Feature is not available
Last modified: 18 November 2019