Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to exclude entire namespaces from NDepend analysis?

I have a setup where Visual Studio 2010 runs test coverage analysis and it's output is absorbed by NDepend during an integration build.

A few assemblies contain generated code that needs to be ignored by NDepend.
Is there a way to do this? Preferably an entire namespace.

like image 307
Kilhoffer Avatar asked Sep 12 '11 15:09

Kilhoffer


2 Answers

Code Query and Rule over LINQ (CQLinq) indeed provides a facility to ignore generated code.

There is the convenient predefined domain named JustMyCode of type ICodeBaseView.

The domain JustMyCode represents a facility of CQLinq to eliminate generated code elements from CQLinq query results. For example the following query will only match large methods that are not generated by a tool (like a UI designer):

from m in JustMyCode.Methods where m.NbLinesOfCode > 30 select m

The set of generated code elements is defined by CQLinq queries prefixed with the CQLinq keyword notmycode. For example the query below matches methods defined in source files whose name ends up with ".designer.cs":

notmycode from m in Methods where
  m.SourceFileDeclAvailable && 
  m.SourceDecls.First().SourceFile.FileName.ToLower().EndsWith(".designer.cs")
select m

The CQLinq queries runner executes all notmycode queries before queries relying on JustMyCode, hence the domain JustMyCode is defined once for all. Obviously the CQLinq compiler emits an error if a notmycode query relies on the JustMyCode domain.

There are 4 default notmycode queries, easily adaptable to match your need. Notes that there is no default notmycode queries for namespaces but you can create your own one(s):

  • Discard generated Assemblies from JustMyCode
  • Discard generated Types from JustMyCode
  • Discard generated and designer Methods from JustMyCode
  • Discard generated Fields from JustMyCode
like image 51
Patrick from NDepend team Avatar answered Nov 17 '22 21:11

Patrick from NDepend team


Found this in the "Quick summary of methods to refactor"

// Here are some ways to avoid taking account of generated methods.
!( NameIs "InitializeComponent()" OR
   // NDepend.CQL.GeneratedAttribute is defined in 
   // the redistributable assembly $NDependInstallDir$\Lib\NDepend.CQL.dll
   // You can define your own attribute to mark "Generated".
   HasAttribute "OPTIONAL:NDepend.CQL.GeneratedAttribute") 

But that doesn't address the need to modify every CQL query to ensure they all ignore the generated code.

like image 31
rbellamy Avatar answered Nov 17 '22 21:11

rbellamy