diff --git a/CHANGELOG.md b/CHANGELOG.md index d77b702..b83459b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.5.0] - 2017-05-28 + +* Allow any version of [wp-coding-standards/wpcs](https://github.com/wp-coding-standards/wpcs), avoiding conflicts with packages that use older versions ([#37]). +* Clarify placement of scripts within `composer.json` ([#41]). +* Exclude `phpcs.xml` from being checked by PHP_CodeSniffer ([#27]). + + ## [0.4.2] - 2017-01-04 * Don't lock [wp-coding-standards/wpcs](https://github.com/wp-coding-standards/wpcs) to a single version. @@ -42,7 +49,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). [Unreleased]: https://github.com/stevegrunwell/wp-enforcer/compare/develop...master -[0.4.2]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.4.1...master +[0.4.2]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.5.0...master +[0.4.2]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.4.1...v0.4.2 [0.4.1]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.4.0...v0.4.1 [0.4.0]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.3.0...v0.4.0 [0.3.0]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.2.0...v0.3.0 @@ -56,4 +64,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). [#11]: https://github.com/stevegrunwell/wp-enforcer/issues/11 [#12]: https://github.com/stevegrunwell/wp-enforcer/issues/12 [#19]: https://github.com/stevegrunwell/wp-enforcer/issues/19 +[#27]: https://github.com/stevegrunwell/wp-enforcer/issues/27 [#29]: https://github.com/stevegrunwell/wp-enforcer/issues/29 +[#37]: https://github.com/stevegrunwell/wp-enforcer/issues/37 +[#41]: https://github.com/stevegrunwell/wp-enforcer/issues/41 diff --git a/README.md b/README.md index ddfc689..fa7f0a0 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,10 @@ WP Enforcer uses [Git Hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git- The easiest way to install WP Enforcer is via Composer: ```bash -$ composer require stevegrunwell/wp-enforcer +$ composer require --dev stevegrunwell/wp-enforcer ``` -This will add WP Enforcer to your composer.json file and install the WP Enforcer package. +This will add WP Enforcer to your `composer.json` file and install the WP Enforcer package. Next, you'll need to run the WP Enforcer installation script to copy the Git hooks into your local repository: @@ -31,17 +31,22 @@ Next, you'll need to run the WP Enforcer installation script to copy the Git hoo $ ./vendor/bin/wp-enforcer ``` -If you'd like to require WP Enforcer for all developers on your project, you can add the following commands to your composer.json file to have WP Enforcer automatically set up Git hooks on `composer install` and `composer update`: +If you'd like to require WP Enforcer for all developers on your project, you can add the following scripts to your `composer.json` file to have WP Enforcer automatically set up Git hooks on `composer install` and `composer update` (for more information, please see [Composer Scripts](https://getcomposer.org/doc/articles/scripts.md)): ```json -"post-install-cmd": [ - "wp-enforcer" -], -"post-update-cmd": [ - "wp-enforcer" -] +{ + "scripts": { + "post-install-cmd": [ + "wp-enforcer" + ], + "post-update-cmd": [ + "wp-enforcer" + ] + } +} ``` + ### Writing for WordPress.com VIP WP Enforcer includes built-in support for the [WordPress.com VIP coding standards](https://vip.wordpress.com/documentation/developers-guide-to-wordpress-com-vip/), simply add `--vip` when you run the `wp-enforcer` command (including in the post-install and post-update commands). @@ -53,6 +58,11 @@ If you need to switch an existing project to the WordPress.com VIP coding standa ``` +### Using a custom ruleset + +If you want to use a custom XML configuration file with PHP_CodeSniffer, add `--ruleset=[FILE]` when you run the `wp-enforcer` command. + + ## Configuration PHP_CodeSniffer allows you to [define a custom, default ruleset by creating a phpcs.xml file in your project root](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file). WP Enforcer will automatically create a phpcs.xml file in your project if one doesn't already exist, but you can edit this to exclude certain files/directories, ignore specific rules, or load additional rulesets. @@ -77,6 +87,12 @@ This leaves you with a copy of PHP_CodeSniffer, a phpcs.xml file, and the WordPr $ ./vendor/bin/phpcs ``` +You may also run PHP Code Beautifier and Fixer, which can fix many common indentation and formatting issues automatically, using the PHP Code Beautifier and Fixer (phpcbf) command: + +```bash +$ ./vendor/bin/phpcbf +``` + Once CodeSniffer comes back clean, re-run the WP Enforcer installation script to restore the Git hook, forcing all future commits to be clean: ```bash @@ -84,3 +100,10 @@ $ ./vendor/bin/wp-enforcer ``` Finally, merge your clean-up branch into master, kicking your project's coding standards compliance into high gear. + + +## Bypassing WP Enforcer + +If it's necessary to bypass WP Enforcer's sniffs for a particular commit (for instance, you're committing small chunks of a file that has older, non-compliant code) you may do so by using [`git commit --no-verify`](https://git-scm.com/docs/git-commit#git-commit--n). + +It's recommended that WP Enforcer is only bypassed when making changes in legacy files that simply haven't been cleaned up yet. For more on integrating WP Enforcer with legacy projects, please see [Adding to an Existing Project](#adding-to-an-existing-project). diff --git a/bin/wp-enforcer b/bin/wp-enforcer index 032b80f..02b964a 100755 --- a/bin/wp-enforcer +++ b/bin/wp-enforcer @@ -2,18 +2,27 @@ # # Copy files for WP Enforcer into the project directory. -readonly VERSION="0.4.0" +readonly VERSION="0.5.0" readonly BIN="$(cd "$(dirname "$0")" && pwd -P)" readonly DIR="$BIN/$(dirname "$(readlink "$0")")" readonly PROJECT="$(pwd)" vip=false ruleset=false +# Trigger an error and exit, but also tell users how they can re-run the script. +error() { + echo + echo "Error: $1" >&2 + echo "You may re-run this setup at any time by running $DIR/wp-enforcer" + echo + exit 1; +} + # Define command-line options here. # Follow -o with a comma-separated list of single-character option names. # Follow -l with a comma-separated list of long option names. # Options may be followed by one colon to indicate they have a required argument -if ! options=$(getopt -o h,v,c -l help,version,vip,customruleset -- "$@") +if ! options=$(getopt -o h,v -l help,version,vip,ruleset: -- "$@") then # something went wrong, getopt will put out an error message for us exit 1 @@ -29,30 +38,33 @@ do echo " wp-enforcer [options]" echo "" echo "OPTIONS:" - echo " --help, -h Show this help and usage" - echo " --version, -v Show the current version of WP Enforcer" - echo " --vip Configure the project to use the WordPress.com VIP coding standards" - echo " --customruleset, -c Configure the project to use a custom PHPCS ruleset file" + echo " --help, -h Show this help and usage" + echo " --version, -v Show the current version of WP Enforcer" + echo " --vip Configure the project to use the WordPress.com VIP coding standards" + echo " --ruleset=FILE Configure the project to use a custom PHPCS ruleset file" echo "" exit;; -v|--version) echo "$VERSION" exit;; --vip) - vip=true; - break;; - -c|--customruleset) - ruleset="$2" ; shift; - break;; + vip=true;; + --ruleset) + ruleset="$2" ; shift;; # For options with required arguments, an additional shift is required # -o|--option) myarg="$2" ; shift;; - (--) shift; break;; + (--) shift;; (-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;; - (*) break;; + (*) shift;; esac shift done +# --vip and --ruleset aren't compatible +if [[ "$ruleset" != false && "$vip" = true ]]; then + error "You can't use both --vip and --ruleset" +fi + # Display a confirmation message and return 0/1 based on the result. confirm() { read -r -p "$1 [Y/n] " response @@ -74,15 +86,6 @@ copy_hook() { echo "Copying $hook hook" } -# Trigger an error and exit, but also tell users how they can re-run the script. -error() { - echo - echo "Error: $1" >&2 - echo "You may re-run this setup at any time by running $DIR/wp-enforcer" - echo - exit 1; -} - echo "Installing WP Enforcer..." # Check that the target Git repository exists diff --git a/composer.json b/composer.json index 5336940..22431d4 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "PHP_CodeSniffer" ], "require": { - "wp-coding-standards/wpcs": "^0.10.0" + "wp-coding-standards/wpcs": "*" }, "bin": [ "bin/wp-enforcer" diff --git a/composer.lock b/composer.lock index ce68c57..5f876d0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,21 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "28e365a28935034b2a8296e0d293e843", - "content-hash": "e73e27e50f889d9f52d101cbd0bec3cb", + "content-hash": "dd482ce6f6bf5dcefae89051b40b9d35", "packages": [ { "name": "squizlabs/php_codesniffer", - "version": "2.7.1", + "version": "2.9.1", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "9b324f3a1132459a7274a0ace2e1b766ba80930f" + "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/9b324f3a1132459a7274a0ace2e1b766ba80930f", - "reference": "9b324f3a1132459a7274a0ace2e1b766ba80930f", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62", + "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62", "shasum": "" }, "require": { @@ -83,24 +82,24 @@ "phpcs", "standards" ], - "time": "2016-11-30 04:02:31" + "time": "2017-05-22T02:43:20+00:00" }, { "name": "wp-coding-standards/wpcs", - "version": "0.10.0", + "version": "0.11.0", "source": { "type": "git", "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", - "reference": "b39490465f6fd7375743a395019cd597e12119c9" + "reference": "407e4b85f547a5251185f89ceae6599917343388" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/b39490465f6fd7375743a395019cd597e12119c9", - "reference": "b39490465f6fd7375743a395019cd597e12119c9", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/407e4b85f547a5251185f89ceae6599917343388", + "reference": "407e4b85f547a5251185f89ceae6599917343388", "shasum": "" }, "require": { - "squizlabs/php_codesniffer": "^2.6" + "squizlabs/php_codesniffer": "^2.8.1" }, "type": "library", "notification-url": "https://packagist.org/downloads/", @@ -119,7 +118,7 @@ "standards", "wordpress" ], - "time": "2016-08-29 20:04:47" + "time": "2017-03-20T23:17:58+00:00" } ], "packages-dev": [], diff --git a/phpcs-vip.xml.sample b/phpcs-vip.xml.sample index 6b2034f..886d04f 100644 --- a/phpcs-vip.xml.sample +++ b/phpcs-vip.xml.sample @@ -7,7 +7,7 @@ Coding standards from WP Enforcer. - + phpcs.xml */tests/* */vendor/* diff --git a/phpcs.xml.sample b/phpcs.xml.sample index 563f72e..dbb6871 100644 --- a/phpcs.xml.sample +++ b/phpcs.xml.sample @@ -7,7 +7,7 @@ Coding standards from WP Enforcer. - + phpcs.xml */tests/* */vendor/*