ReSharper 2016.1 Help

Code Style Assistance in C++

ReSharper provides a lot of features for keeping your code neat and clean. Being tightly interwoven with the majority of other ReSharper's features, they help you produce code and change existing codebases according to the specific code style. The code style, which includes naming standards, formatting rules, and many other tiny aspects can be configured to a very detailed level and shared across your team.

Similarly to other languages, all C++ code style preferences can be applied in the desired scope with a single command using either Fix in scope or Code cleanup.

ReSharper provides the following code style assistance features in C++:

Code formatting rules

An important aspect of code style is how to format the code, i.e. how to use whitespaces and blank lines to arrange and separate code blocks, whether and how to use tabs for indents, whether and how to wrap long lines, etc.

The extensive set of ReSharper code formatting rules has a default configuration that takes into account default Visual Studio formatting options as well as numerous best practices.

You can configure every detail of formatting rules and enforce the rules in your code. These rules are applied when ReSharper produces new code with code completion and code generation features, code templates and refactorings. The formatting rules can be also applied to the existing code in the current selection, current file, or in a larger scope up to the entire solution.

ReSharper allows you to configure formatting rules in options pages under the Code Editing | C++ | Formatting Style group.

As an alternative to digging through options pages, you can select a block of code and configure only those formatting rules that are applicable to this block, observing the changes right in this block.

To configure formatting rules for selected code

  1. In the editor, select a block of code that you want to reformat.
  2. Choose Format | Configure.
  3. In the Configure format dialog box that opens, you will see all formatting rules that affect the selected code block. The code block itself will be surrounded with a dotted frame:
    Configuring formatting rules for selected code
  4. As you change the formatting rules, you will see how they affect the code in the selected block.
  5. ReSharper will save your modifications and reformat the code block.

Naming style

ReSharper helps you define, control, and apply naming style for symbols in your code. Naming style is implemented as a set of rules, each of which targets specific identifiers with the set of constraints . Each rule can have one or more associated styles that define suffixes, prefixes, capitalization of compound words, etc.

Naming rules in C++ are applied to generated code. Out of the box, ReSharper provides a naming rule for each type of identifier. If necessary, you can configure naming rules according to your preferences.

Arranging cv-qualifiers

ReSharper helps you arrange cv-qualifiers in generated code. In the Code Editing | C++ | Code Style options page, you can specify whether to put cv-qualifiers before or after the type specifier as well as the order of the const and volatile modifiers.

Include directive style

In the Code Editing | C++ | Code Style options page, you can specify whether to use forward or backward slash as a path separator in include directives in generated code. You can also specify whether or not to generate forward declaration in the header file.

See Also

Last modified: 19 August 2016