Hi there,
I was looking for a solution to validate my code against the Drupal coding standards.
Finally I found this Eclipse project PHP Tool Integration (PTI)
It integrates different php tools into Eclipse - for my goal especially the PHP_CodeSniffer integration as an Eclipse validator is essential.
PHP_CodeSniffer provides a framework to test code against a coding standard.
There's also already a project drupal-sniff-standard that has started to port the PEAR coding standards to a Drupal specific version.
Unfortunately the project looks not really alive, and it covers not all the standards yet.
My own port based on the PEAR coding standards covers more cases but I'll try to contribute to the other project.
Now, what this post is really about :)
I would like to see a tools topic in the Coding Standards documentation.
A description of the coding standard is nice, but it's great to have tools.
I know there's already the coder module - but in my opinion it can't beat an IDE integration.
So let's bring all the information together, try to optimize the current solution and create a documentation page.
Current Tools / Projects:
- Plugin PHP Tool Integration (PTI) integrates PEAR into Eclipse
- PHP_CodeSniffer part of PTI - integrated as Eclipse validator
- drupal-sniff-standard initial port of the PEAR coding standard Sniffs
Projects to consider:
- Drupal plug-in for Eclipse
- Coder Module maybe there are some synergies
If someone wants to try my Drupal port of the PEAR sniffs for PHP_CodeSniffer please write me a mail.
There are still several issues (elseif, else, doxygen comments) but it's already a handy tool.
There's now a full project for this validator:
http://drupal.org/project/eclipse_code_validator
Cheers,
Peter
Comments
drupal sniff
Dear Peter,
I agree that checking coding standard with PHP CodeSniffer directly in IDE or as part of continuous integration setup is a much better solution than using the coder module. Unfortunately the drupal sniff on code.google.com seems to have disappeared, and also PHP CodeSniffer is changing the way it handles custom coding standards (it now uses a ruleset.xml). I would be interesting in using your sniff, or in documentation what exactly the differences with Pear coding standard are.
Just uploaded the latest
Just uploaded the latest version to:
http://www.das-peter.ch/files/Drupal_CondingStandardSniff.zip
http://www.das-peter.ch/files/Drupal_CondingStandardSniff.tar.gz
If the demand is growing I'll try to make a Drupal project out of this.
________________________________________
Cando Image GmbH
Else Züblinstrasse 115 :: CH-8404 Winterthur :: Switzerland
Thanks
Hi, Peter.
Thanks for this useful tool. I've downloaded your sniffer, but I've realized that it expects an indentation of 4 spaces, instead of 2, as it is said in documentation ( http://drupal.org/coding-standards#indenting )EDITED: Forget it, I was simply not running the command properly
Updated the
Updated the sniff:
http://www.das-peter.ch/files/Drupal_CondingStandardSniff.zip
http://www.das-peter.ch/files/Drupal_CondingStandardSniff.tar.gz
Attention:
Make sure the Standard Tab Widht configuration of PTI is set to 0. Otherwise you won't get notified about evil tabs in the code.
________________________________________
Cando Image GmbH
Else Züblinstrasse 115 :: CH-8404 Winterthur :: Switzerland
Setup a "Code Sniffer for Drupal" Project?
Hi Peter,
maybe we could add this package as d.o project so more people will recognize it and hopefully provide patches for it?
Cheers,
Karsten
--
Best regards
Karsten Frohwein
+1. This tool is helpful and
+1. This tool is helpful and deserves more attention. I use it everyday now.
Drupal_sniff_standard was my
Drupal_sniff_standard was my project, but I don't really have time to support it anymore (maybe sometimes in the future...:)). Thanks for your work on sniffer, I'm sure it will be very useful for developers here.
Great Tool Need Update
This is a great tools.
Until it does not work anymore.. :(
This is the error result:
ERROR: the "Drupal" coding standard is not installed. The installed coding standards are Zend, MySource, Squiz, PHPCS and PEAR
Is this related to file ruleset.xml that not available? This happened when i updated the pti..
Temporary Solution:
Use custom PEAR library and downgrade PHP_CodeSniffer to version 1.2.2.
A new URL
Would be great add some extra links at the beginning from this post and some comment that promote read the following comments.
Its a great project and I'll be active testing and looking new sniffers.
[at]Killua99 ~~
github repository and 1.3.x compatibility
I have updated this code for PHP_CodeSniffer 1.3.x compatibility and posted the code on a public github repository at https://github.com/pdrakeweb/PHP_CodeSniffer-Drupal-Standard for convenience. I was looking at posting it on Drupal.org as a project but did not see an appropriate project category for this.
End of line character is invalid
Thanks for the nice job, it works on my machine with Eclipse Helios, PTI tools, and CodeSniffer 1.3.0.
But I get this funny error: End of line character is invalid; expected "\n" but found "\n". I see from CodeSniffer documentation and source code they are using $eolChar = '\n' (note the single quotes). So I change it to single quotes and everything ok.
I've fixed this in the git
I've fixed this in the git repo. Thanks.
Many thanks for your interest
Many thanks for your interest in the idea - I just created a sandbox project for it: http://drupal.org/sandbox/daspeter/1232144
I hope this will help to push it further.
@pdrake: Thank you very much for your efforts. I've merged your code base before I did the initial sandbox check-in. And of course you've commit permission to the sandbox. :)
________________________________________
Cando Image GmbH
Else Züblinstrasse 115 :: CH-8404 Winterthur :: Switzerland
Finally - a full project
The sandbox is past - you can download the code now from here: http://drupal.org/project/eclipse_code_validator
Please use the project issue queue to report issues or request support - thanks :)
________________________________________
Cando Image GmbH
Else Züblinstrasse 115 :: CH-8404 Winterthur :: Switzerland
Emacs coding standard validation with coder + Code Sniffer
Another IDE solution is to use Code Sniffer with the Drupal coder module in Emacs via the flycheck module. It works very well by highlighting and giving annotated help messages for code not following the Drupal standard.
Here's how I set it up:
1) installed PHP_CodeSniffer 1.4.4 from Pear
2) download Drupal coder module and place in CodeSniffer "Standards" directory
3) configure CodeSniffer to use the Drupal standard by running this command:
% phpcs --config-set default_standard Drupal
4) Use emacs package manager to install 'flycheck' and 'php-mode'
5) Put this line in your emacs init file to load flycheck for php-mode:
(add-hook 'php-mode-hook 'flycheck-mode)
Restart emacs and you're done.
For more info see:
https://github.com/lunaryorn/flycheck
http://pear.php.net/package/PHP_CodeSniffer
http://drupal.org/project/coder