Anybody got a .vssettings file that matches StyleCop's rules?

Dec 10, 2012 at 5:09 PM

Hi,

does anybody have a .vssettings file (for C# text editor settings) that matches StyleCop's rules?

 

Yes, I'm aware that Visual Studio does not offer settings for every StyleCop rule. Nonetheless, it would be very convenient to have at least those violations fixed automatically by Edit->Advanced->Formatxx that are covered by Visual Studio's options (things like spaces around parentheses etc.)

Yes, probably R# can do that and even more.  But introducing StyleCop to an organization like mine is hard enough, even if you don't have to purchase another tool.

 

So if anybody has such a settings file (or maybe just an unordered list of VS settings that should be changed) it would be great if that could be made available for other people.

 

Thanks

Bernhard

Jan 4, 2013 at 3:25 PM
Edited Oct 7, 2013 at 9:51 AM
I've tried to create the settings myself. Just copy the XML from below to a text file and give it a .vssettings extension if you want to use it. If I've missed out on something please let me know.

Note 1: Those settings only concern the C# text editor and nothing else.

Note 2: I couldn't find out where some of the properties came from; check the comments

Note 3: You probably don't need or want the "InsertTabs" setting, but I thought most people will prefer spaces over tabs.

Note 4: As soon as StyleCop checks indentation, additional settings like "indent size" (and probably others) will become relevant. I've not included those for now.

Bernhard
<UserSettings>
    <ApplicationIdentity version="11.0"/>
    <ToolsOptions>
        <ToolsOptionsCategory name="TextEditor" RegisteredName="TextEditor">
            <ToolsOptionsSubCategory name="CSharp" RegisteredName="CSharp" PackageName="Text Management Package">
                <!-- Tabs -->
                <PropertyValue name="InsertTabs">false</PropertyValue>
            </ToolsOptionsSubCategory>
            <ToolsOptionsSubCategory name="CSharp-Specific" RegisteredName="CSharp-Specific" PackageName="Visual C# Language Service Package">

                <!-- Advanced -->
                <PropertyValue name="AutoComment">1</PropertyValue><!-- Generate XML documentation comments for /// -->
                <PropertyValue name="ImplementInterface_InsertRegionTags">1</PropertyValue>
                <PropertyValue name="SortUsings_PlaceSystemFirst">1</PropertyValue>

                <!-- Formatting: indendation -->
                <PropertyValue name="Indent_BlockContents">1</PropertyValue>
                <PropertyValue name="Indent_Braces">0</PropertyValue>
                <PropertyValue name="Indent_CaseContents">1</PropertyValue>
                <PropertyValue name="Indent_CaseLabels">1</PropertyValue>
                <PropertyValue name="Indent_FlushLabelsLeft">0</PropertyValue>
                <PropertyValue name="Indent_UnindentLabels">1</PropertyValue>

                <!-- Formatting: New lines -->
                <PropertyValue name="NewLines_Braces_Type">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_Method">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_AnonymousMethod">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_ControlFlow">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_AnonymousTypeInitializer">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_ObjectInitializer">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_LambdaExpressionBody">1</PropertyValue>

                <!-- The following 2 properties are probably supposed to place braces in collection and array initalizers on new lines.
                     However, they cannot be set in the GUI and they also seem to have no effect... -->
                <PropertyValue name="NewLines_Braces_CollectionInitializer">1</PropertyValue>
                <PropertyValue name="NewLines_Braces_ArrayInitializer">1</PropertyValue>

                <PropertyValue name="NewLines_Keywords_Catch">1</PropertyValue>
                <PropertyValue name="NewLines_Keywords_Finally">1</PropertyValue>
                <PropertyValue name="NewLines_Keywords_Else">1</PropertyValue>

                <PropertyValue name="NewLines_ObjectInitializer_EachMember">1</PropertyValue>
                <PropertyValue name="NewLines_AnonymousTypeInitializer_EachMember">1</PropertyValue>
                <PropertyValue name="NewLines_QueryExpression_EachClause">1</PropertyValue>

                <!-- Formatting: Spacing -->
                <PropertyValue name="Space_AfterMethodDeclarationName">0</PropertyValue>
                <PropertyValue name="Space_WithinMethodDeclarationParentheses">0</PropertyValue>
                <PropertyValue name="Space_BetweenEmptyMethodDeclarationParentheses">0</PropertyValue>

                <PropertyValue name="Space_AfterMethodCallName">0</PropertyValue>
                <PropertyValue name="Space_WithinMethodCallParentheses">0</PropertyValue>
                <PropertyValue name="Space_BetweenEmptyMethodCallParentheses">0</PropertyValue>

                <PropertyValue name="Space_InControlFlowConstruct">1</PropertyValue>
                <PropertyValue name="Space_WithinExpressionParentheses">0</PropertyValue>
                <PropertyValue name="Space_WithinCastParentheses">0</PropertyValue>
                <PropertyValue name="Space_WithinOtherParentheses">0</PropertyValue>
                <PropertyValue name="Space_AfterCast">0</PropertyValue>
                <PropertyValue name="Space_Normalize">0</PropertyValue>

                <PropertyValue name="Space_BeforeOpenSquare">0</PropertyValue>
                <PropertyValue name="Space_BetweenEmptySquares">0</PropertyValue>
                <PropertyValue name="Space_WithinSquares">0</PropertyValue>

                <PropertyValue name="Space_AfterBasesColon">1</PropertyValue>
                <PropertyValue name="Space_AfterComma">1</PropertyValue>
                <PropertyValue name="Space_AfterDot">0</PropertyValue>
                <PropertyValue name="Space_AfterSemicolonsInForStatement">1</PropertyValue>
                <PropertyValue name="Space_BeforeBasesColon">1</PropertyValue>
                <PropertyValue name="Space_BeforeComma">0</PropertyValue>
                <PropertyValue name="Space_BeforeDot">0</PropertyValue>
                <PropertyValue name="Space_BeforeSemicolonsInForStatement">0</PropertyValue>

                <PropertyValue name="Space_AroundBinaryOperator">1</PropertyValue>

                <!-- The following 2 properties are supposed to insert a space before and after the arrow in lambda expresseions.
                     They seem to work correctly, but they cannot be set in the GUI... -->
                <PropertyValue name="Space_AfterLambdaArrow">1</PropertyValue>
                <PropertyValue name="Space_BeforeLambdaArrow">1</PropertyValue>

                <!-- Formatting: Wrapping -->
                <PropertyValue name="Wrapping_PreserveSingleLine">0</PropertyValue>
                <PropertyValue name="Wrapping_KeepStatementsOnSingleLine">0</PropertyValue>

                <!-- I don't know what those 2 mean and where they come from -->
                <PropertyValue name="Wrapping_IgnoreSpacesAroundVariableDeclaration">0</PropertyValue>
                <PropertyValue name="Wrapping_IgnoreSpacesAroundBinaryOperators">1</PropertyValue>

                <!-- The following 2 might be useful but I don't know what they do and whether you can set them in the GUI. -->
                <PropertyValue name="RemoveUnusedUsings">1</PropertyValue>
                <PropertyValue name="SortUsings">1</PropertyValue>

                <!-- Those 2 settings seem to be related to the code definition window.
                     I have no idea what they are supposed to do, whether they work or not, and where you can set them in the GUI (if at all)... -->
                <PropertyValue name="CodeDefinitionWindow_DocumentationComment_IndentBase">1</PropertyValue>
                <PropertyValue name="CodeDefinitionWindow_DocumentationComment_WrapLength">80</PropertyValue>

            </ToolsOptionsSubCategory>
        </ToolsOptionsCategory>
    </ToolsOptions>
</UserSettings>