在 Detekt 中配置规则

发布于 2025-01-10 14:15:29 字数 180 浏览 0 评论 0原文

我正在将 Detekt 添加到新项目中。 但是,我发现有些规则过于严格。

如何为一些规则实施我自己的阈值?

我不想使用 基线文件,因为这是新代码,我们不想考虑一些代码味道。

I am adding Detekt to a new project.
But, I find that some rules are too strict.

How can I implement my own thresholds for a few rules?

I don't want to use Baseline files, because this is new code and we don't want to consider some things code smells.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我恋#小黄人 2025-01-17 14:15:29

可以通过配置文件配置 Detekt。

根据 Detekt 文档,我强调:

detekt 允许轻松选择您想要的规则并按照您喜欢的方式配置它们。例如,如果您希望在 Kotlin 文件中允许最多 20 个函数而不是默认阈值,请编写:

复杂性:
功能太多:
  文件阈值:20

您需要创建一个配置 code> 文件夹位于项目根目录中,并将 detekt.yaml 添加到其中。此配置将包含您想要覆盖默认值的所有规则,或所有规则(将默认值建立为正确的值)。

更多信息,查看官方配置文档

It's possible to configure Detekt via configuration files.

As per Detekt's documentation, with my emphasis:

detekt allows easily to just pick the rules you want and configure them the way you like. For example if you want to allow up to 20 functions inside a Kotlin file instead of the default threshold, write:

complexity:
TooManyFunctions:
  thresholdInFiles: 20

You'll want to create a config folder in the root of your project, and add detekt.yaml to it. This config will contain all the rules that you want to override the default, or all the rules (establishing the defaults as the correct value).

For more information, check the official documentation on configuration

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文