vs2010代码指标的扩展/可扩展点在哪里?

时间:2010-07-27 18:00:09

标签: visual-studio-2010 static-analysis code-metrics

我想扩展2010年静态代码分析指标(主要是修复它,因此汇总是最大值而不是总和)。可扩展点在哪里?它是某个MEF组件吗?

1 个答案:

答案 0 :(得分:0)

我不确定VS 2010指标是否有任何可扩展性点。

或者,您可以选择82 code metrics附带的NDepend,定义阈值就像编写短Code Rule over LINQ Query (CQLinq)一样简单:

warnif count > 0 from m in Application.Methods where 
m.NbLinesOfCode > 30 || m.CyclomaticComplexity > 10
select new { m, m.NbLinesOfCode, m.CyclomaticComplexity }

您还可以在默认的CQLinq代码规则中查找趋势:Avoid making complex methods even more complex (Source CC)

// <Name>Avoid making complex methods even more complex (Source CC)</Name>
// To visualize changes in code, right-click a matched method and select:
//  - Compare older and newer versions of source file
//  - Compare older and newer versions disassembled with Reflector

warnif count > 0 
from m in JustMyCode.Methods where
 !m.IsAbstract &&
  m.IsPresentInBothBuilds() &&
  m.CodeWasChanged()

let oldCC = m.OlderVersion().CyclomaticComplexity
where oldCC > 6 && m.CyclomaticComplexity > oldCC 

select new { m,
    oldCC ,
    newCC = m.CyclomaticComplexity ,
    oldLoc = m.OlderVersion().NbLinesOfCode,
    newLoc = m.NbLinesOfCode,
}

您还可以撰写建议的代码指标,以定义您自己的代码指标,例如C.R.A.P method code metric

// <Name>C.R.A.P method code metric</Name>
// Change Risk Analyzer and Predictor (i.e. CRAP) code metric
// This code metric helps in pinpointing overly complex and untested code.
// Reference: http://www.artima.com/weblogs/viewpost.jsp?thread=215899
// Formula:   CRAP(m) = comp(m)^2 * (1 – cov(m)/100)^3 + comp(m)
warnif count > 0
from m in JustMyCode.Methods

// Don't match too short methods
where m.NbLinesOfCode > 10

let CC = m.CyclomaticComplexity
let uncov = (100 - m.PercentageCoverage) / 100f
let CRAP = (CC * CC * uncov * uncov * uncov) + CC
where CRAP != null && CRAP > 30
orderby CRAP descending, m.NbLinesOfCode descending
select new { m, CRAP, CC, uncoveredPercentage = uncov*100, m.NbLinesOfCode }