by Gabriel Lozano-Moran
26. May 2008 17:31
Microsoft has been working for years on a new static code analyzer which was internally known and used as StyleCode. This weekend Microsoft released the first bits and it has been officially named Microsoft Source Analysis for C#.
The difference between this new tool and FxCop is that Source Analysis analyzes the source code directly while FxCop analyzes the compiled binaries and as you know during the compilation there are some optimizations. So basically Source Analysis focuses on the design and the readability of the source code, things like the layout of members, elements, curly brackets, line spacing and so on.
I have given it a try and there are several rules I don't like:
- SA1600 errors for not commenting our private fields;
- SA1202 errors for having our protected fields after our private fields. This is also the default member order if you use R# code reformatting.
- SA1101 errors for calling members without the this prefix;
- SA1000 errors for not having a space after keywords like if;
- SA1200 errors for not having the using directives inside of the namespace;
- SA1309 errors for prefixing my private fields with an underscore;
- SA1013 errors because we put the curly braces for empty constructors on a single line;
- SA1502 errors for putting our abstract property declaration (automatic properties) on a single line;
- ... and many, many more;
All by all on a fairly small project I had 507 errors :( The good news is that you can disable these rules by right-clicking a project and choosing "Source Analysis Settings" from the context menu:
Anyway just try it out for yourself. Here are a couple of useful links to get started:
4cbb28ee-f7d1-4895-b95c-7fe291538f46|0|.0
Tags: