dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.13k stars 4.04k forks source link

editorconfig rules are ignored in cshtml files #46364

Open vsfeedback opened 4 years ago

vsfeedback commented 4 years ago

This issue has been moved from a ticket on Developer Community.


I have these rules defined in the editorconfig file:

csharp_new_line_before_open_brace = none
csharp_new_line_before_else = false
csharp_new_line_before_catch = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_between_query_expression_clauses = false

They work fine for .cs files, but are ignored for C# code in .cshtml files. If I set the corresponding settings in the UI (Tools - Options - Text editor - C# - Code Style - Formatting - New lines), the settings are also applied to cshtml files.


Original Comments

Ailsa Gu [MSFT] on 11/7/2018, 06:26 PM:

We appreciate you taking the time to report this problem. We are currently prioritizing problems that are impacting a broad set of our customers, so we may not be able to investigate this one immediately. We know this problem is important to you, so we will continue to monitor it.

Simo Paasisalo on 9/15/2019, 10:57 PM:

Same issue in VS19 - editorconfig indent size seems to work fine but for example

csharp_new_line_before_else = true

is not respected when formatting .cshtml files

duncan on 12/30/2019, 01:21 PM:

csharp_space_after_keywords_in_control_flow_statements

is also ignored in .cshtml files.

This is even when specifically targeting them via .editorconfig:

[*.{cs,cshtml}]
csharp_space_after_keywords_in_control_flow_statements = false

This is inconsistent behavior because as mentioned, configuring it in Options > Text Editor > Formatting > C# does affect .cshtml files.

#### Simo Paasisalo on 5/21/2020, 11:11 PM:

Updating to VS19 v 16.6.0 completely broke formatting for cshtml-files - braces previously on new lines are appended to end of the current line, indendations are all over the place etc. despite a previously working editorconfig

#### Feedback Bot on 7/27/2020, 04:31 PM:

This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available, or the issue is resolved.

--- ### Original Solutions (no solutions)
mavasani commented 4 years ago

I am presuming this could likely be due to the fact that the code behind files for C# code within this cshtml files are generated in intermediate directories outside the editorconfig cone. @dibarbet @jasonmalinowski do you know?

ian-a-anderson commented 4 years ago

I have the same issue in VS2019 Razor Pages, any progress on a fix?

SailorTurkey commented 3 years ago

Let me ask just in case, is there any workaround for the below problem

Simo Paasisalo on 5/21/2020, 11:11 PM: Updating to VS19 v 16.6.0 completely broke formatting for cshtml-files - braces previously on new lines are appended to end of the current line, indendations are all over the place etc. despite a previously working editorconfig

patriksvensson commented 3 years ago

I'm still seeing this in VS22 (Version 17.0.0 Preview 5.0).

ArtemAvramenko commented 2 years ago

This workaround is not suitable for everyone, but in VS 2022 I enabled this option: Tools > Options > Text Editor > HTML > Use legacy Razor editor for ASP.NET Core

y2kbugger commented 2 years ago

This workaround is not suitable for everyone, but in VS 2022 I enabled this option: Tools > Options > Text Editor > HTML > Use legacy Razor editor for ASP.NET Core

So this used to work?

https://github.com/dotnet/razor-tooling/issues/4406

ArtemAvramenko commented 2 years ago

So this used to work?

I guess the legacy editor doesn't respect editorconfig, but at least it doesn't break formatting.