ReSharper 2024.3 Help

Code style assistance in Visual Basic

The main ReSharper's code style assistance features available in C# (for example Naming style, Apply formatting rules, Code cleanup) are also supported in Visual Basic. You can find the detailed information on these features in the corresponding topics of the Code style and cleanup section.

Formatting style

An important aspect of code style is how to format the code, that is, how to use whitespaces, tabs, and line breaks to arrange code elements, whether and how to use tabs for indents, whether and how to wrap long lines, and so on.

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, applies code templates and performs refactorings. The formatting rules can also be applied to the existing code in the current selection, current file, or in a larger scope up to the entire solution.

Here is an example of a code block reformatted with ReSharper.

Before:

ReSharper: Code cleanup in Visual Basic

After:

ReSharper: Code cleanup in Visual Basic

For more information, see Apply formatting rules.

Naming style

ReSharper helps you define, control, and apply desired naming styles for symbols in your code. There is 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 capitalization of compound words, underscores, suffixes, prefixes, and so on.

These rules are taken into account when ReSharper produces new code with code completion and code generation features, applies code templates and performs refactorings. ReSharper also helps you detect and fix violations of naming rules. If necessary, the automatic checkup of naming rules can be configured or disabled.

Edit naming rule

  1. Do one of the following:

    • Press Alt+Enter on a highlighted symbol with inconsistent naming, then choose Inspection 'Inconsistent Naming' | Change settings for naming rule '[rule name]'.

    • From the main menu, choose ReSharper | Options | Code Editing | Visual Basic | Naming Style, select the desired rule, and click Edit ThemedIcon.EditorOptionsPage.Screen.(Gray).png or double-click it.

  2. In the Edit Rule Settings dialog that opens, check the existing style for the rule.

  3. If the existing style is acceptable, but you would like to allow other styles for this rule, click Add ThemedIcon.AddedParameter.Screen.(Gray).png When there are several styles for a single rule, ReSharper does not report code style violation if a corresponding symbol name matches at least one of these styles. Otherwise, ReSharper detects a code style violation and suggests renaming the symbol according to the default style (the first style in the list). To change the default style, use Move Up ThemedIcon.Up.Screen.(Gray).png and Move Down ThemedIcon.Down.Screen.(Gray).png buttons.

  4. To configure a specific style, select it in the list and configure prefix, suffix, and choose a naming style.

  5. To remove an unnecessary style, select it in the list and click Remove ThemedIcon.Delete.Screen.(Gray).png.

  6. If necessary, you can disable reporting code style violations associated with this rule, while still allowing ReSharper to detect other naming rule violations. To do so, clear the Enable inspections checkbox.

  7. Click Save in the Options dialog to apply the modifications and let ReSharper choose where to save them, or save the modifications to a specific settings layer by choosing this layer from the Save To selector. For more information, see manage and share resharper settings.

Create a custom naming rule

  1. From the main menu, choose ReSharper | Options | Code Editing | Visual Basic | Naming Style and click Advanced settings.

  2. In the Advanced Naming Settings dialog that opens, click Add ThemedIcon.AddedParameter.Screen.(Gray).png to create a custom naming rule.

    ReSharper: naming style options. advanced settings
  3. In the Edit Extended Naming Rule dialog that appears, configure the new rule: specify a name for the new rule in the Rule Description field, select the target identifiers in the Affected entities area, use Access rights and Static/non-static areas to further constrain the scope of the rule.

  4. In the Naming style section, configure one or more styles for the rule as described in the procedure above.

    ReSharper: Naming style options. Edit extended naming rule
  5. Click OK to close the Edit Extended Naming Rule dialog, and then again OK to close the Advanced Naming Settings dialog.

  6. Click Save in the Options dialog to apply the modifications and let ReSharper choose where to save them, or save the modifications to a specific settings layer by choosing this layer from the Save To selector. For more information, see manage and share resharper settings.

Last modified: 26 May 2024