Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

Does the stylecop modify or arrange our C# code as per the rules set?...
Or it will just show the errors and warnings?....
do we ourself need to make it clear??.
Thanks
Jim
Posted
Updated 21-Oct-13 4:40am
v2

1 solution

StyleCop integrates with Visual Studio, and is accessible from the 'Tools Menu. During the install you can choose whether StyleCop integrates with Visual Studio, or MS Build, or both.

It does not automatically change your source code !

When you run it, it will write a summary report on how many of its "rules" you have violated. This is written to the 'Output Window of Visual Studio.

The specific error messages are written to the "Error List" window.

StyleCop, using its default settings, may surprise you by what it finds in your code:

1. it will flag uses of the Tab character as a violation

2. it wants 'using directives inside the NameSpace

3. it really wants to see you use 'this as a prefix to object references even though your code will run fine without using 'this.

I used StyleCop for a while, but just got tired of it; however, I am not currently part of a programming team where having everyone conform to a certain set of code guidelines is critical.

You can configure StyleCop, however, to your taste by removing rules, etc.

See the StyleCop docs for information on customizing it: [^].
 
Share this answer
 
Comments
jim1972 21-Oct-13 11:28am    
hello. thanks for the reply.
so my worry is if it just showing us which rules are being voilated and not helping us to refactor the violated code, it will not be that helpful for a developer? isn't it?.
Like in, resharper helps us to identify the violated rules and helping us to refactor it also.

thanks
jim
BillWoodruff 21-Oct-13 11:38am    
Hi Jim, It's been a while since I've used StyleCop, but I doubt it has changed that much. It is really a tool for semantic analysis, not a tool for re-factoring. I use ReSharper now, and love it.

And, for me, the way Visual Studio itself re-formats code is quite acceptable.

Typically using StyleCop, I'd have to use search-and-replace in Visual Studio to fix syntax that StyleCop flagged.

By the way, StyleCop, by default, does not "like" one-true-brace style curly-brace syntax, and it "hates" Hungarian Notation :)

Why don't you try it out: it's free, and it won't do anything to your source code.

You also might check out nArrange, another free-tool that does some prettying-up of your code: http://www.NArrange.net

Check out what other folks on CP say about nArrange: http://www.codeproject.com/search.aspx?q=nArrange&sort=createddesc
jim1972 21-Oct-13 12:10pm    
thanks alot billwood. From your experience sharing, i concluded to opt the resharper, which helps us to refactor the code.
thanks
Jim
jim1972 21-Oct-13 12:12pm    
and also, will try the nArrange too..
Sergey Alexandrovich Kryukov 21-Oct-13 11:45am    
My 5.

Now, I already mentioned that FxCop rules have some stupidities.

As to the StyleCop, in my opinion, almost all rules are stupidities. I would recommend to use FxCop (with removing rules), but hardly StyleCop.

About some particular rules:

I really think that using directives inside a name space declaration is better style, at least to my taste. But! I once found a case when it causes a problem which can be fixed only if you pop some using directive outside of namespaces. Enforcing this rule could break functionality! (Sorry, it's hard to remember how to reproduce this problem, I only remember that when I found the problem and the solution, it was 100% apparent to me. It was something like circular namespace dependency.)

StyleCop enforced alphabetical order of using directives. This is not about good or bad style, this means total lack of understanding what is the purpose of the style. For example, I order my lines semantically. They can be automatically sorted. It actually means destroying some information: you turn some information expressed in "style" into default. I think destructive nature of such "styling" is apparent...

Moreover, with time I came to conclusion that 1) good style should be required from team member and can be critical, 2) attempts to enforce one particular style (see the difference between "good" and "one particular style", even if it is good?) just kills the development process. Styles of different members of the team have to be different!.

Practically, some unacceptable style flaws should be required to fix (often, this is often done by not working with unfit people), but on top of it people should enjoy as much style freedom as possible, as soon as the style is neat enough.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900