codeclimate / codeclimate-phpcodesniffer

Code Climate Engine for PHP Code Sniffer
MIT License
28 stars 23 forks source link

Add Drupal code sniffs #31

Closed josephdpurcell closed 8 years ago

josephdpurcell commented 8 years ago

This addresses https://github.com/codeclimate/codeclimate-phpcodesniffer/issues/30.

While this solution varies from https://github.com/codeclimate/codeclimate-phpcodesniffer/pull/29, I suspect we would want to find a generic way to add code standards to Code Climate's PHPCS. Perhaps the best alternative is to request PHPCS itself to support these sniffs.

I have not tested to verify this PR works. Next step should be to verify it.

Side note: I generated the list of sniffs that Drupal has by running phpcs -e --standard="Drupal".

josephdpurcell commented 8 years ago

This PR is likely blocked by https://github.com/codeclimate/codeclimate-phpcodesniffer/pull/33.

josephdpurcell commented 8 years ago

It looks like this works. Next would be to try adding a codeclimate yml with:

engines:
  phpcodesniffer:
    enabled: true
    config:
      standard: "Drupal"

and see if it correctly runs. Any thoughts on how to test?

wfleming commented 8 years ago

Thanks for this @josephdpurcell! The approach here looks reasonable, and your example .codeclimate.yml looks correct. For testing it, I would suggest building this version of the image locally (docker build -t codeclimate/codeclimate-phpcodesniffer .), and then running codeclimate analyze on a local project with that configuration to confirm you're getting the expected results.

josephdpurcell commented 8 years ago

I was able to successfully test this. Here are the steps I took:

  1. Install code climate
  2. git clone --branch feature/drupal git@github.com:josephdpurcell/codeclimate-phpcodesniffer.git
  3. cd codeclimate-phpcodesniffer
  4. docker build -t codeclimate/codeclimate-phpcodesniffer .
  5. cd ..
  6. git clone git@github.com:josephdpurcell/drupal-relaxed.git
  7. cd drupal-relaxed
  8. Modify the .codeclimate.yml to have just "Drupal" for the standard
  9. codeclimate analyze

And here was the output:

root@wps:~/drupal-relaxed# codeclimate analyze
Starting analysis
Running phpcodesniffer: Done!

== relaxed.api.php (2 issues) ==
22: Missing parameter comment [phpcodesniffer]
24: Return comment must be on the next line [phpcodesniffer]
...
...
== src/Workspace/RelaxedWorkspaceNegotiator.php (5 issues) ==
1: Missing file doc comment [phpcodesniffer]
10: Missing class doc comment [phpcodesniffer]
12: Missing short description in doc comment [phpcodesniffer]
17: Missing short description in doc comment [phpcodesniffer]
18: Missing parameter comment [phpcodesniffer]

Analysis complete! Found 450 issues.

So, as far as I can tell this PR will meet the objective of supporting Drupal code sniffs with PHPCS.

josephdpurcell commented 8 years ago

Closing in favor of https://github.com/codeclimate/codeclimate-phpcodesniffer/pull/34.