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
18.99k stars 4.03k forks source link

IDE2001 is not compatible with brace placement at the end of a line #72189

Open vsfeedback opened 8 months ago

vsfeedback commented 8 months ago

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


In Tools -Options - Text Editor - C# - Code Style, setting "Allow embedded statements on same line" to "No" causes analyzer errors to be reported on every non-embedded statement


Original Comments

Feedback Bot on 2/20/2024, 04:32 AM:

(private comment, text removed)


Original Solutions

(no solutions)

sharwell commented 8 months ago

IDE2001 is reported for the braces at the end of lines, even when csharp_new_line_before_open_brace omits control_blocks:

if (a) {
} else {
}
CyrusNajmabadi commented 7 months ago

By design. These are strictly not compatible options. The new-experimental options are not meant to compliment the existing options. They're meant to supersede (they do not look at, or otherwise consider any other options at all). In this case, the options is strict and intentional. Embedded states are simply not allowed to start on the prior line.

sharwell commented 7 months ago

As a former user of brace placement at the end of a line who also disallowed embedded statements on the same line, I'm reopening this issue since I can certainly see the value of it. It's a fairly simple approach to make these work together (only the brace itself would need to be checked differently when the option is set).

I would be amenable to removing the option of placing braces at the end of a line and closing this as a result (provided it could be added back by a 3rd-party formatting extension), but as long as we have both options it makes sense to allow them to work together if someone sends a PR to do so.