API Breaking Changes: Types

Rule ND1500 API Breaking Changes

Runs only in diff mode (baseline defined). Warns if a type publicly visible in the baseline is no longer public or has been removed: client code using it will be broken.

How to fix

Keep public types public, now and in the future. If a public type must be removed, tag it with System.ObsoleteAttribute and a workaround message for a few releases first (obsolete-tagged removals are not matched).

Severity is High: an API Breaking change can provoke significant friction with API consumers.

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>API Breaking Changes: Types</Name>
// <Id>ND1500:APIBreakingChangesTypes</Id>

warnif count > 0 from t in codeBase.OlderVersion().Application.Types
where t.IsPubliclyVisible 

let reason = 
   // The type has been removed, it was not tagged as obsolete
   // and its parent assembly hasn't been removed …
     ( t.WasRemoved() && 
      !t.ParentAssembly.WasRemoved() && 
      !t.IsObsolete) ? "was public and has been removed" :

   // … or the type is not publicly visible anymore
     (!t.WasRemoved() && !t.NewerVersion().IsPubliclyVisible) ?
   "used to be publicly visible but not anymore" : null

where reason != null

select new { 
   t,
   NewVisibility = 
      (t.WasRemoved() ? " " : 
       t.NewerVersion().Visibility.ToString()),
   reason,
   Debt = 20.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>The *{0}* {2}. This breaks client code using it.</Expl>

//<Desc>
// Runs only in *diff mode* (baseline defined). Warns if a type publicly
// visible in the *baseline* is no longer public or has been removed:
// client code using it will be broken.
//</Desc>

//<HowToFix>
// Keep public types public, now and in the future. If a public type must be
// removed, tag it with *System.ObsoleteAttribute* and a *workaround message*
// for a few releases first (obsolete-tagged removals are not matched).
//
// Severity is **High**: an API Breaking change can provoke significant
// friction with API consumers.
//</HowToFix>

API Breaking Changes: all 9 items