简体   繁体   English

如何在 IntelliJ IDEA 中自定义 SonarLint 规则?

[英]How do you customize SonarLint rules in IntelliJ IDEA?

是否可以让 IntelliJ IDEA 的 SonarLint 仅强制执行我在 Sonar 服务器上启用的规则?

SonarLint 1.0 for Eclipse and IntelliJ do not allow to edit the quality profile (or set of rules) to be used for the analysis. Eclipse 和 IntelliJ 的 SonarLint 1.0 不允许编辑用于分析的质量配置文件(或规则集)。 Moreover, SonarLint 1.x works completely independently of a SonarQube server (having a SonarQube server is not a requirement), and therefore does not have the ability to reuse a quality profile defined there.此外,SonarLint 1.x 完全独立于 SonarQube 服务器工作(不需要 SonarQube 服务器),因此无法重用那里定义的质量配置文件。

SonarLint 2.0 will have an optional mode that connects to a SonarQube server, and will offer this feature - but this isn't available yet. SonarLint 2.0 将具有连接到 SonarQube 服务器的可选模式,并将提供此功能 - 但目前尚不可用。

As it is now possible with the current release of SonarLint (I'm using version 3.0.0.2041 ), people might be interested in the solution.由于现在可以使用当前版本的 SonarLint(我使用的是3.0.0.2041版本),人们可能会对解决方案感兴趣。

  • File -> Settings -> Other Settings -> SonarLint General Settings
  • Click on the green + in "SonarQube servers" :单击“SonarQube 服务器”中的绿色 +:
    • Enter a name (ex : SonarQube / localhost)输入名称(例如:SonarQube / localhost)
    • Select SonarQube and enter URL like http://localhost:9000选择 SonarQube 并输入 URL,例如http://localhost:9000
    • Authentication : select your user token or your login/pwd身份验证:选择您的用户令牌或您的登录名/密码
    • Click on Finish点击完成
    • Click on "Update binding" to synchronize with the SonarQube server单击“更新绑定”以与 SonarQube 服务器同步
  • Go to SonarLint Project Settings and bind your project to the SonarQube project转到SonarLint Project Settings并将您的项目绑定到 SonarQube 项目

Thus, when you open your files, SonarLint will automatically retrieve the SonarQube server's issues.因此,当您打开文件时,SonarLint 将自动检索 SonarQube 服务器的问题。

For Android Studio Chipmunk , Bumblebee 2022 and Arctic Fox 2021适用于 Android Studio花栗鼠大黄蜂2022 和北极狐2021

File >> Settings >> Tools >> SonarLint >> Rules文件 >> 设置 >> 工具 >> SonarLint >> 规则

Then select your project language and any rule then check/uncheck it, you can edit its options (if exist)然后选择您的项目语言和任何规则,然后选中/取消选中它,您可以编辑其选项(如果存在)

声纳

最新版本 IntelliJ (2020.2) 中 SonarLint 的这些连接设置位于“工具”>“SonarLint”>“项目设置”的“首选项”窗口中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM