Closed (fixed)
Project:
Drupal Code Sniffer
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
25 Apr 2012 at 20:05 UTC
Updated:
4 Jan 2014 at 02:05 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
patcon commentedFluxSauce and I are playing around with using RobLoach's Composer module to install the PHP_CodeSniffer dep and run it directly using Composer's autoloader functionality.
Not much there yet, as I'm just figuring out Composer as well as Drush's API, but it's here for anyone interested:
https://github.com/myplanetdigital/drupalcs
The idea would be to have
drush dl drupalcsdownload the "module" (hopefully right to~/.drush/drupalcs, as Composer module does). The rest of the install would involve runningdrush dl composerto download that module, and then runningdrush code-sniff. The first invocation would ideally run composer (which downloads the composer.phar file to~/.drush/cachefor all subsequent use), and then rundrush composer installin~/.drush/drupalcs. This resolves and fetches all the dependencies based on thecomposer.jsonfile that I've got in my module repo, and drops then into a~/.drush/drupalcs/vendor/dir and builds an autoloader so that we can work with it in ourdrupalcs.drush.inccommand file. Phewf!I might have some of this stuff wrong, but I'll try to get Rob in here for feedback :)
Comment #2
das-peter commentedThis sounds indeed nice. Everything that makes using drupalcs more convenient is nice, it hopefully improves the usage of it and thus spreads the coding standard ;)
Unfortunately I'm not familiar with the composer module and can't really help.
Comment #3
patcon commentedThanks @das-peter! I actually just came across your issue in the phpcs github repo, and the fact that it wasn't yet in a release was what got me going down this road into learning a bit about composer. Composer can use the repo at a given commit, rather than using only official releases :)
In case anyone's wondering, composer is an outside project that aims to be like the Bundler package manager in the Ruby world, used for handling rubygems management. PHP hasn't had a good, decentralized package manager like that. It's pretty much like drush_make for php libraries :)
Comment #4
klausiThinking about this: as you can run drupalcs from the command line anyway, what's the point of having a drush integration?
Comment #5
fluxsauce commentedThanks for the introduction, patcon. I focused on the drush integration first; I haven't written any code for composer yet.
Speaking to the improved installation; this is on two levels.
First, the symbolic link on installation is a workaround for a known limitation in PHP_CodeSniffer 1.3.3 and all previous versions; you can't specify the path of the Standard and have custom Sniffs work too. This is now fixed on the github repository, but not in PEAR. Therefore, the drush command I wrote checks to see if the Standard is installed (if you used the symbolic link), or if it isn't, if you have a version above 1.3.3 (does not exist yet) or a version from github. Depending on how it passes, drush will intelligently build the command.
The second level is integration with composer, which I have not written at this time, that will make it extremely easy to get drupalcs/PHP_CodeSniffer up and running, which will increase usability and improve user experience, which will in turn should lead to a greater adoption rate.
In short, this drush command will make it easier to use the Drupal PHP_CodeSniffer standards.
I have attached a working patch, which includes the module definition (required for drush integration), the drush command, and an amendment to the README.
Feedback is welcome.
Comment #6
patcon commentedLooks awesome Jon! Full disclosure on the double-team: I work with Jon :)
I'm a little biased, but I'm in agreement. Coder, while a cherished baby of the Drupal community, separates us from the larger PHP community's tool. Coder is dead simple to get working with the tool we all use, so its use makes sense.
As painless as possible that we can make the transition, the better, in my opinions -- similar flags, similar defaults, similar output, similar install method, etc.
Right now, coder install is as easy as:
phpcs is a little more involving. Really exciting for using composer to avoid system-wide pear access :)
Comment #7
klausiWhy does this have to be a module? Does that mean that I have to download and install drupalcs for each separate drupal installation I have? Is there no way to install drupal independent drush commands?
Comment #8
patcon commentedI believe it could be just an extra file,
drupalcs.drush.inc. It looks like fluxsauce has chosen to use a .module file, but I believe we could just as easily cut that down to one file. There might be another reason to do so:If I understand correctly, drush5.1 downloads modules without .info and .module files straight to ~/.drush/[modulename] by default when using
drush dl. (See composer module repo.) Not sure how it would treat the drupalcs project that also has a "Drupal/" directory (and "composer.json"), but I'll check it out. We might be able to convince the drush maintainers to change the behavior if it won't download to ~/.drush already.So as I'm imagining it,
drush dl drupalcswould ideally download the project to~/.drush/drupalcs, dropping the Drupal standard, the composer.json and the drupalcs.drush.inc into place. We could add the logic on first execution ofdrush drupalcsto:1) check for the availability of the phpcs command. If available use it, and if not:
2) check for the drush composer command (which would be in
~/.drush/composer) and if available, use that to download the components in composer.json to ~/.drush/drupalcs/vendor. If not available, then3) throw an error telling the use to either install codesniffer via pear or install composer using "drush dl composer"
Would that work for you guys?
Comment #9
patcon commentedYeah, here's the bit where drush checks:
http://drupalcode.org/project/drush.git/blob/refs/tags/7.x-5.1:/commands...
Seems if there are *.drush.inc files but not *.module files, it downloads to ~/.drush/
Comment #10
fluxsauce commentedThanks for the feedback, klausi and patcon.
I'll take a different approach to make it a more proper drush extension, rather than using the module approach (it made sense at one point, but in the context of multiple site installations and command availability...).
I'll look into the composer integration; patcon can you submit a PHP_CodeSniffer package to http://packagist.org/ ?
Comment #11
patcon commentedCoolio. Although we can add a package to packagist, that will just be something we need to keep up to date -- plus, the one we want isn't even a full release, so we'd be putting up a package for a random pre-release commit hash.
We can just use the git repo directly, and it will be easy to update the reference from a commit to a tag when a new version is released and tagged:
https://github.com/myplanetdigital/drupalcs/blob/drush-command-composer/...
Hopefully the maintainer will cave and add a composer.json file soon enough :)
Comment #12
fluxsauce commentedHere's the updated version. Major differences:
I'm considering composer integration as a separate feature for the time being. Let's focus on the initial integration first.
Feedback on the drush integration?
Comment #13
Darko commentedInstalled and tested. It works as described.
Comment #14
klausiMake sure that the lines wrap at 80 characters in README.txt
do not hardcode the current release in the README, so that we don't have to update it all the time.
While this is nice to check PHP files, drupalcs is also capable of checking CSS, JS, TXT and info files. Maybe there should be an option to run it on those, too. Maybe a "--mode" option with two possible values "default" and "extended", which is ignored if --extensions is present.
Command drupalcs needs a higher bootstrap level to run - you will need invoke drush from a more functional Drupal environment to run this command.Why? drupalcs does not need Drupal?
Comment #15
klausiThere is now a dedicated installation doc page: http://drupal.org/node/1419988
So I think we should keep the additions to README.txt short, just mention that drush integration is available and link to the install page where we can list the instructions.
Comment #16
fluxsauce commentedJust pinging back, going to work on this Friday. Thanks for the feedback & suggestions, @klausi
Comment #17
fluxsauce commentedMajor changes:
Documentation for installation page:
Installation: Drush
While drupalcs can be used as a standalone set of rules for PHP_CodeSniffer, drush command support is included to facilitate ease of use, installation, and leveraging of drush features such as site aliasing.
Extract the contents of the drupalcs project into one of the locations specified in the drush README.txt COMMANDS section, including:
~/.drush/drupalcs(you may have to create the .drush folder yourself)--includeoption (seedrush topic docs-configuration)/path/to/drush/commands(not recommended)Example:
For more information about drush, see http://drupal.org/project/drush
Comment #18
klausiVery good, committed! http://drupalcode.org/project/drupalcs.git/commit/8878df3
Would you be so kind to copy the text from above to the documentation page?
Comment #19
ericduran commentedIt should be noted, it we remove the .info file Drush will automatically download this to it's .drush directory.
Comment #20
patcon commented@fluxsauce So awesome Jon! Nice man. Just... nice. :)
Really glad that this got committed. Thanks klausi!
Comment #21
fluxsauce commentedExcellent, thanks all for your feedback and reviews! I've got a big grin on my face IRL.
Instructions updated - http://drupal.org/node/1419988
Comment #22
patcon commentedtagging