tags:

views:

127

answers:

2

I'm trying to get NDepend to identify long methods using a modified version of the standard "Methods too big" query.

I don't want to report long methods that the developers have little control over, so I filter out generated code using the DebuggerNonUserCode attribute and InitializeComponent().

Unfortunately, I still get a few false positives as methods in generated types are reported as well. The problem is that while the type itself has the DebuggerNonUserCode attribute, the methods do not, so they are included in the output despite the fact that they are generated.

I am looking for something like a join between types and methods: Give me all types that do not have the DebuggerNonUserCode attribute and run the query on those, but I can't figure out how to express this in CQL.

For some of the assemblies, I can simply filter on the full name, but unfortunately some of our assemblies mix developer made and generated types. Unfortunately the IsGeneratedByCompiler can't be used either in this case.

My query

WARN IF Count > 0 IN SELECT METHODS WHERE 
   NbLinesOfCode > 30 AND
   !HasAttribute "System.Diagnostics.DebuggerNonUserCodeAttribute" AND
   !NameIs "InitializeComponent()"
   ORDER BY NbLinesOfCode DESC
A: 

I quite like NDepend, but it's still the biggest single shortcoming that namespace/type/method info cannot be joined into a single query. That feature would make CQL really powerful stuff.

Apart from that the checks 'IsGeneratedByCompiler' and 'IsInFrameworkAssembly' may be helpful. You can also remover certain namespaces from the query (OUT OF NAMESPACES "...")

flq
It certainly would! I'm aware of the OUT OF feature, but unfortunately the relevant assemblies lump both dev made code and generate code in the same namespace :(
Brian Rasmussen
+1  A: 

I asked NDepend's support about joining methods and type info; the answer is that it is a planned feature for the next 12 months.

Timores
Thanks for the effort.
Brian Rasmussen