Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是CRAP指标的粉丝,并使用它来监控我的C#和Java项目的代码质量。
我想为我不断增长的 Javascript 代码库做同样的事情。
是否有现有的流程可以轻松地将其集成到我的 Javascript 构建流程中?
CRAP 公式为:
var complexity = ...; //cyclomatic complexity of a method var coverage = ...; //test code coverage for the method var crap = Math.pow(complexity,2) * Math.pow(1 – coverage/100,3) + complexity;
因此,您需要计算圈复杂度并计算测试代码覆盖率(或此处)。
jshint 计算圈复杂度,参见http://www.jshint.com/docs/参数 maxcomplexity。我不知道如何检索结果,但您可能会查看 jshint 源。希望有帮助