What is the difference between "StyleCop" vs. "VS2010 Code Analysis" vs. "FxCop"

I had this conversation the other day and started some investigation into this. Here is my quick recap from the below links

  • VS2010 Code analysis includes FxCop + more
  • VS2010 Code analysis and FxCop analyze assemblies
  • StyleCop is not part of the VS2010 Code analysis suite and checks C# coding style
  • StyleCop analyses source code

from

StyleCop interferes with Resharper (which I prefer, because there you can change which layout you prefer)

PS

There is a tool called StyleCopFixer that can automatically resolve some StyleCop issues

http://visualstudiogallery.msdn.microsoft.com/en-us/ea197362-8fa1-44c8-8be2-e2b87d12be2a?SRC=Home

StyleCopFixer works only with VS2010

Right click on a warning from StyleCop shows you "Fix it" from StyleCopFixer

clip_image002

PPS

I gave StyleCop a quick test

StyleCop didn't like the following yellow, which I like

Warning SA1009: Invalid spacing around the closing parenthesis

        public void UpdateBuyerBidBasis(long auctionID, string lotNumber, string usercode, short bidBasisType, float levy, string trim, float skinValue)
        {
            using (var dc = new AuctionEntities())
            {
                var foundBasis = dc.AuctionBidBasis.FirstOrDefault(l => (l.LotNumber == lotNumber &&
                                                                            l.AuctionID == auctionID &&
                                                                            l.UserCode == usercode
                                                                        )
                                                                  );

 

StyleCopFixer changed that to the following, which is worse I think!
Parenthesis aligned to the start of the line, ignoring completely my indentation

        public void UpdateBuyerBidBasis(long auctionID, string lotNumber, string usercode, short bidBasisType, float levy, string trim, float skinValue)
        {
            using (var dc = new AuctionEntities())
            {
                var foundBasis = dc.AuctionBidBasis.FirstOrDefault(l => (l.LotNumber == lotNumber &&
                                                                            l.AuctionID == auctionID &&
                                                                            l.UserCode == usercode
)
);

My recap

I don't like StyleCopFixer, but I like StyleCop

Rules I like

· SA1201: All methods must be placed after all properties.              

· SA1119: The line contains unnecessary parenthesis

Rules I don't like

· SA1309: Field names must not start with an underscore.
This is completely dependent who you are working with, some teams want to have that for private members, some don't…
I say "stick to one standard in your team"

2 comments:

Anonymous said...

>SA1309: Field names must not start with an underscore.

Why not using NDepend and decide easily with a regex what kind of naming rule your want thanks to CQL flexibility? For example:

// A static field should not be named 'm_XXX'
WARN IF Count > 0 IN SELECT FIELDS WHERE
NameLike "^m_" AND
IsStatic
ORDER BY FieldCa DESC

Peter Gfader said...

Hi Anonymous

Yes, NDepend sounds good ... that means introducing another tool to check your code for compliance

It would be nice to use 1 tool for everything...

Post a Comment

Latest Posts

Popular Posts