SonarQube/SonarLint/Visual Studio:在解决方案中的所有项目中使用一个规则集 [英] SonarQube/SonarLint/Visual Studio: Use one ruleset fo all projects in solution

查看:88
本文介绍了SonarQube/SonarLint/Visual Studio:在解决方案中的所有项目中使用一个规则集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在评估.NET应用程序对SonarQube/SonarLint的使用.我们对到目前为止所看到的一切感到非常满意(顺便说一句,对于将SonarQube推广到现在已经感到很荣幸-我几年前就在我的博士项目中使用了它,自那时以来,它有了很大的进步!)./p>

但是,有一件事有些令人惊讶:当我将SonarLint实例连接到我们的SonarQube服务器(工作正常)并开始同步绑定的项目时,SonarLint开始下载nuget包(这是预料之中的),然后为我们解决方案的每个项目创建了一个或什至两个.ruleset文件(除了文件 SonarQube/< solution name> CSharp.ruleset ,我认为这是解决方案范围的规则集).

我期望并希望仅对整个解决方案有效的单个规则集(以及可能在有意义的项目(例如测试项目)中覆盖该规则集的选项).

这种行为是否完全可能,即我是否错过了任何事情?到目前为止,我唯一确定的领域是缺少SonarLint的文档.

解决方案

创建这些附加规则集文件是有原因的.嗯,实际上有多个:

  • 这是允许您设置所有项目必须遵守的基准,但是为具有特定代码类型的项目启用其他规则.您可能启用了一些特定于Sharepoint项目的MSOCAF规则,这对您的Unittest或Windows Service项目没有意义

  • 例如,修复项目中的技术债务时,可以为整个解决方案设置基准,并慢慢收紧各个项目的规则集,以便您可以将清理工作重点放在特定项目上.不必在解决方案中的所有项目中同时清除一条特定的规则或一组规则.

每次与SonarQube同步时,一个项目规则集文件将被覆盖.剩下的一个将保留.允许您保存自定义设置,并且仍然可以安全地将更改同步到SonarQube基准.

如果我没记错的话,解决方案规则集和存储自定义内容的规则集一样都包含在项目规则集中.目前,我手头没有SonarQube服务器来验证哪个规则集文件服务器的用途,但这是其背后的原因.

We are currently in the process of evaluating the use of SonarQube/SonarLint for our .NET applications. We are pretty happy with what we've seen so far (and, btw, kudos for bringing SonarQube this far - I've used it a couple of years ago for my PhD project, and it has improved greatly since then!).

However, one thing was a bit surprising: When I connected my SonarLint instance to our SonarQube server (which worked just fine) and started syncing the bound project, SonarLint started to download nuget packages (which was kind of expected) and then created one or even two .ruleset files for each project of our solution (in addition to a file SonarQube/<solution name>CSharp.ruleset which I assume is the solution-wide ruleset).

What I expected and would prefer is only the single ruleset valid for the complete solution (and possibly the option to override that ruleset for projects where this makes sense (e.g., test projects)).

Is this behavior possible at all, i.e., did I miss anything? Documentation is the only area I've identified so far where SonarLint is lacking.

解决方案

There is a reason why these additional ruleset files are created. Well actually there are multiple:

  • That is to allow you to set a baseline to which all projects must adhere, but the enable additional rules for projects with specific types of code. You may have a couple MSOCAF rules enabled that are specific to Sharepoint projects, which don't make sense for your Unittest or Windows Service projects

  • Say, when you are fixing technical debt in your projects, you can set a baseline for the whole solution and that slowly tighten the rulesets of the individual projects so that you can focus your cleanup effort on a specific project. Instead of having to clear up a specific rule or set of rules across all projects in the solution at the same time.

One of the project ruleset files will be overwritten each time you sync with SonarQube. The other one will remain as you've left it. Allowing you to save your customizations and still allowing you to safely sync changes to the SonarQube baseline.

If I'm remembering this correctly, the Solution ruleset is included in the project ruleset as is the ruleset in which you store your customizations. Currently I don't have a SonarQube server at hand to verify which ruleset file server which purpose, but this is the reasoning behind it.

这篇关于SonarQube/SonarLint/Visual Studio:在解决方案中的所有项目中使用一个规则集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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