Code style and cleanup
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, file layout, file header style, and many other tiny aspects (such as order of modifiers or whether to use var
keyword) can be configured to a very detailed level and shared across your team.
ReSharper uses different approaches to deal with different aspects of the code style. For instance:
Using code inspections, ReSharper detects and highlights symbol names inconsistent with your naming standards, redundancies in your code, and a lot more.
Each of the highlighted style violations can be fixed with a quick-fix, or the fix in scope can be applied to all violations of this type.
Violations of code formatting rules as well as some other minor inconsistencies are not highlighted for the reason of keeping your code readable in the editor. Violations of formatting rules can be easily fixed though — select non-formatted code, press Alt+Enter and choose .
Code cleanup helps apply formatting rules and many other code style preferences in a bulk mode for the desired scope.
Most of your code style preferences are taken into account when ReSharper produces new code with code completion and code generation features, applies code templates and performs refactorings.
The mechanism of shared settings allows having different code style configurations for different solutions, and keeping the settings under a VCS to automatically share them with your team members.
When working with existing codebases, you can automatically detect formatting and syntax style rules used there, and then use these rules when contributing to those codebases.
Code formatting styles, code syntax styles, and code inspection severity levels can be also listed in EditorConfig, StyleCop, and Clang-Format configuration files, which also allow you to share your code style settings.
If reformatting C# code is not an option, you can enable Virtual Formatter and view reformatted code without actually changing the sources.
You can refer to specific topics in this section to learn how exactly ReSharper deals with the corresponding code style aspects.
Most of ReSharper's code style features are available in C# and Visual Basic, some are available in several languages, others are language-specific. The table below lists all code style features and languages/technologies where they are supported.
The instructions and examples given in the topics within this section address the use of code style features in C#. For more information about code style features available for specific languages, refer to the corresponding topics in the Languages and frameworks section.
Feature | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
|
|
|
|
| ||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
| |||
|
|
|
|
|
|
|
|
|
|
|
| ||||
|
|
|
|
|
|
|
|
|
|
|
|
| |||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
| |||
|
|
|
|
|
|
|
|
|
|
|
|
| |||
|
|
|
|
|
|
|
|
|
| ||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
| ||||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
| |||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
| |||||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
| |||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
|
|
| ||||||||||||
|
|
|
|