Search code examples
c#stylecop

CodeMaid vs Stylecop usings organisation


I am using StyleCop for a quite a while (and I am used to it). Friend of mine recommended me to also try CodeMaid. First thing I've noticed is difference in usings organisation.

Stylecop orders usings in alphabetical order where System usings are listed first and non-system usings are listed below.

CodeMaid orders usings also in alphabetical order but it does not order System usings first. It only orders usings alphabetically

Another thing I came across is that CodeMaid allows you to have usings outside of namespace (and as far as I know it is better to place all the usings within the namespace)

I wanted to ask what is the proper ordering of usings and eventually why?


Solution

  • Disclaimer: I wrote CodeMaid.

    1. For System using statements being first, Microsoft changed their default preferences in Visual Studio 2012 as they started introducing "Windows." assemblies. More details here: Using Directives Sorted in Wrong Order

    You can easily change this back to the VS2010 default at Tools->Options->Text Editor->C#->Advanced->"Place 'System' directives first when sorting usings". CodeMaid respects the Visual Studio defined preference which defaults to not putting System directives first.

    1. For using statements being inside the namespace, it is on our backlog to support that https://trello.com/c/CLRxsIyc . StyleCop may state it as the standard, but if you look at MSDN examples, Visual Studio templates, etc. you'll find using statements outside the namespace is far more conventional. There is a lot of debate on that issue and our goal is to support both approaches.

    Hope it helps. :)