Skip to content

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegrunwell committed May 28, 2017
2 parents d975e35 + e1fbad3 commit 6d58358
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 48 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
41 changes: 32 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,33 @@ 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:

```bash
$ ./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).
Expand All @@ -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.
Expand All @@ -77,10 +87,23 @@ 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
$ ./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).
47 changes: 25 additions & 22 deletions bin/wp-enforcer
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"PHP_CodeSniffer"
],
"require": {
"wp-coding-standards/wpcs": "^0.10.0"
"wp-coding-standards/wpcs": "*"
},
"bin": [
"bin/wp-enforcer"
Expand Down
25 changes: 12 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpcs-vip.xml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>Coding standards from WP Enforcer.</description>

<!-- FILES -->

<exclude-pattern>phpcs.xml</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>Coding standards from WP Enforcer.</description>

<!-- FILES -->

<exclude-pattern>phpcs.xml</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

Expand Down

0 comments on commit 6d58358

Please sign in to comment.