Juan van den Anker
Juan van den Anker

Reputation: 91

Is it possible to customise rules for SonarCloud (not SonarQube)

I'm wondering if it is possible to add a custom rule or modify an existing rule - as mentioned in https://docs.sonarqube.org/display/DEV/Adding+Coding+Rules - to our SonarCloud instance.

We've setup SonarCloud on a couple of private projects and I want to - for instance - modify rule 'php:S1068 - Unused private fields should be removed". In the framework that we're using, a private field with the name of "$db" shouldn't be marked as 'unused', because that framework uses that variable through reflection.

Is it possible to add/modify such rules in SonarCloud?

Upvotes: 8

Views: 7377

Answers (4)

mchristos
mchristos

Reputation: 1899

This is the way (see this article):

  1. Find the existing quality profile being used, and click the three dots. Click copy (not extend!). This will create a new profile with editable rules, whereas extend doesn't allow to change any rules that exist in the parent profile.
  2. Now find the relevant rule, and edit it. For example, naming rules are often defined by a regular expression, which you're now able to edit (I asked chatGPT to come up with the new regular expression that encoded the rule I wanted).

Upvotes: 0

Ihor Baklykov
Ihor Baklykov

Reputation: 583

Yes, you actually can do that (partialy)!

Go to "Quality Profiles" of your organization, scroll down to the required-one, click 'triple dot' button at the right of profile and select in drop-down menu "Extend".

Step №1

Now you can change rules in your extended profile by opening it, selecting the rule you want to change and setting new walue of parameters you want (if possible).

Step №2

Now, it is possible to apply this profile as new default by selecting "Set as Default" from 'triple dot' menu of that profile:

Step №3


P.S.: The only trick here is you can only change parameters which are allowed to change

Upvotes: 0

David Střelák
David Střelák

Reputation: 169

AFAIK, you can partly modify (some) rules and you can disable them. I don't know how to add a new rule for a public project and we don't have any private one.

To disable/modify the rule:

  1. On your organization page, click on 'Quality Profiles'
  2. Select the language you want to alter, and using the 'gear' setting button, copy existing (default) profile and set the new one as default.
  3. You can now look for the rule you want to deactivate / modify in the 'Rules' tab

Bellow is a screen from the current version. In our project, we have deactivates several Python rules: enter image description here

Upvotes: 6

Rapster
Rapster

Reputation: 524

From SonarCloud Team

For custom rules, this is unfortunately not possible on SonarCloud - yet. (and I don't know when this is available - this is not in our short-term list)

Upvotes: 6

Related Questions