Skip to content

Instantly share code, notes, and snippets.

Created September 26, 2013 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6711976 to your computer and use it in GitHub Desktop.
Save anonymous/6711976 to your computer and use it in GitHub Desktop.
// <TrendMetric Name="Max C.R.A.P Score" />
// 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)
(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 select CRAP)
.Max(CRAP => CRAP)
// To list methods with highest C.R.A.P scores, please refer to the default rule:
// Test and Code Coverage > C.R.A.P method code metric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment