Validating CQLinq Code Rules in Visual Studio

One popular aspect of the tool NDepend is the integration of the tool into the Continuous Integration build process. Every morning the team leader gets an up-to-date report telling if some coding rules written with CQLinq have been violated within the last 24h.

NDepend integrated in Visual Studio 2013, 2012, 2010 and 2008 is a smoother answer to the critical scenario when a developer violates a rule. Waiting till the day after to discover that a rules get violated is too long, it is not enough agile-oriented. Hence CQLinq rules violation warn as soon as possible, right within Visual Studio.

All CQLinq rules get checked into Visual Studio as soon as one or several VS projects have been (re)compiled.

▲▲ Go to Top ▲▲


Checking if there are Rules Violations

The developer gets permanently informed of CQLinq rules validation status thanks to a NDepend progress circle located in the bottom-right corner of the Visual Studio window.
  • green, means that all CQLinq rules are validated,

  • yellow, means some activated CQLinq rules are violated,

  • red, means:
    • some critical CQLinq rules are violated or
    • some activated CQLinq rules or queries don’t compile or
    • some activated CQLinq rules or queries have an execution problem (exception thrown or time-out)

  • blue + progressing, means that the code is currently loaded by NDepend,

  • blue + progressing + turning chevrons, means that the code is currently analyzed by NDepend,

  • grey, means that no NDepend project is currently loaded in VisualStudio.

On the NDepend Dashboard, you can see the number of rules violated and the number of rules violations.



Notice that Rules Violated, Critical Rules Violated... are links. When clicked, the related rules or queries are listed in the Queryies and Rules Explorer panel.


▲▲ Go to Top ▲▲


Rules Explorer and Rules Edition

The CQLinq Explorer lists all rules grouped by categories…



…and by clicking a rule you can jump to the CQLinq edition panel, where you can edit the rule and see culprit methods or classes that violate the rule.



Of course double clicking a culprit method or class lets jump to its source code declaration. And if the application analyzed by NDepend spawns several VS solutions, and these solutions are currently opened in several VS instances, the code element gets edited within the adequate VS instance, the one that contains the VS solution that contains the code element. This behavior at first glance might surprise and even look like a bug. But with the habits it becomes a powerful time-saver trick. And this multi-VS-instances communication trick is made possible thanks to the Application-Wide code analysis of NDepend.

▲▲ Go to Top ▲▲


Focusing on Recent Code Rules Violations

On a large legacy code base, NDepend will likely report thousands of code violations. NDepend proposes the possibility to focus only on recent code rules violations. Only violations that occur on code elements added or refactored since the baseline for comparison will be reported.

Hence this feature represents a way to prioritize the rules violations be reducing significantly the number of violations reported to focus only on recent ones. To activate this feature, both on rules violations reported in the interactive UI and in the report, just tick the box Recent Violations Only on the Dashboard. A baseline for comparison needs to be defined to get this feature working.





▲▲ Go to Top ▲▲


Rules Execution Options



Finally, in the form shown on progress circle hovering with mouse, there are 2 links Analysis Execution and Analysis Refresh in VS.
  • The option panel Analysis Refresh in VS let’s customize when an NDepend analysis should occurs.



  • The option panel Analysis Execution let’s finally customize the analysis process (incremental/full analysis, in/out process, report generation…).