Configure custom rule for SoftwareQuality = Reliability

I want to write a custom SonarQube rule for Java. The example on how to do that mentions a json file to configure that rule. Here you see a json code from that tutorial:

{
  "title": "Return type and parameter of a method should not be the same",
  "type": "Bug",
  "status": "ready",
  "tags": [
    "bugs",
    "gandalf",
    "magic"
  ],
  "defaultSeverity": "Critical"
}

When I look at the UI of the SonarQube server, I also see something which is called “SoftwareQuality” as a further attribute of my rule. Since I did not configure it in the json file, it is set to the default “Maintainability”. But I want it to have the value “Reliability”. How must I configure the json file to achieve that?

Hey there.

Point taken that we ought to update the custom rules tutorial to handle these new attributes. I anticipate we’ll do that before (but probably not long before) the next LTA release.

In the meantime, you can check the open-source sonar-java repo to see how these rules are configured with software qualities and impacts.

I suggest that the tutorial not only will be updated, but additionally explains the whole structure of that json file in more detail:

  • which UI elements are configured by the fields?
  • which values are possible for the enums?

Here is my complete json file:

{
  "title": "a getter access to an autowired state class must be null-checked",
  "type": "CODE_SMELL",
  "code": {
    "impacts": {
      "RELIABILITY": "HIGH"
    },
    "attribute": "COMPLETE"
  },
  "status": "ready",
  "tags": [
    "convention",
    "cucumber",
    "confusing"
  ],
  "defaultSeverity": "Major"
}

I stopped my local SonarQube server. built the jar, deployed it to the server, and started the server again. Still, the UI shows:

I expected it would show “Reliability” instead of “Maintainability”

Hi @Colin ,
We have a similar request, just that we use custom rules with the xml format like:

  <rule>
      <key>AvoidUnconditionalBuiltLogStrings</key>
      <name>Log String is built irrespective of log level.</name>
      <internalKey>com/jpinpoint/pmd/rules/jpinpoint-rules.xml/AvoidUnconditionalBuiltLogStrings</internalKey>
      <severity>CRITICAL</severity>
      <description>...</description>
      <tag>cpu</tag>
      <tag>jpinpoint-rule</tag>
      <tag>performance</tag>
      <tag>sustainability-low</tag>
   </rule>

How can we make this fit well into the new Clean Code / Software Quality structure? What are the new rule attributes to use?