官术网_书友最值得收藏!

Editor config

Editor config helps developers define and maintain consistent coding styles between different editors and/or IDEs. Microsoft has added support of Editor config in Visual Studio 2017.

The default text editor settings in Visual Studio applies to all projects of a given type. For example, if you change a C# or VB.NET text editor's settings, those settings will apply to all C# projects and VB.NET projects respectively. However, in general, the coding conventions that you use in your personal projects may differ from those used in your team's projects.

Here comes the Editor Config that enables you to do this on a per project basis and/or per folder level. In this case, the settings are contained in a .editorconfig file added to your code base. As the settings are contained in a file in the code base, they travel along with the code base:

The Editor Config doesn't support a full set of C# formatting rules and, hence, it's not a replacement for format settings in Visual Studio. Currently, it supports the following settings only in Visual Studio 2017:

  • indent_style
  • indent_size
  • tab_width
  • end_of_line
  • charset
  • root
  • trim_trailing_whitespace
  • insert_final_newline
  • Code style conventions

You can create an editor configuration file at the project level or at any folder level. When you add it to the project's root level, its settings are applied across all the files in the project. If you add it to any specific folder level inside the project, the root settings will be overridden and will apply to all applicable files at that level and below.

Did you know? Adding an .editorconfig file to your project or code base will not convert the existing styles to new ones. It will apply the settings to only newly added lines in that code base. To make an entire document adhere to the code formatting rules defined in your editor configuration, you can use the Format Document ( Ctrl + K, D) command.

To create an Editor Config (.editorconfig) file, right-click on a project or folder where you want to apply the settings, and then, from the context menu, click on Add | New Item..., as shown in the following screenshot:

Now, from the Add New Item dialog box, select the Text File template and give it a name, for example, .editorconfig, as shown in the following screenshot, to add the file. Note that the file name only consists of the extension of the file:

The .NET code style settings allow you to enforce the style that you want to use in your code base. Depending on the severity set in the Editor Config, it can show you a suggestion, a compiler warning, or compiler error. This can be written in the following fashion:

options_name = false|true : none|suggestion|warning|error 

The option must specify true (preferable) or false; a colon, :, and a severity of none, suggestion, warning, or error. The default is none.

If you set the severity as none, it will not show anything to the user when this style is not being followed. If you set it as a suggestion, it will show a suggestion (underlying dots on the first two characters) when the style is not being followed. In case of warning or error, it will either show compiler warning or compiler error if the code does not match the style being applied to it.

主站蜘蛛池模板: 黎平县| 民乐县| 泗阳县| 阿鲁科尔沁旗| 江城| 磴口县| 鲁山县| 来安县| 义乌市| 清河县| 甘谷县| 广水市| 安庆市| 江孜县| 台前县| 容城县| 江北区| 蚌埠市| 安龙县| 寻乌县| 会同县| 长兴县| 资阳市| 江山市| 施甸县| 土默特右旗| 博湖县| 遂宁市| 公主岭市| 伊通| 宿州市| 洪泽县| 横山县| 彝良县| 大厂| 安康市| 苏尼特右旗| 嘉黎县| 巴中市| 昌黎县| 陇川县|