Unnecessary NDepend SuppressMessageAttribute Usage
Finds SuppressMessageAttribute("NDepend", ...) usages that suppress no NDepend issue; they can be safely removed. Disabled by default (advanced usage only). On test code, only ND1611 suppressions are checked: no other default rule reports issues there. Doc: https://www.ndepend.com/docs/suppress-issues
CQLinq source
This quality gate 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.
// <QualityGate Name="Unnecessary NDepend SuppressMessageAttribute Usage" Unit="usages" />
failif count > 50
warnif count > 0
// There can be several SuppressMessageAttribute
// in System.Runtime, netstandard and mscorlib for example
let suppressAttributes = ThirdParty.Types.
WithFullName("System.Diagnostics.CodeAnalysis.SuppressMessageAttribute")
// Get the tags of SuppressMessageAttribute used
// from suppressed issues
let ndpSuppressTagsUsed =
(from i in context.IssuesSet.AllSuppressedIssues
where i.Rule.Provider == RuleProvider.CodeQueryRule
select i.SuppressAttributeTag).ToHashSetEx()
// Get all tags like SuppressMessageAttribute("NDepend"...)
let allNdpSuppressTags = suppressAttributes
.SelectMany(sa => sa.TagsWithMeAsAttribute)
// Filter only NDepend category
.Where(s => s.ValueOf("Category") != null &&
s.ValueOf("Category").AsString.StartsWith("NDepend"))
// Infer unnecessary tags like SuppressMessageAttribute("NDepend"...)
let ndpTagsSuppressUnused = allNdpSuppressTags.Except(ndpSuppressTagsUsed)
// Uncomment to get instead all tags that actually suppress one or several issues
//from tag in ndpSuppressTagsUsed
from tag in ndpTagsSuppressUnused
let checkId = tag.ValueOf("CheckId") == null ? null : tag.ValueOf("CheckId").AsString
where !tag.CodeElementTagged.IsThirdParty &&
// Rules don't report issues on test code except ND1611 'Test methods should assert something':
// there, only an ND1611 suppression can be unnecessary
(!tag.CodeElementTagged.IsTestCode ||
(checkId != null && (checkId == "ND1611" || checkId.StartsWith("ND1611:"))))
select new {
tag.CodeElementTagged,
tag.AttributeType,
desc=tag.Parameters.Select(p =>p.Name +": "+p.Value.AsString).Aggregate(", ")
}
//<Desc>
// Finds SuppressMessageAttribute("NDepend", ...) usages that suppress no
// NDepend issue; they can be safely removed. Disabled by default (advanced
// usage only). On test code, only ND1611 suppressions are checked: no
// other default rule reports issues there.
// Doc: https://www.ndepend.com/docs/suppress-issues
//</Desc>
Open in the interactive Rules Explorer · All default rules
Quality Gates: all 19 items
- Quality Gates Evolution
- Percentage Coverage
- Percentage Coverage on New Code
- Percentage Coverage on Refactored Code
- Percentage Coverage (JustMyCode)
- Percentage Coverage on New Code (JustMyCode)
- Percentage Coverage on Refactored Code (JustMyCode)
- Blocker Issues
- Critical Issues
- New Blocker / Critical / High Issues
- Critical Rules Violated
- Treat Compiler Warnings as Error
- Percentage Debt
- Debt
- New Debt since Baseline
- Debt Rating per Namespace
- Annual Interest
- New Annual Interest since Baseline
- Unnecessary NDepend SuppressMessageAttribute Usage