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

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.

主站蜘蛛池模板: 石林| 桐庐县| 秀山| 武清区| 繁峙县| 航空| 通渭县| 合川市| 华容县| 长寿区| 西昌市| 田林县| 句容市| 白水县| 泽普县| 金寨县| 阳曲县| 文山县| 广宁县| 沛县| 循化| 平邑县| 凤阳县| 潼南县| 中西区| 聂拉木县| 南丹县| 沿河| 大同市| 凤山市| 平阳县| 双城市| 泸定县| 易门县| 平罗县| 疏勒县| 思南县| 安远县| 兴山县| 珠海市| 苍南县|