2010-07-27 127 views

回答

0

我不確定VS 2010指標是否有任何可擴展性。

或者,你可以選擇NDepend的附帶82 code metrics和定義的閾值是一樣容易寫短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 }