WordPress sonarqube analysis

php

(Denis Žoljom) #1

Hi!

I am wondering if it’s possible to add WordPress coding standards to sonarqube analysis?

There are rules created for PHP_CodeSniffer (https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/), and these sniffs are closely following the handbook with standards (https://make.wordpress.org/core/handbook/best-practices/coding-standards/).

If there is some tutorial on how to create the standards for sonarqube that would be great as well.


(Antoine Vigneau) #2

Hello @dingo-d,

Our SonarPHP analyzer is shipped with a built-in Drupal Quality Profile, but not for Wordpress. Note that it does not mean we implemented specific rules for Drupal, just that a set of them specifically applies for Drupal projects.

We do not plan on short term to implement specific rules for Wordpress, addressing each popular PHP frameworks coding standards (of frameworks in general) would be a lot of work and a lot of maintenance.
However either existing PHP rules are good enough and it’s just a matter of creating a Quality Profile which targets Wordpress projects, or it needs some rules implementation. From our Extension guide you can figure out how to develop a plugin and how to implement rules.

I hope this helps.

Antoine


(Denis Žoljom) #3

Some PHP rules are good enough, but some (like PSR2 standard for class names) are not. I tried extending some, but in some cases I could do it, and in other I couldn’t which I found odd.

Also it would make more sense to have WordPress standards since WordPress powers over 30% of top 10 million sites on the web :slight_smile:

I’ll take a look at the extension guide, maybe I can modify it more easily :slight_smile:

Thanks!


(Alexandre Gigleux) #4

Hello Denis,

You can help us to provide a default Quality Profile covering WordPress’s standards even without thinking about writing custom rules.

What you need to do is to study the 164 rules available in SonarPHP and tell us:

  • if the rule is relevant for WordPress
  • if this is the case, which part of WordPress standards the rule is covering
  • if the rule is no useable out of box for WordPress, tell us why
  • if you believe some rules are missing to fully cover WordPress’s standards, tell it and we will do our best to close the gap.

The best way to share this information with us would be a Google Sheet but whatever format that suits you will work for us. The identifier of a rule at SonarSource is looking like that: RSPEC-4426

Is that something you can lead?

Thanks
Alex


(Denis Žoljom) #5

Hi Alexandre,

I will try to look it up in the following weeks and get back to you with the findings. I’ll create a Google sheet and share it here.

Thank you!