CA1502的自定义阈值 [英] Custom threshold for CA1502

查看:117
本文介绍了CA1502的自定义阈值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以更改CodeAnalysis规则的阈值?

Is there any way to change the thresholds for CodeAnalysis rules?

特别是,当方法的代码复杂度超过10%时,我们希望构建失败。 20.不幸的是,规则 CA1502 的阈值为25:

In particular, we would like our Build to fail when a method has a code complexity of more than 20. Unfortunately, rule CA1502 has a threshold of 25:


当圈复杂度大于25时,该规则将报告违规。

The rule reports a violation when the cyclomatic complexity is more than 25.

我们可以以某种方式更改它吗?

Can we somehow change this?

推荐答案

是的,这是可能的。不幸的是,为可配置规则提供自定义规则设置的唯一方法是通过 .fxcop 项目文件,由于文件顺序不完全与VStudio无缝集成。规则集和项目文件将被处理。基本上,如果要同时使用规则集文件和项目文件,则需要在禁用规则的情况下在项目文件中包括所有规则库文件的列表。然后,您将能够通过规则集控制是启用还是禁用规则。设置完成后,您可以使用 Settings 部分调整圈复杂度规则的设置,如下所示(假设您可以将所有阈值设置为20,就可以了) ):

Yes, this is possible. Unfortunately, the only way to provide custom rule settings for a configurable rule is via a .fxcop project file, which doesn't integrate terribly seamlessly with VStudio due to the order in which the rule set and project files are processed. Basically, if you want to use both a ruleset file and the project file, you will need to include a list of all rule library files in your project file with the rules disabled. You will then be able to control whether the rules are enabled or disabled via the ruleset. Once that's all set up, you can tweak the settings for the cyclomatic complexity rule using a Settings section like the following (assuming you're OK with all the thresholds being set to 20):

<Settings>
    <Rule TypeName="AvoidExcessiveComplexity">
        <Entry Name="Warning Threshold">20</Entry>
        <Entry Name="Information Threshold">20</Entry>
        <Entry Name="Critical Warning Threshold">20</Entry>
        <Entry Name="Critical Error Threshold">20</Entry>
        <Entry Name="Error Threshold">20</Entry>
        <Entry Name="Recommended Threshold">20</Entry>
    </Rule>
</Settings>

这篇关于CA1502的自定义阈值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆