WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

Visual Studio ruleset for coding guidelines - review

Open Depechie opened this issue 9 years ago • 7 comments

Was wondering about a warning the current ruleset gives to developers. When we write following code:

if (foo)
    CallBar();

We get a warning stating { } should not be omitted. But when we look at the ReadMe of the project ( https://github.com/Microsoft/UWPCommunityToolkit/blob/master/contributing.md ) we see that everything is referenced to the .Net foundation guidelines. Now, looking at those ( https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md ) we see that it's actually allowed to omit the brackets for one line code blocks.

We use Allman style braces, where each brace begins on a new line. A single line statement block can go without braces but the block must be properly indented on its own line and it must not be nested in other statement blocks that use braces

So just wondering if we could stop the warning.

Depechie avatar Mar 21 '17 14:03 Depechie

I'm in favor of this change, but only when exiting the current block. Examples: Exiting a method:

if(condition) return;

Continuing or exiting a loop

if(condition) continue;
if(condition2) break;

skendrot avatar Mar 21 '17 14:03 skendrot

Not to spawn of a new war of We do, You do... ( I always omit single line { } also for ForEach, For and If statements ) But IF you ref the .Net foundation guidelines, you should keep to those and not bloat up the warnings list.

Depechie avatar Mar 21 '17 14:03 Depechie

We will discuss it with core team to see if we keep the warning or not :) thanks for reporting

deltakosh avatar Mar 21 '17 16:03 deltakosh

TOTALY in favor ;)

Mimetis avatar Mar 24 '17 17:03 Mimetis

I have found that when having unordered Namespaces, that when you Auto-order them, they get inserted below the namespace. Is that an issue with the Ruleset?

WilliamABradley avatar Aug 19 '17 05:08 WilliamABradley

I have the exact issue that @WilliamABradley mentioned in previous comments in 2 of my previous PR's. Is this something to do with the rulesets itself?

avknaidu avatar Feb 13 '18 20:02 avknaidu

#1812 should prevent the namespaces from being moved.

In terms of the original request of this issue, we will keep the warning for single line blocks as there is no way to selectively ignore only lines exiting the block.

nmetulev avatar Feb 14 '18 05:02 nmetulev