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

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.

主站蜘蛛池模板: 梁平县| 沁阳市| 栾川县| 福海县| 通城县| 禄丰县| 亳州市| 许昌县| 霸州市| 琼结县| 花莲市| 女性| 莎车县| 疏附县| 江津市| 中方县| 海门市| 卫辉市| 沂水县| 台中市| 抚松县| 香河县| 云浮市| 盖州市| 叙永县| 彭泽县| 博客| 麻栗坡县| 新郑市| 岚皋县| 开鲁县| 鹤山市| 大名县| 泰和县| 邛崃市| 长葛市| 咸阳市| 彩票| 浠水县| 盐源县| 临城县|