I'm a codesniffer newbie, so this isn't intended as a criticism -- more like, am I missing something obvious?

I ran phpcs with standard=Drupal on a Drupal 7 custom theme, and received a tonne of errors. Filtered out the CSS and still saw a tonne. I wondered to myself, is the Drupal standard overzealous? So I ran it on what, in D7, is virtually but not core -- the views module -- and I saw over 10,000 errors.

So my first question is, am I doing something wrong here? Or is it that something even so mainstream as Views does not adhere to Drupal coding standards?

And my second question is, is there no granularity in errors other than error & warning? I see that phpcs supports severity levels, but I don't see severity implemented in the Drupal rulesets. Is this planned functionality? If not, is there a reason why not?

Again I'm just trying to get a basic sense of what's going on here. Perhaps in D8 things are inherently better, but as I'm using it in D7, running codesniffer with the Drupal standard is listing so many errors that it's hard to use it practically. Maybe I should be using the 7.x release of Coder even though the documentation suggests to use the 8.x release on D7 builds. I feel like I must be missing something, but perhaps I am not?

Thanks!

Comments

Shiraz Dindar created an issue. See original summary.

pfrenssen’s picture

I don't think the Drupal coding standard is particularly overzealous, it is quite comprehensive but not overly complex. If anything there are still a lot of missing parts in it, people are often suggesting additions. It is based for the most part on the PEAR coding standard, but extended for modern practices and newer PHP functionality that was added after the PEAR standard was written.

Indeed Views for Drupal 7 has a ton of coding standards violations, that is not a good example to follow if you are looking to write coding standards compliant code. It is not because a module is popular that it means that it will be more coding standards compliant. Even Drupal core has a lot of coding standards violations, but we are actively working on getting Drupal 8 core as standards compliant as possible: #2571965: [meta] Fix PHP coding standards in core.

If you have a lot of coding standards violations, the best first step to take is to use phpcbf which is able to fix a large number of coding standards automatically.

We do not support granularity in severity because the Drupal coding standards are for the most part very clear and non-ambiguous. Code is either compliant or it is not. We do not have the concept of a 'minor violation'.

Don't use the 7.x branches. These are outdated and no longer maintained, except for security issues. This is no longer a Drupal module, so these versions are no longer tied to major Drupal releases. 8.x is a complete rewrite which is based on PHP_CodeSniffer, the industry standard PHP coding style checker. It is compatible with all supported versions of Drupal.

klausi’s picture

Status: Active » Fixed

I agree with everything pfrenssen said.

When you enable Coder the first time on your project then you can disable certain rules at firstwith a phpcs.xml.dist config file and then fix them gradually. An example can be seen at https://github.com/pfrenssen/coder#store-settings-in-a-phpcsxmldist-file

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.