Skip to content

Commit 89cf4ea

Browse files
authored
Merge pull request #13913 from Mikejo5000/mikejo-br24
Update code style preferences and EditorConfig article
2 parents 013be8d + 099baa5 commit 89cf4ea

File tree

7 files changed

+129
-63
lines changed

7 files changed

+129
-63
lines changed

docs/code-quality/roslyn-analyzers-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Analyzers are divided into the following groups:
2424

2525
- [Code style analyzers](/dotnet/fundamentals/code-analysis/code-style-rule-options?preserve-view=true&view=vs-2019#convention-categories)
2626

27-
These analyzers are built into Visual Studio. The analyzer's diagnostic ID, or code format is IDExxxx, for example, IDE0001. You can configure preferences in the [text editor options page](../ide/code-styles-and-code-cleanup.md#code-styles-in-the-options-dialog-box) or in an [EditorConfig file](../ide/create-portable-custom-editor-options.md). Starting in .NET 5.0, code style analyzers are included with the .NET SDK and can be strictly enforced as build warnings or errors. For more information, see [Overview of .NET source code analysis](/dotnet/fundamentals/productivity/code-analysis).
27+
These analyzers are built into Visual Studio. The analyzer's diagnostic ID, or code format is IDExxxx, for example, IDE0001. You can configure preferences in the [text editor options page](../ide/code-styles-and-code-cleanup.md#net-code-styles-in-the-options-dialog-box) or in an [EditorConfig file](../ide/create-portable-custom-editor-options.md). Starting in .NET 5.0, code style analyzers are included with the .NET SDK and can be strictly enforced as build warnings or errors. For more information, see [Overview of .NET source code analysis](/dotnet/fundamentals/productivity/code-analysis).
2828

2929
- [Code quality analyzers](/dotnet/fundamentals/code-analysis/overview#code-quality-analysis)
3030

docs/ide/code-styles-and-code-cleanup.md

Lines changed: 91 additions & 35 deletions
Large diffs are not rendered by default.

docs/ide/create-portable-custom-editor-options.md

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: Define consistent coding styles with EditorConfig
33
description: Add an EditorConfig file to your project or codebase to enforce consistent coding styles for everyone that works in the codebase.
4-
author: mikadumont
5-
ms.author: midumont
4+
ms.date: 05/08/2025
5+
author: mikejo5000
6+
ms.author: mikejo
67
manager: mijacobs
78
ms.subservice: general-ide
89
ms.topic: how-to
910
helpviewer_keywords:
1011
- editorconfig [Visual Studio]
11-
ms.date: 04/01/2024
1212

1313
#customer intent: As a developer, I want to use EditorConfig files to enforce coding style consistency for everyone that writes code in our Visual Studio codebase and projects.
1414

@@ -17,21 +17,13 @@ ms.date: 04/01/2024
1717

1818
To enforce consistent coding styles for everyone that works in a codebase, you can add an `.editorconfig` file to your solution or project. EditorConfig file settings adhere to a file format specification maintained by [EditorConfig.org](https://editorconfig.org). Many code editors and applications support EditorConfig files, including Visual Studio. Because the settings are in a file, they accompany your code, and can be used even outside of Visual Studio.
1919

20-
In Visual Studio, EditorConfig file settings take precedence over the various global text editor settings available under **Tools** > **Options** > **Text Editor** > **C/C++** > **Code Style**. You can use an EditorConfig file to tailor each codebase to use text editor settings that are specific to that project.
20+
In Visual Studio, EditorConfig file settings take precedence over the various global text editor settings available under **Tools** > **Options** > **Text Editor** > **\[C# | C/C++ | Visual Basic\]** > **Code Style**. You can use an EditorConfig file to tailor each codebase to use text editor settings that are specific to that project.
2121

22-
You can manually populate an EditorConfig file, or automatically generate it based on the code style settings you've chosen in Visual Studio. To create a new `.editorconfig` file based on your current Visual Studio settings, from the Visual Studio main menu choose **Tools** > **Options** > **Text Editor** > **C/C++** > **Code Style**. Then choose **Generate .editorconfig file from settings**. Choose the folder where your project is and then choose **Select Folder** to save the `.editorconfig` file.
22+
You can manually populate an EditorConfig file, or automatically generate it based on the code style settings you've chosen in Visual Studio. For more information, see [Ways to add an EditorConfig file](#ways-to-add-an-editorconfig-file).
2323

2424
When you use an EditorConfig file, you can still continue to set your own personal editor preferences in the Visual Studio text editor. These text editor settings apply whenever you're working in a codebase without an EditorConfig file, or when the EditorConfig file doesn't override a particular setting. An example of such a preference is whether to use tabs or spaces for the code indent style.
2525

26-
When you add an EditorConfig file to your project in Visual Studio, only new lines of code are formatted based on the EditorConfig settings. The formatting of existing code isn't changed unless you run one of the following commands:
27-
28-
- [Code Cleanup](../ide/code-styles-and-code-cleanup.md#apply-code-styles).
29-
30-
Select **Code Cleanup** in the Visual Studio editor, or press **Ctrl**+**K**, **Ctrl**+**E**. This command applies to white-space settings, such as indent style, and selected code-style settings, such as parenthesis preferences.
31-
32-
- Format Document.
33-
34-
Select **Edit** > **Advanced** > **Format Document**, or press **Ctrl**+**K**, **Ctrl**+**D** in the default profile. This command applies only to white-space settings, such as indent style.
26+
When you add an EditorConfig file to your project in Visual Studio, only new lines of code are formatted based on the EditorConfig settings. The formatting of existing code isn't changed unless you run the **Code Cleanup** or **Format Document** commands. For more information, see [Apply code styles](../ide/code-styles-and-code-cleanup.md).
3527

3628
## Code consistency
3729

@@ -67,7 +59,35 @@ EditorConfig supports [code style](/dotnet/fundamentals/code-analysis/code-style
6759

6860
When you add an EditorConfig file to your project or codebase, Visual Studio formats any new lines of code you write according to the EditorConfig file settings. However, Visual Studio doesn't convert existing styles to the new ones until you format the document or run [Code Cleanup](../ide/code-styles-and-code-cleanup.md#apply-code-styles). For example, if the indents in your file are formatted with tabs and you add an EditorConfig file that formats indents with spaces, the indent characters aren't automatically converted to spaces. When you format the document (select **Edit** > **Advanced** > **Format Document** or press **Ctrl**+**K**, **Ctrl**+**D**), the white-space settings in the EditorConfig file are applied to existing lines of code.
6961

70-
If you remove an EditorConfig file from your project or codebase, you must close and reopen any open code files for the global editor settings to effect new lines of code.
62+
If you remove an EditorConfig file from your project or codebase, you must close and reopen any open code files for the global editor settings to affect new lines of code.
63+
64+
### Ways to add an EditorConfig file
65+
66+
There are a couple of ways you can add an EditorConfig file to your project:
67+
68+
- [Automatically generate an EditorConfig file based on your code-style settings](../ide/code-styles-and-code-cleanup.md#code-styles-in-editorconfig-files).
69+
70+
- [Manually add the EditorConfig file](#add-an-editorconfig-file-to-a-project).
71+
72+
- Use [IntelliCode for Visual Studio](/visualstudio/ide/intellicode-visual-studio) to generate an `.editorconfig` file in your solution. Right-click in Solution Explorer and choosing **Add** > **New EditorConfig (IntelliCode)** from the context menu. IntelliCode for Visual Studio infers your code styles from existing code, and then creates an EditorConfig file with your code-style preferences predefined.
73+
74+
### Generate an EditorConfig from code-style settings
75+
76+
::: moniker range=">=vs-2022"
77+
78+
You can manually populate your EditorConfig file, or you can automatically generate the file based on the code style settings you've chosen in the Visual Studio **Options** dialog box. This options page is available at **Tools** > **Options** > **Text Editor** > [**C#** | **C/C++** | **Visual Basic**] > **Code Style** > **General**. Click **Generate .editorconfig file from settings** to automatically generate a coding style *.editorconfig* file based on the settings on this **Options** page.
79+
80+
![Screenshot of Generate editorconfig file from settings.](media/vs-2022/generate-editorconfig-file-small.png)
81+
82+
::: moniker-end
83+
84+
::: moniker range="vs-2019"
85+
86+
You can manually populate your EditorConfig file, or you can automatically generate the file based on the code style settings you've chosen in the Visual Studio **Options** dialog box. This options page is available at **Tools** > **Options** > **Text Editor** > [**C#** or **Basic**] > **Code Style** > **General**. Click **Generate .editorconfig file from settings** to automatically generate a coding style *.editorconfig* file based on the settings on this **Options** page.
87+
88+
![Screenshot of Generate editorconfig file from settings.](media/vs-2019/generate-editorconfig-file-small.png)
89+
90+
::: moniker-end
7191

7292
### Add an EditorConfig file to a project
7393

@@ -95,14 +115,6 @@ To add an EditorConfig file to your project or solution, follow these steps:
95115

96116
1. Optionally edit the file, and then save it.
97117

98-
### Other ways to add an EditorConfig file
99-
100-
There are a couple of other ways you can add an EditorConfig file to your project:
101-
102-
- Use [IntelliCode for Visual Studio](/visualstudio/ide/intellicode-visual-studio) to generate an `.editorconfig` file in your solution. Right-click in Solution Explorer and choosing **Add** > **New EditorConfig (IntelliCode)** from the context menu. IntelliCode for Visual Studio infers your code styles from existing code, and then creates an EditorConfig file with your code-style preferences predefined.
103-
104-
- [Automatically generate an EditorConfig file based on your code-style settings](code-styles-and-code-cleanup.md#code-styles-in-editorconfig-files).
105-
106118
## File hierarchy and precedence
107119

108120
When you add an `.editorconfig` file to a folder in your file hierarchy, its settings apply to all applicable files at that level and lower. You can also override EditorConfig settings for a particular project, codebase, or part of a codebase, such that it uses different conventions than other parts of the codebase. Doing so can be useful when you incorporate code from somewhere else, and don’t want to change its conventions.

docs/ide/find-and-fix-code-errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Visual Studio provides [on-demand formatting of your C# code file](code-styles-a
9898

9999
![Screenshot of Code Cleanup button.](media/vs-2019/execute-code-cleanup.png)
100100

101-
In addition to formatting your file for spaces, indents, and so on, **Code Cleanup** also applies a set of code style conventions that you define. Your preferences for each code style are read from the [EditorConfig file](code-styles-and-code-cleanup.md#code-styles-in-editorconfig-files), if you have one for the project, or from the [code style settings](code-styles-and-code-cleanup.md#code-styles-in-the-options-dialog-box) in the **Options** dialog box.
101+
In addition to formatting your file for spaces, indents, and so on, **Code Cleanup** also applies a set of code style conventions that you define. Your preferences for each code style are read from the [EditorConfig file](code-styles-and-code-cleanup.md#code-styles-in-editorconfig-files), if you have one for the project, or from the [code style settings](code-styles-and-code-cleanup.md#net-code-styles-in-the-options-dialog-box) in the **Options** dialog box.
102102

103103
## Debug your running code
104104

68.1 KB
Loading
3.5 KB
Loading

docs/toc.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -960,12 +960,10 @@
960960
href: ide/reference/options-text-editor-all-languages-scroll-bars.md
961961
- name: Tabs
962962
href: ide/reference/options-text-editor-all-languages-tabs.md
963-
- name: Basic
963+
- name: Visual Basic
964964
items:
965965
- name: Advanced
966966
href: ide/reference/options-text-editor-basic-visual-basic.md
967-
- name: Code Style
968-
href: ide/code-styles-and-code-cleanup.md
969967
- name: IntelliSense
970968
href: ide/visual-basic-specific-intellisense.md
971969
- name: C#

0 commit comments

Comments
 (0)