templating icon indicating copy to clipboard operation
templating copied to clipboard

Please apply EditorConfig settings to template files

Open glen-84 opened this issue 3 years ago • 3 comments

When creating projects and solutions using dotnet new, it doesn't respect an existing EditorConfig file, and you end up with 2-space indentation, CRLFs, and some files (like launchSettings.json) with a BOM.

This isn't very cross-platform-friendly. In fact, the project was added from Linux, and I still got CRLFs.

Please:

  • Read and apply settings from an existing EditorConfig file.
  • If there is no EditorConfig file, apply settings based on the OS (f.e. LF on Linux and macOS).

This should not require any parsing or understanding of the template itself. Most text-like files can have these settings applied, or you can maintain a simple list of files (file extensions) that support them.

The following EditorConfig settings should be applied:

charset end_of_line indent_size indent_style insert_final_newline trim_trailing_whitespace

This would make it easier to get started without having to spend time fixing the files.

glen-84 avatar May 30 '22 18:05 glen-84

Related: https://github.com/dotnet/templating/issues/1248

vlada-shubina avatar May 31 '22 08:05 vlada-shubina

Ideally dotnet format would be called as an implicit post action and would apply the formatting changes. Unfortunately dotnet format is quite slow due to need to perform project evaluation.

Per discussion with @baronfel, we should try to inspect option of using dotnet format whitespace, skips the evaluation.

JanKrivanek avatar Jun 07 '22 09:06 JanKrivanek

@JanKrivanek

The problem with that is that dotnet format doesn't support files like .csproj .sln, .cshtml .razor, or other template files like appsettings.json, etc.

I wonder if dotnet format should add support for basic EditorConfig formatting in all (most) file types.

glen-84 avatar Jun 07 '22 17:06 glen-84

I've opened https://github.com/dotnet/format/issues/1798.

glen-84 avatar Jan 29 '23 11:01 glen-84

Close as duplicate of https://github.com/dotnet/templating/issues/5505. Please follow up there.

YuliiaKovalova avatar May 18 '23 11:05 YuliiaKovalova