Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Commit 6d58358

Browse files
committed
Merge branch 'release/0.5.0'
2 parents d975e35 + e1fbad3 commit 6d58358

File tree

7 files changed

+84
-48
lines changed

7 files changed

+84
-48
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

66

7+
## [0.5.0] - 2017-05-28
8+
9+
* Allow any version of [wp-coding-standards/wpcs](https://github.com/wp-coding-standards/wpcs), avoiding conflicts with packages that use older versions ([#37]).
10+
* Clarify placement of scripts within `composer.json` ([#41]).
11+
* Exclude `phpcs.xml` from being checked by PHP_CodeSniffer ([#27]).
12+
13+
714
## [0.4.2] - 2017-01-04
815

916
* 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/).
4249

4350

4451
[Unreleased]: https://github.com/stevegrunwell/wp-enforcer/compare/develop...master
45-
[0.4.2]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.4.1...master
52+
[0.4.2]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.5.0...master
53+
[0.4.2]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.4.1...v0.4.2
4654
[0.4.1]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.4.0...v0.4.1
4755
[0.4.0]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.3.0...v0.4.0
4856
[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/).
5664
[#11]: https://github.com/stevegrunwell/wp-enforcer/issues/11
5765
[#12]: https://github.com/stevegrunwell/wp-enforcer/issues/12
5866
[#19]: https://github.com/stevegrunwell/wp-enforcer/issues/19
67+
[#27]: https://github.com/stevegrunwell/wp-enforcer/issues/27
5968
[#29]: https://github.com/stevegrunwell/wp-enforcer/issues/29
69+
[#37]: https://github.com/stevegrunwell/wp-enforcer/issues/37
70+
[#41]: https://github.com/stevegrunwell/wp-enforcer/issues/41

README.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,33 @@ WP Enforcer uses [Git Hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-
2020
The easiest way to install WP Enforcer is via Composer:
2121

2222
```bash
23-
$ composer require stevegrunwell/wp-enforcer
23+
$ composer require --dev stevegrunwell/wp-enforcer
2424
```
2525

26-
This will add WP Enforcer to your composer.json file and install the WP Enforcer package.
26+
This will add WP Enforcer to your `composer.json` file and install the WP Enforcer package.
2727

2828
Next, you'll need to run the WP Enforcer installation script to copy the Git hooks into your local repository:
2929

3030
```bash
3131
$ ./vendor/bin/wp-enforcer
3232
```
3333

34-
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`:
34+
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)):
3535

3636
```json
37-
"post-install-cmd": [
38-
"wp-enforcer"
39-
],
40-
"post-update-cmd": [
41-
"wp-enforcer"
42-
]
37+
{
38+
"scripts": {
39+
"post-install-cmd": [
40+
"wp-enforcer"
41+
],
42+
"post-update-cmd": [
43+
"wp-enforcer"
44+
]
45+
}
46+
}
4347
```
4448

49+
4550
### Writing for WordPress.com VIP
4651

4752
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
5358
```
5459

5560

61+
### Using a custom ruleset
62+
63+
If you want to use a custom XML configuration file with PHP_CodeSniffer, add `--ruleset=[FILE]` when you run the `wp-enforcer` command.
64+
65+
5666
## Configuration
5767

5868
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,10 +87,23 @@ This leaves you with a copy of PHP_CodeSniffer, a phpcs.xml file, and the WordPr
7787
$ ./vendor/bin/phpcs
7888
```
7989

90+
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:
91+
92+
```bash
93+
$ ./vendor/bin/phpcbf
94+
```
95+
8096
Once CodeSniffer comes back clean, re-run the WP Enforcer installation script to restore the Git hook, forcing all future commits to be clean:
8197

8298
```bash
8399
$ ./vendor/bin/wp-enforcer
84100
```
85101

86102
Finally, merge your clean-up branch into master, kicking your project's coding standards compliance into high gear.
103+
104+
105+
## Bypassing WP Enforcer
106+
107+
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).
108+
109+
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).

bin/wp-enforcer

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,27 @@
22
#
33
# Copy files for WP Enforcer into the project directory.
44

5-
readonly VERSION="0.4.0"
5+
readonly VERSION="0.5.0"
66
readonly BIN="$(cd "$(dirname "$0")" && pwd -P)"
77
readonly DIR="$BIN/$(dirname "$(readlink "$0")")"
88
readonly PROJECT="$(pwd)"
99
vip=false
1010
ruleset=false
1111

12+
# Trigger an error and exit, but also tell users how they can re-run the script.
13+
error() {
14+
echo
15+
echo "Error: $1" >&2
16+
echo "You may re-run this setup at any time by running $DIR/wp-enforcer"
17+
echo
18+
exit 1;
19+
}
20+
1221
# Define command-line options here.
1322
# Follow -o with a comma-separated list of single-character option names.
1423
# Follow -l with a comma-separated list of long option names.
1524
# Options may be followed by one colon to indicate they have a required argument
16-
if ! options=$(getopt -o h,v,c -l help,version,vip,customruleset -- "$@")
25+
if ! options=$(getopt -o h,v -l help,version,vip,ruleset: -- "$@")
1726
then
1827
# something went wrong, getopt will put out an error message for us
1928
exit 1
@@ -29,30 +38,33 @@ do
2938
echo " wp-enforcer [options]"
3039
echo ""
3140
echo "OPTIONS:"
32-
echo " --help, -h Show this help and usage"
33-
echo " --version, -v Show the current version of WP Enforcer"
34-
echo " --vip Configure the project to use the WordPress.com VIP coding standards"
35-
echo " --customruleset, -c Configure the project to use a custom PHPCS ruleset file"
41+
echo " --help, -h Show this help and usage"
42+
echo " --version, -v Show the current version of WP Enforcer"
43+
echo " --vip Configure the project to use the WordPress.com VIP coding standards"
44+
echo " --ruleset=FILE Configure the project to use a custom PHPCS ruleset file"
3645
echo ""
3746
exit;;
3847
-v|--version)
3948
echo "$VERSION"
4049
exit;;
4150
--vip)
42-
vip=true;
43-
break;;
44-
-c|--customruleset)
45-
ruleset="$2" ; shift;
46-
break;;
51+
vip=true;;
52+
--ruleset)
53+
ruleset="$2" ; shift;;
4754
# For options with required arguments, an additional shift is required
4855
# -o|--option) myarg="$2" ; shift;;
49-
(--) shift; break;;
56+
(--) shift;;
5057
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
51-
(*) break;;
58+
(*) shift;;
5259
esac
5360
shift
5461
done
5562

63+
# --vip and --ruleset aren't compatible
64+
if [[ "$ruleset" != false && "$vip" = true ]]; then
65+
error "You can't use both --vip and --ruleset"
66+
fi
67+
5668
# Display a confirmation message and return 0/1 based on the result.
5769
confirm() {
5870
read -r -p "$1 [Y/n] " response
@@ -74,15 +86,6 @@ copy_hook() {
7486
echo "Copying $hook hook"
7587
}
7688

77-
# Trigger an error and exit, but also tell users how they can re-run the script.
78-
error() {
79-
echo
80-
echo "Error: $1" >&2
81-
echo "You may re-run this setup at any time by running $DIR/wp-enforcer"
82-
echo
83-
exit 1;
84-
}
85-
8689
echo "Installing WP Enforcer..."
8790

8891
# Check that the target Git repository exists

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"PHP_CodeSniffer"
2121
],
2222
"require": {
23-
"wp-coding-standards/wpcs": "^0.10.0"
23+
"wp-coding-standards/wpcs": "*"
2424
},
2525
"bin": [
2626
"bin/wp-enforcer"

composer.lock

Lines changed: 12 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpcs-vip.xml.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<description>Coding standards from WP Enforcer.</description>
88

99
<!-- FILES -->
10-
10+
<exclude-pattern>phpcs.xml</exclude-pattern>
1111
<exclude-pattern>*/tests/*</exclude-pattern>
1212
<exclude-pattern>*/vendor/*</exclude-pattern>
1313

phpcs.xml.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<description>Coding standards from WP Enforcer.</description>
88

99
<!-- FILES -->
10-
10+
<exclude-pattern>phpcs.xml</exclude-pattern>
1111
<exclude-pattern>*/tests/*</exclude-pattern>
1212
<exclude-pattern>*/vendor/*</exclude-pattern>
1313

0 commit comments

Comments
 (0)