Skip to content

Commit

Permalink
Build/PHPCS: rename ruleset
Browse files Browse the repository at this point in the history
If the PHPCS ruleset is named `.phpcs.xml`, `phpcs.xml`, `.phpcs.xml.dist` or `phpcs.xml.dist`, it will automatically be picked up by PHPCS and you don't need to pass the ruleset name anymore.

Additionally, using a `.dist` file for a repo ruleset allows for individual developers to overrule the ruleset with a custom version (without the `.dist` file extension).
This makes testing of new additions/changes to the ruleset easier.
The master ruleset can be imported into a custom ruleset by using `<rule ref="./.phpcs.xml.dist"/>`.

Since PHPCS 3.1.0, it is also possible to use dot-prefixed files for the PHPCS config, allowing these files to be sorted with other configuration related files.

The loading order of the ruleset files in PHPCS, as of version 3.1.1., is:
1. `.phpcs.xml`
2. `phpcs.xml`
3. `.phpcs.xml.dist`
4. `phpcs.xml.dist`

References:
* https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file
* https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.1.0
* https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.1.1 (change in the file loading order)
  • Loading branch information
jrfnl committed Sep 5, 2018
1 parent 27c384e commit c9356ed
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -35,3 +35,8 @@ svn
# PHPUNIT #
###########
build/logs

# Local Dev files #
###################
.phpcs.xml
phpcs.xml
File renamed without changes.
9 changes: 4 additions & 5 deletions .travis.yml
Expand Up @@ -39,12 +39,11 @@ script:
# -s flag: Show sniff codes in all reports.
# -v flag: Print verbose output.
# -n flag: Do not print warnings. (shortcut for --warning-severity=0)
# --standard: Use WordPress as the standard.
# --extensions: Only sniff PHP files.
- vendor/bin/phpcs -p -s -v -n ./*.php --standard=./phpcs.ruleset.xml --extensions=php
- vendor/bin/phpcs -p -s -v -n ./**/*.php --standard=./phpcs.ruleset.xml --extensions=php
- vendor/bin/phpcs -p -s -v -n ./**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php
- vendor/bin/phpcs -p -s -v -n ./**/**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php
- vendor/bin/phpcs -p -s -v -n ./*.php --extensions=php
- vendor/bin/phpcs -p -s -v -n ./**/*.php --extensions=php
- vendor/bin/phpcs -p -s -v -n ./**/**/*.php --extensions=php
- vendor/bin/phpcs -p -s -v -n ./**/**/**/*.php --extensions=php

after_script:
- php vendor/bin/coveralls
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Expand Up @@ -41,6 +41,7 @@ rm .jscsrc
rm .jshintignore
rm .jshintrc
rm .jhintrc
rm .phpcs.xml.dist
rm .simplecov
rm .travis.yml
rm CODE_OF_CONDUCT.md
Expand All @@ -49,7 +50,6 @@ rm -rf vendor/
rm example.php
rm Gruntfile.js
rm package.json
rm phpcs.ruleset.xml
rm phpunit.xml
rm phpunit.xml.dist
rm README.md
Expand Down

0 comments on commit c9356ed

Please sign in to comment.