Critical Rules

NDepend comes with the notion of Critical CQLinq Rule. Critical rules represent a mean to define high priority rules that must never be violated.

A critical rule is just a CQLinq rule with the flag Critical Rule checked:

ndepend cqlinq csharp linq critical code rule

With critical rules, it is possible to break the Build Process when a critical rule violation occurs. To do so, just make sure that this default Quality Gate is enabled (it is enabled by default).

// <QualityGate Name="Critical Rules Violated" Unit="rules" />
failif count > 0 rules
from r in Rules where r.IsCritical && r.IsViolated()
select new { r, issues = r.Issues() }
ndepend cqlinq csharp linq quality gate critical code rule

At development time, the NDepend interactive UI (integrated in VisualStudio, or VisualNDepend.exe standalone) comes with several visual indicators when a critical rule is violated:

  • The bottom-right circle becomes red.
  • The number of critical rule violated is shown in the bottom-right circle tooltip panel.
  • In Queries and Rules Explorer panel, violated rules status have a top-left red flag.
  • In Queries and Rules Explorer panel, the status of groups that contains a violated rules have a top-left red flag.

ndepend cqlinq csharp linq critical code rule shown in the ndepend dashboard