saran
saran

Reputation:

How to write static code analyzer for .net

I am interested in writing static code analyzer for vb.net to see if it conforms to my company standard coding guidelines. Please advise from where i have to start.

Upvotes: 5

Views: 812

Answers (8)

Alex Fort
Alex Fort

Reputation: 18819

I would suggest you use Mono's Gendarme. It's a very nice tool, with plenty of built in rules. It also generates nice HTML reports.

Upvotes: 4

aaimnr
aaimnr

Reputation: 1646

I agree with one of the posters that it would be a quite difficult taks, but rather than with Lisp I'd start with F#, just like Microsoft did for their 3rd party windows drivers analysis tool:

http://arstechnica.com/journals/microsoft.ars/2005/11/10/1796

F# shares Lisp's expressiveness (ok, almost) and works on CLR just like VB.NET, which would make the whole thing easier.

Upvotes: 0

Krzysztof Kozmic
Krzysztof Kozmic

Reputation: 27384

if you need mroe architectural insight use NDepend. This tool does not stop to amaze me. It can do soo much more than FxCop. It's commercial though, but has a free trial version

Upvotes: 2

alnayyir
alnayyir

Reputation: 9

Use FxCop, this isn't a project you want to undertake personally. The parsing/lexical rules involved and the possible catches would be insane. The only way I could imagine doing it while retaining a modicum of sanity would be to use Lisp thanks to the extreme amount of expressiveness, but again, best to use FxCop.

If you must write a custom in-house tool for some (dogmatic?) reason, I'd recommend writing a Lisp program that does only basic rules-checking. Don't try to make it comprehensive, we're talking the kind of frontier that AI researchers are dealing with in terms of the parsing capabilities of a piece of software.

Just use Lisp to find the possible obvious offenders, or just at catching whatever it ends up being good at catching in terms of non-compliant code, then subject it to a brief human eye scan. I highly recommend abusing macros if you do use Lisp to write the parser.

Upvotes: 0

David B Heise
David B Heise

Reputation: 396

FXCop is a good start for coding problems/mistakes, StyleCop is good for coding style (obviously), but if neither of those two work then you then you can either write a parser yourself or use the VBCodeProvider class in the .Net Framework

Upvotes: 1

Scott Dorman
Scott Dorman

Reputation: 42526

The best options are to use FxCop or StyleCop and write custom rules if necessary.

Upvotes: 0

Jonathan Rupp
Jonathan Rupp

Reputation: 15782

Start with FxCop. If you can't do what you're trying there, try something like NStatic or NDepend.

Upvotes: 0

Haacked
Haacked

Reputation: 59061

Rather than write your own static code analyzer, I recommend you use FxCop: and instead, write custom FxCop rules for your needs. It'll save you a lot of time. http://www.binarycoder.net/fxcop/

Upvotes: 16

Related Questions