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
- http://stackoverflow.com/questions/580168/visual-studio-code-analysis-vs-stylecop-fxcop
- http://blogs.msdn.com/b/sourceanalysis/archive/2008/07/20/clearing-up-confusion.aspx
- You can find an HTML with a list of rules for StyleCop 4.3
http://www.thewayithink.co.uk/stylecop/stylecop4_3rules.htm
Current version is 4.4 though
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
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:
>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
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