Skip to content

Commit e8a9877

Browse files
authored
Merge pull request #1359 from MicrosoftDocs/gewarren-editorconfig-existingcode
Added note about new vs. existing code
2 parents 8767d6d + 396569f commit e8a9877

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ In Visual Studio 2017, you can add an [EditorConfig](http://editorconfig.org/) f
1919

2020
EditorConfig settings are supported by numerous code editors and IDEs, including Visual Studio. It's a portable component that travels with your code, and can enforce coding styles even outside of Visual Studio.
2121

22+
> [!NOTE]
23+
> When you add an EditorConfig file to your project in Visual Studio, the formatting of existing code is not changed unless you format the document (**Edit** > **Advanced** > **Format Document** or **Ctrl**+**K**, **Ctrl**+**D**). However, any new lines of code are formatted according to the EditorConfig settings.
24+
2225
## Coding consistency
2326

2427
Settings in EditorConfig files enable you to maintain consistent coding styles and settings in a codebase, such as indent style, tab width, end of line characters, encoding, and more, regardless of the editor or IDE you use. For example, when coding in C#, if your codebase has a convention to prefer that indents always consist of five space characters, documents use UTF-8 encoding, and each line always ends with a CR/LF, you can configure an .editorconfig file to do that.
@@ -44,7 +47,7 @@ EditorConfig editor settings are supported in all Visual Studio-supported langua
4447

4548
## Adding and removing EditorConfig files
4649

47-
Adding an EditorConfig file to your project or codebase does not convert existing styles to the new ones. For example, if you have indents in your file that are formatted with tabs, and you add an EditorConfig file that indents with spaces, the indent characters are not converted to spaces. However, any new lines of code will be formatted according to the EditorConfig file.
50+
Adding an EditorConfig file to your project or codebase does not convert existing styles to the new ones. For example, if you have indents in your file that are formatted with tabs, and you add an EditorConfig file that indents with spaces, the indent characters are not automatically converted to spaces. However, any new lines of code are formatted according to the EditorConfig file. Additionally, if you format the document (**Edit** > **Advanced** > **Format Document** or **Ctrl**+**K**, **Ctrl**+**D**), the settings in the EditorConfig file are applied to existing lines of code.
4851

4952
If you remove an EditorConfig file from your project or codebase, you must close and reopen any open code files to revert to the global editor settings for new lines of code.
5053

@@ -64,16 +67,16 @@ If you remove an EditorConfig file from your project or codebase, you must close
6467

6568
1. Edit the file as desired, for example:
6669

67-
```EditorConfig
68-
root = true
70+
```EditorConfig
71+
root = true
6972
70-
[*.{cs,vb}]
71-
indent_size = 4
72-
trim_trailing_whitespace = true
73+
[*.{cs,vb}]
74+
indent_size = 4
75+
trim_trailing_whitespace = true
7376
74-
[*.cs]
75-
csharp_new_line_before_open_brace = methods
76-
```
77+
[*.cs]
78+
csharp_new_line_before_open_brace = methods
79+
```
7780

7881
Alternatively, you can install the [EditorConfig Language Service extension](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.EditorConfig). After you install this extension, simply choose **Add** > **.editorconfig File** from the right-click or context menu of the solution node, project node, or any folder in Solution Explorer.
7982

@@ -87,7 +90,7 @@ To override some or all of the EditorConfig settings, add an .editorconfig file
8790

8891
![EditorConfig hierarchy](../ide/media/vside_editorconfig_hierarchy.png)
8992

90-
If you just want to override some but not all of the settings, simply specify those settings in the .editorconfig file. Only those properties that you explicitly list in the lower-level file will be overridden. Other settings from higher-level .editorconfig files will continue to apply. If you want to ensure that _no_ settings from _any_ higher-level .editorconfig files are applied to this part of the codebase, add the ```root=true``` property to the lower-level .editorconfig file:
93+
If you want to override some but not all of the settings, specify just those settings in the .editorconfig file. Only those properties that you explicitly list in the lower-level file are overridden. Other settings from higher-level .editorconfig files continue to apply. If you want to ensure that _no_ settings from _any_ higher-level .editorconfig files are applied to this part of the codebase, add the ```root=true``` property to the lower-level .editorconfig file:
9194

9295
```EditorConfig
9396
# top-most EditorConfig file
@@ -118,7 +121,7 @@ As expected, pressing the **Tab** key on the next line indents the line by addin
118121

119122
![Code before using EditorConfig](../ide/media/vside_editorconfig_before.png)
120123

121-
We'll add a new file called .editorconfig to the project, with the following contents. The `[*.cs]` setting means that this change applies only to C# code files in the project.
124+
Add a new file called .editorconfig to the project, with the following contents. The `[*.cs]` setting means that this change applies only to C# code files in the project.
122125

123126
```EditorConfig
124127
# Top-most EditorConfig file
@@ -139,7 +142,7 @@ If there is an EditorConfig file anywhere in the directory structure at or above
139142

140143
**"User preferences for this file type are overridden by this project's coding conventions."**
141144

142-
This means that if any editor settings in **Tools**, **Options**, **Text Editor** (such as indent size and style, tab size, or coding conventions) are specified in an EditorConfig file at or above the project in the directory structure, the conventions in the EditorConfig file override the settings in Options. You can control this behavior by toggling the **Follow project coding conventions** option in **Tools**, **Options**, **Text Editor**. Unchecking the option turns off EditorConfig support for Visual Studio.
145+
This means that if any editor settings in **Tools** > **Options** > **Text Editor** (such as indent size and style, tab size, or coding conventions) are specified in an EditorConfig file at or above the project in the directory structure, the conventions in the EditorConfig file override the settings in Options. You can control this behavior by toggling the **Follow project coding conventions** option in **Tools** > **Options** > **Text Editor**. Unchecking the option turns off EditorConfig support for Visual Studio.
143146

144147
![Tools Options - follow project coding conventions](media/coding_conventions_option.png)
145148

@@ -154,6 +157,7 @@ You can control the scope of your EditorConfig conventions by setting the ```roo
154157
## See also
155158

156159
[.NET code style conventions](../ide/editorconfig-code-style-settings-reference.md)
160+
[.NET naming conventions](../ide/editorconfig-naming-conventions.md)
157161
[Supporting EditorConfig for a language service](../extensibility/supporting-editorconfig.md)
158162
[EditorConfig.org](http://editorconfig.org/)
159163
[Writing code in the editor](writing-code-in-the-code-and-text-editor.md)

docs/ide/editorconfig-naming-conventions.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
---
2-
title: ".NET Naming Conventions For EditorConfig | Microsoft Docs"
2+
title: ".NET Naming Conventions For EditorConfig files | Microsoft Docs"
33
ms.custom: ""
44
ms.date: "11/20/2017"
55
ms.reviewer: ""
66
ms.suite: ""
7-
ms.tgt_pltfrm: ""
87
ms.topic: "article"
98
helpviewer_keywords:
109
- "naming conventions [EditorConfig]"
1110
- "EditorConfig naming conventions"
1211
author: "gewarren"
1312
ms.author: "gewarren"
1413
manager: ghogen
15-
ms.technology:
16-
- "vs-ide-general"
14+
ms.technology: vs-ide-general
1715
ms.workload:
1816
- "multiple"
1917
---
20-
# Naming Conventions for EditorConfig
18+
# .NET naming conventions for EditorConfig
2119

2220
Naming conventions concern the naming of code elements such as classes, properties, and methods. For example, you can specify that public members must be capitalized, or that asynchronous methods must end in "Async". You can enforce these rules by specifying them in an [.editorconfig file](../ide/create-portable-custom-editor-options.md). Naming rule violations appear either in the Error List or as a suggestion under the name, depending on the severity you choose for your rule. There is no need to build the project in order to see violations.
2321

0 commit comments

Comments
 (0)