[drupal-devel] Checking coding style of contributed modules

Dries Buytaert dries at buytaert.net
Sat Feb 19 12:17:34 UTC 2005


Dries Buytaert wrote:
> Right on.  I'm a True Believer of automation and self-organization (if 
> possible).
> 
> If we'd have a 'code check' script -- even an extremely basic one -- I 
> could install it on drupal.org and run the script once or twice a day on 
> _each_ project in the contributions repository and link the report from 
> the project pages.
> 
> For example, on the project page of the image module 
> (http://drupal.org/project/image), there would be a link called 'View 
> code report' that points to the image module's code report, generated by 
> the script.
> 
> Of course, it is nothing like a real review and it might generate false 
> positives but it could easily catch dozens of issues and encourage good 
> coding style without manual intervention and within a few hours.  After 
> all, it is easy enough to detect tabs, '} else' or the absence of '{}' 
> in SQL queries.

I slapped together the foundations of a code checker scripts and 
installed it on drupal.org.  It took me 50 minutes to write and install. 
  It catched hundreds of (small) issues already, and will continue to 
catch many more in future to it most certainly pays off.

The code:
---------

The code lives at:
http://cvs.drupal.org/viewcvs/drupal/contributions/tricks/code-checker/

Currently, it checks for '} else', SQL queries that lack '{}' (prefix), 
and CamelCase function names.

Drupal.org:
-----------

At the bottom of the project pages, there is a new link called 'View 
code report'.  For example, take a look at http://drupal.org/project/image.
The image module's report looks like: 
http://drupal.org/files/projects/image.status.

Note that the report is generated against the HEAD version of each 
project and is updated a few times a day.

What is next?
-------------

Of course, we'll want to integrate it better and make it visually more 
appealing.  Also, we'll want to add many more tests.

I won't be able to work on it until after DrupalCon but you're all 
invited to add more tests.  I'd be happy to install newer versions on 
drupal.org as soon they hit CVS.

So, who's first to add a new test?

-- 
Dries Buytaert  ::  http://www.buytaert.net/



More information about the drupal-devel mailing list