Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegrunwell committed Dec 2, 2015
2 parents 4f1fb1d + 071c85f commit 74ca822
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
vendor
vendor
phpcs.xml
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Change Log

All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.4.0] - 2015-12-02

* Restore explicit reference to `vendor/bin` (previously removed in [#3]) within the pre-commit Git hook ([#11]). Props @leewillis77.
* Added `--help` and `--version` options to the `wp-enforcer` command for easier usage (and setting us up for more fun options in the future, [#8]). Props @daveross.
* Fixed major bug wherein PHP_CodeSniffer was complaining about files not containing any code ([#12]).
* Added a `--vip` option to the `wp-enforcer` command to use WordPress.com VIP coding standards ([#7]). Props @daveross.
* Moved the Change Log out of the README and into CHANGELOG.md ([#19]).


## [0.3.0] - 2015-11-29

* Remove explicit references to `./vendor/bin/`, as Composer automatically prepends this directory to the user's path ([#3]). Props @johnpbloch, @bswatson.
* Automatically create a `.git/hooks` directory if it doesn't already exist ([#5]).


## [0.2.0] - 2015-11-27

* Restrict the Git hook to only changed files, not the entire codebase ([#1]).
* Confirmed Windows Compatibility (as Git Bash ships with a version of Cygwin for all the Unix-y goodness needed). Props @EricMann ([#2]).


## 0.1.0 - 2015-11-22

* Initial public release.

[0.4.0]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.3.0...HEAD
[0.3.0]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/stevegrunwell/wp-enforcer/compare/v0.1.0...v0.2.0
[#1]: https://github.com/stevegrunwell/wp-enforcer/issues/1
[#2]: https://github.com/stevegrunwell/wp-enforcer/issues/2
[#3]: https://github.com/stevegrunwell/wp-enforcer/issues/3
[#5]: https://github.com/stevegrunwell/wp-enforcer/issues/5
[#7]: https://github.com/stevegrunwell/wp-enforcer/issues/7
[#8]: https://github.com/stevegrunwell/wp-enforcer/issues/8
[#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
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Thank you for taking an interest in helping enforce coding standards on WordPres

This project is open for anyone to make suggestions, report issues, and contribute code, but please adhere to the following guidelines:

1. **Keep the code as portable as possible:!** Not everyone is running the same, super-cool setup that you use, so we're targeting code that will run across the largest number of machines. That means Bash scripting that will run on OSX, Linux, and Cygwin for our friends on Windows.
2. **The code is meant to be a starting point for PHP_CodeSniffer usage.** There are a lot of different configurations for WordPress projects, so the best thing we can do is give developers the tools they need to get started and point them to things like [the PHP_CodeSniffer ruleset.xml standard](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml)
1. **Keep the code as portable as possible!** Not everyone is running the same, super-cool setup that you use, so we're targeting code that will run across the largest number of machines. That means Bash scripting that will run on OSX, Linux, and Cygwin for our friends on Windows.
2. **The code is meant to be a starting point for PHP_CodeSniffer usage.** There are a lot of different configurations for WordPress projects, so the best thing we can do is give developers the tools they need to get started and point them to things like [the PHP_CodeSniffer ruleset.xml standard](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml).

## Branching strategy

The **master** branch should be considered stable, enabling people to pull from "dev-master" at any time and be sure their projects are safe. Active development happens in the **develop** branch.
The **master** branch should be considered stable, enabling people to pull from "dev-master" at any time and be sure their projects are safe. Active development happens in the **develop** branch. New branches should fork off of the **develop** branch, as this repository is now following the [Gitflow Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) as of version 0.4.0.
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

When writing for a platform as big as WordPress – especially in a team environment – a consistent set of coding standards is vital. Having multiple developers committing code using a mixture of spaces and tabs, inconsistent formatting, or otherwise varying coding styles can lead to headache-inducing merge conflicts.

There are a number of great tools available to check against established coding standards (namely [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)), but setting them up on a project can be a pain. WP Enforcer is designed to make this setup a breeze.
There are a number of great tools available to check against established coding standards (namely [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)), but setting them up on a project can be a pain. WP Enforcer is designed to make this setup a breeze.


## How does it work?

WP Enforcer uses [Git Hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) to automatically run PHP CodeSniffer every time a developer tries to make a commit; if the code isn't up-to-snuff, the commit will be rejected and the developer will get a message explaining what needs to be fixed.
WP Enforcer uses [Git Hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) to automatically run PHP_CodeSniffer every time a developer tries to make a commit; if the code isn't up-to-snuff, the commit will be rejected and the developer will get a message explaining what needs to be fixed.

**Note:** If your project already has messy standards you may not want to make WP Enforcer mandatory until *after* you've cleaned up the codebase or suddenly commits will be quite painful! See [Adding to an Existing Project](#adding-to-an-existing-project) for an easy work-around.

Expand Down Expand Up @@ -42,12 +42,22 @@ If you'd like to require WP Enforcer for all developers on your project, you can
]
```

### 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).

If you need to switch an existing project to the WordPress.com VIP coding standards, you can add the following to your project's phpcs.xml file (replacing "WordPress-Extra", if it's set):

```xml
<rule ref="WordPress-VIP" />
```


## 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.
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.

For a complete list of configuration options, see [the PHP CodeSniffer ruleset.xml standard](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml).
For a complete list of configuration options, see [the PHP_CodeSniffer ruleset.xml standard](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml).


## Adding to an Existing Project
Expand All @@ -59,8 +69,9 @@ If you're adding WP Enforcer to a current project, it's recommended to follow th
```bash
$ rm .git/hooks/pre-commit
```
> **Reminder:** Use the `rm` command with care; double-check everything you're passing to it before you execute, as we'd hate to see you lose valuable repository information (or worse: your operating system).
This leaves you with a copy of PHP CodeSniffer, a phpcs.xml file, and the WordPress Coding Standards but removes the "don't commit improperly formatted code" restrictions. While still in your clean-up branch, work through the codebase and clean up coding standards, running PHP CodeSniffer manually as needed:
This leaves you with a copy of PHP_CodeSniffer, a phpcs.xml file, and the WordPress Coding Standards but removes the "don't commit improperly formatted code" restrictions. While still in your clean-up branch, work through the codebase and clean up coding standards, running PHP_CodeSniffer manually as needed:

```bash
$ ./vendor/bin/phpcs
Expand All @@ -73,15 +84,3 @@ $ ./vendor/bin/wp-enforcer
```

Finally, merge your clean-up branch into master, kicking your project's coding standards compliance into high gear.

## Changelog

### 0.3.0 - November 29, 2015

* Remove explicit references to `./vendor/bin/`, as Composer automatically prepends this directory to the user's path ([#3](https://github.com/stevegrunwell/wp-enforcer/issues/3)). Props @johnpbloch, @bswatson.
* Automatically create a `.git/hooks` directory if it doesn't already exist ([#5](https://github.com/stevegrunwell/wp-enforcer/issues/5)).

### 0.2.0 - November 27, 2015

* Restrict the Git hook to only changed files, not the entire codebase ([#1](https://github.com/stevegrunwell/wp-enforcer/issues/1)).
* Confirmed Windows Compatibility (as Git Bash ships with a version of Cygwin for all the Unix-y goodness needed). Props @EricMann ([#2](https://github.com/stevegrunwell/wp-enforcer/issues/2)).
6 changes: 3 additions & 3 deletions bin/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ else
standard=''
fi

# Run PHP CodeSniffer
echo "Running PHP CodeSniffer..."
# Run PHP_CodeSniffer
echo "Running PHP_CodeSniffer..."

git diff --name-only --cached | xargs phpcs $standard
git diff --name-only --cached | xargs vendor/bin/phpcs $standard
if [ $? != 0 ]
then
echo "Please fix coding standards errors before committing"
Expand Down
35 changes: 27 additions & 8 deletions bin/wp-enforcer
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
#
# Copy files for WP Enforcer into the project directory.

readonly VERSION="0.4.0"
readonly BIN="$(cd "$(dirname "$0")" && pwd -P)"
readonly DIR="$BIN/$(dirname "$(readlink "$0")")"
readonly PROJECT="$(pwd)"
vip=false

# 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 -l help -- "$@")
if ! options=$(getopt -o h,v -l help,version,vip -- "$@")
then
# something went wrong, getopt will put out an error message for us
exit 1
Expand All @@ -20,11 +22,23 @@ while [ $# -gt 0 ]
do
case $1 in
-h|--help)
echo "Usage: wp-enforcer [OPTION]...";
echo "After adding wp-enforcer to a project with Composer, run this script to finish installation.";
echo "";
echo " -h, --help display this help and exit";
echo "After adding WP Enforcer to a project with Composer, run this script to finish installation."
echo ""
echo "USAGE:"
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 ""
exit;;
-v|--version)
echo "$VERSION"
exit;;
--vip)
vip=true;
break;;
# For options with required arguments, an additional shift is required
# -o|--option) myarg="$2" ; shift;;
(--) shift; break;;
Expand Down Expand Up @@ -94,13 +108,18 @@ else
copy_hook "pre-commit"
fi

# Copy the PHP CodeSniffer standards file
# Copy the PHP_CodeSniffer standards file
if [[ ! -f "$PROJECT"/phpcs.xml ]]; then
cp "$DIR"/../phpcs.xml.sample "$PROJECT"/phpcs.xml
if [ "$vip" = false ]; then
sample_file_name="phpcs.xml.sample"
else
sample_file_name="phpcs-vip.xml.sample"
fi
cp "$DIR"/../"$sample_file_name" "$PROJECT"/phpcs.xml
echo "Created sample phpcs.xml file"
fi

# Configure PHP CodeSniffer
# Configure PHP_CodeSniffer
installed_paths="$("$BIN"/phpcs --config-show | grep "installed_paths:")"
if [[ "$installed_paths" != "installed_paths: ../../wp-coding-standards/wpcs" ]]; then
"$BIN"/phpcs --config-set installed_paths ../../wp-coding-standards/wpcs
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stevegrunwell/wp-enforcer",
"description": "Git hooks to encourage well-written WordPress.",
"version": "0.3.0",
"version": "0.4.0",
"authors": [
{
"name": "Steve Grunwell",
Expand All @@ -14,7 +14,7 @@
"git hooks",
"WordPress",
"coding standards",
"PHP CodeSniffer"
"PHP_CodeSniffer"
],
"require": {
"wp-coding-standards/wpcs": "0.8.0"
Expand Down
24 changes: 24 additions & 0 deletions phpcs-vip.xml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!--
Customize the rules WP Enforcer uses by editing this file according to PHP_CodeSniffer's
ruleset.xml standard: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
-->
<ruleset name="WP-Enforcer">
<description>Coding standards from WP Enforcer.</description>

<!-- FILES -->

<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

<!--
Don't get angry about checking files that don't contain code
@link https://github.com/stevegrunwell/wp-enforcer/issues/12
-->
<rule ref="Internal.NoCodeFound">
<severity>0</severity>
</rule>

<rule ref="WordPress-VIP" />
<rule ref="WordPress-Docs" />
</ruleset>
16 changes: 12 additions & 4 deletions phpcs.xml.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
Customize the rules WP Enforcer uses by editing this file according to PHP CodeSniffer's
ruleset.xml standard: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
Customize the rules WP Enforcer uses by editing this file according to PHP_CodeSniffer's
ruleset.xml standard: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
-->
<ruleset name="WP-Enforcer">
<description>Coding standards from WP Enforcer.</description>
Expand All @@ -11,6 +11,14 @@
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

<rule ref="WordPress-Extra"/>
<rule ref="WordPress-Docs"/>
<!--
Don't get angry about checking files that don't contain code
@link https://github.com/stevegrunwell/wp-enforcer/issues/12
-->
<rule ref="Internal.NoCodeFound">
<severity>0</severity>
</rule>

<rule ref="WordPress-Extra" />
<rule ref="WordPress-Docs" />
</ruleset>

0 comments on commit 74ca822

Please sign in to comment.