Add support for enumerating count of suppressions/attributes
We have a situation where SuppressMessage attributes are being used very liberally in order to remove issues NDepend finds from the tech debt metrics. This is an unintended side effect of engineers attempting to get their tech debt percent to zero. I don't believe that this aligns with the spirit of the tool and I would like to create some custom rules/gates around issue suppressions in order to discourage their overuse. I am of the strong opinion that these attributes should be used sparingly and an excessive number of these attributes is a sign of tech debt, as it means we are intentionally ignoring tech debt.
I can use code such as the following to create a custom gate that fails at a certain number of suppressed issues:
/// <QualityGate Name="Excessive Issue Suppressions" Unit="issues" />
failif count > 10 issues
warnif count > 5 issues
from i in context.IssuesSet.AllSuppressedIssues
select new { i, i.Severity, i.Debt, i.AnnualInterest }
However, I would like to actually implement a rule that I can use to raise an issue based on the number of attributes used. I can formulate a rule to determine distinct number of types that specifically use the attribute:
from t in AttributeTargets
where t.AttributeClassesThatTagMe.WithName("SuppressMessageAttribute").Any()
select new {
t,
Count = t.AttributeClassesThatTagMe.WithName("SuppressMessageAttribute").Count()
}
However, there does not appear to be a way to give me a count of all the attributes that are decorating an AttributeTarget. The above query always returns a Count of 1. So for example, applying 4 attributes to one class will still only count as one occurrence in the CQLinq script. Such a rule becomes completely impossible if a GlobalSuppressions class is used, or any case when the attributes are all targeted to the assembly, so even if 20 SuppressMessage attributes are used, only one (just for the assembly) will count in the CQLinq result.
Please provide a method to get the count of attributes of a specific type.
Additionally, it would be good to know if there are suppressions that are not actually suppressing any issues, since often a suppression is added for a false positive, which is later fixed by NDepend. This would require adding actual suppression definitions to the code model. This would help to clean up suppressions that are added but are no longer needed and should be removed.