Open gtbuchanan opened 2 years ago
One could possibly argue that a method that needs comments are better off not using expression bodies in the first place, but it's of course not desirable if you can't get StyleCop to harmonize with editor config settings that looks perfectly reasonable.
Updating SA1515 to allow this as well seems easy enough, so this suggestion seems reasonable to me.
It seems that:
Both of these strategies are already compatible with StyleCop Analyzers, so I'm not sure any change is warranted here.
@sharwell I agree that 1 would be preferable but it does not play well with IDE0022 and suppression for a short comment is not ideal. 2 is okay but converting to a statement body later might leave the comment ambiguous. Converting to a statement body (ReSharper refactor?) with the comment how it is in the OP will preserve the comment location above the line of code.
If you're opposed to adding an exception for this, can the documentation be updated to mention expression-bodied members are not included in the "first item within its scope" comment (or perhaps change "scope" to "block")? It's more of an annoyance than anything but I can explain the workarounds to my team if I need to.
I'm also stumbling over this issue and I see it like @gtbuchanan
@sharwell / @bjornhellander : Can you please provide an update about this?
@sharwell / @bjornhellander : friendly ping :)
SA1515 for single-line comments states:
I would expect this exception to also apply to expression-bodied members. However, SA1515 is triggered in this case:
I confirmed that the exception works fine when changing the method to have a normal body.
Though, we're currently using the
////
workaround instead since we've setcsharp_style_expression_bodied_methods = true:error
in.editorconfig
to enforce expression-bodied methods in situations where it is possible.Tested with 1.2.0-beta.435.