roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

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

Open vsfeedback opened this issue 1 year ago • 3 comments

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)

vsfeedback avatar Feb 20 '24 21:02 vsfeedback

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 {
}

sharwell avatar Feb 20 '24 21:02 sharwell

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.

CyrusNajmabadi avatar Feb 20 '24 22:02 CyrusNajmabadi

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.

sharwell avatar Feb 21 '24 15:02 sharwell