Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 2b942d4

Browse files
author
Chris Wiegman
authored
Update Standards for Easier Usage (#5)
* Remove obsolete scripts * Update legacy bin scripts for anyone still using them * Update json with fixes to work as composer package * Add default configuration * Remove shared config from rulesets * Update usage instructions * Don't suppress make output by default * Correctly call make * Implment script options * Fix wpecs script * Add scripted usage instructions to readme * wpecbf signature now matches wpecs signature
1 parent f20abbb commit 2b942d4

File tree

9 files changed

+173
-100
lines changed

9 files changed

+173
-100
lines changed

.phpcs.xml.dist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WP Engine Coding Standards for WordPress" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
3+
4+
<description>Coding standards, based on the WordPress Coding Standards, to improve security and performance on the WP Engine farm.</description>
5+
6+
<file>.</file>
7+
8+
<arg value="sp"/>
9+
<arg name="extensions" value="php"/>
10+
<arg name="basepath" value="."/>
11+
<arg name="parallel" value="8"/>
12+
13+
<!-- Up the Memory limit for large plugins -->
14+
<ini name="memory_limit" value="512M"/>
15+
16+
<!-- Exclude these paths -->
17+
<exclude-pattern>*/dev-lib/*</exclude-pattern>
18+
<exclude-pattern>*/node_modules/*</exclude-pattern>
19+
<exclude-pattern>*/vendor/*</exclude-pattern>
20+
<exclude-pattern>*/tests/*</exclude-pattern>
21+
22+
</ruleset>

Makefile

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
VENDOR_BIN := ./vendor/bin
22

33
install:
4-
@composer install
5-
@ $(VENDOR_BIN)/phpcs --config-set default_standard WP-Engine
6-
@ $(VENDOR_BIN)/phpcs --config-set show_progress 1 > /dev/null 2>&1
7-
@ $(VENDOR_BIN)/phpcs --config-set colors 1 > /dev/null 2>&1
8-
@chmod +x ${CURDIR}/bin/wpecs
9-
@chmod +x ${CURDIR}/bin/wpecbf
10-
@rm /usr/local/bin/wpecs || true
11-
@rm /usr/local/bin/wpecbf || true
12-
@ln -s ${CURDIR}/bin/wpecs /usr/local/bin/wpecs
13-
@ln -s ${CURDIR}/bin/wpecbf /usr/local/bin/wpecbf
14-
@ $(VENDOR_BIN)/phpcs -i; echo "\n"
15-
@echo "USAGE: wpecs [--strict] [phpcs-options] <path>\n"
16-
@echo "For assistance getting started try 'wpecs -h'\n"
4+
composer install
5+
$(VENDOR_BIN)/phpcs --config-set default_standard WP-Engine
6+
$(VENDOR_BIN)/phpcs --config-set show_progress 1 > /dev/null 2>&1
7+
$(VENDOR_BIN)/phpcs --config-set colors 1 > /dev/null 2>&1
8+
chmod +x ${CURDIR}/bin/wpecs
9+
chmod +x ${CURDIR}/bin/wpecbf
10+
rm /usr/local/bin/wpecs || true
11+
rm /usr/local/bin/wpecbf || true
12+
ln -s ${CURDIR}/bin/wpecs /usr/local/bin/wpecs
13+
ln -s ${CURDIR}/bin/wpecbf /usr/local/bin/wpecbf
14+
$(VENDOR_BIN)/phpcs -i; echo "\n"
15+
echo "USAGE: wpecs [--strict] [phpcs-options] <path>\n"
16+
echo "For assistance getting started try 'wpecs -h'\n"
1717
update:
18-
@git pull origin master
19-
@make install
18+
git pull origin master
19+
$(MAKE) install

README.md

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
WP Engine Coding Standards for WordPress
44

5-
If [WordPress Coding Standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/) offer a baseline for developers to use when contributing to or extending WordPress, think of WP Engine Coding Standards as an additional layer of best practices that:
5+
If [WordPress Coding Standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/) offer a baseline for developers to use when contributing to or extending WordPress, think of WP Engine Coding Standards as an additional layer of best practices that:
66

77
- help developers achieve greater consistency within their themes and plugins
88
- assist developers in meeting the requirements of a WP Engine Solution Partner
@@ -13,7 +13,7 @@ The information included here walks you through the process of installing and us
1313

1414
## Requirements
1515

16-
WP Engine Coding Standards (WPECS) uses [Composer](https://getcomposer.org/) to install these main dependencies:
16+
WP Engine Coding Standards (WPECS) uses [Composer](https://getcomposer.org/) to install these main dependencies:
1717

1818
* [PHP_Codesniffer (PHPCS)](https://github.com/squizlabs/PHP_CodeSniffer)
1919
* [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
@@ -23,6 +23,53 @@ If you're using Homebrew on Mac, you can install Composer with: `brew install co
2323

2424
## Installation
2525

26+
### Global installation
27+
28+
1. Clone the repository and install the dependencies:
29+
30+
```bash
31+
git clone [email protected]:wpengine/wpengine-coding-standards.git
32+
cd wpengine-coding-standards
33+
composer install
34+
```
35+
36+
2. Link your coding standards to your `phpcs` installation:
37+
38+
```bash
39+
phpcs --config-set installed_paths /path/to/wp-engine-coding-standards
40+
```
41+
42+
### Install as a dependency
43+
44+
You can also install the coding standards as a dependency in your local project. Here's how
45+
46+
1. Add the following repository to your composer.json
47+
48+
```json
49+
"repositories": [
50+
{
51+
"type": "git",
52+
"url": "https://github.com/wpengine/wpengine-coding-standards.git"
53+
}
54+
]
55+
```
56+
57+
2. Manually add the following to `require-dev` in composer.json
58+
59+
```json
60+
"wpengine/wpengine-coding-standards": "dev-master"
61+
```
62+
63+
3. Run `composer install` or `composer update` to ensure your project is configured.
64+
65+
4. You can now use `WP-Engine` or `WP-Engine-Strict` in any IDE that uses the local phpcs. If you already have a phpcs.xml in your project, simply add the following to it:
66+
67+
```xml
68+
<rule ref="WP-Engine-Strict"/>
69+
```
70+
71+
### Alternative Install (wpecs command)
72+
2673
Clone or download this repository. From terminal, navigate to the download location and install WPECS globally with the following command:
2774

2875
make install
@@ -31,11 +78,17 @@ You will then be able to run WPECS from any directory.
3178

3279
Running `make install` will install WPECS dependencies and register coding standards with PHPCS.
3380

81+
* Note you might need to manually move the binaries to your path, or properly set path, if make fails.
82+
3483
## Usage
3584

36-
USAGE: wpecs [--strict] [phpcs-options] <path>
37-
<wpecs> Run the specified path against the WP Engine Coding Standards
38-
<wpecbf> Attempt to fix sniffs against the WP Engine Strict Coding Standards
85+
### Command line
86+
87+
Run the `phpcs` command line tool on a given file or directory, for example:
88+
89+
```bash
90+
phpcs --standard=WP-Engine wp-load.php
91+
```
3992

4093
**WP-Engine Coding Standard**
4194

@@ -49,15 +102,22 @@ _The recommend standard for WP Engine authored plugins._
49102

50103
`wpecs --standard="WP-Engine-Strict" .`
51104

52-
Since WPECS is a collection of custom rulesets, you can still use regular [PHP_CodeSniffer commands](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage).
105+
### Using PHPCS and WP Engine Coding Standards from within your IDE
53106

54-
## Results
107+
While the following is based on the parent WordPress Coding Standards, simply swap out the ruleset you need for `WP-Engine` or `WP-Engine-Strict` as appropriate.
55108

56-
When you run WP Engine Coding Standards against your PHP file(s) or against a project directory, it will generate two reports:
109+
* **PhpStorm** : Please see "[PHP Code Sniffer with WordPress Coding Standards Integration](https://confluence.jetbrains.com/display/PhpStorm/WordPress+Development+using+PhpStorm#WordPressDevelopmentusingPhpStorm-PHPCodeSnifferwithWordPressCodingStandardsIntegrationinPhpStorm)" in the PhpStorm documentation.
110+
* **Sublime Text** : Please see "[Setting up WPCS to work in Sublime Text](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Setting-up-WPCS-to-work-in-Sublime-Text)" in the wiki.
111+
* **Atom**: Please see "[Setting up WPCS to work in Atom](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Setting-up-WPCS-to-work-in-Atom)" in the wiki.
112+
* **Visual Studio**: Please see "[Setting up PHP CodeSniffer in Visual Studio Code](https://tommcfarlin.com/php-codesniffer-in-visual-studio-code/)", a tutorial by Tom McFarlin.
113+
* **Eclipse with XAMPP**: Please see "[Setting up WPCS when using Eclipse with XAMPP](https://github.com/WordPress/WordPress-Coding-Standards/wiki/How-to-use-WPCS-with-Eclipse-and-XAMPP)" in the wiki.
57114

58-
* Summary report of PHP Code Sniffer violations (`report-summary.txt`)
59-
* Verbose report of PHP Code Sniffer violations (`report-full.txt`)
115+
### Alternative usage (wpecs)
60116

61-
The summary provides an overview of how many total sniff violations were detected, while the detailed review highlights specific lines of code (by file) where errors or warnings were detected and what the issues are.
117+
USAGE: wpecs [--strict] [phpcs-options] <path>
118+
<wpecs> Run the specified path against the WP Engine Coding Standards
119+
<wpecbf> Attempt to fix sniffs against the WP Engine Strict Coding Standards
120+
121+
## Results
62122

63123
For help understanding errors or warnings and suggestions for troubleshooting specific issues, please refer to the full [WP Engine Coding Standards Documentation](https://github.com/wpengine/wpengine-coding-standards/wiki).

WP-Engine-Strict/ruleset.xml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
<?xml version="1.0"?>
2-
<ruleset name="WP Engine Strict" namespace="WPE\CS">
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WP Engine Strict" namespace="WPE\CS" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
33
<description>WP Engine Coding Standards - Strict</description>
44

5-
<!-- Only sniff PHP files -->
6-
<arg name="extensions" value="php"/>
7-
8-
<!-- Show sniff codes in all reports -->
9-
<arg value="s"/>
10-
11-
<!-- Up the Memory limit for large plugins -->
12-
<ini name="memory_limit" value="512M"/>
13-
14-
<!-- Exclude these paths -->
15-
<exclude-pattern>*/dev-lib/*</exclude-pattern>
16-
<exclude-pattern>*/node_modules/*</exclude-pattern>
17-
<exclude-pattern>*/vendor/*</exclude-pattern>
18-
<exclude-pattern>*/tests/*</exclude-pattern>
19-
205
<rule ref="PHPCompatibilityWP">
216
<severity>10</severity>
227
</rule>

WP-Engine/ruleset.xml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,7 @@
11
<?xml version="1.0"?>
2-
<ruleset name="WP Engine" namespace="WPE\CS">
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WP Engine" namespace="WPE\CS" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
33
<description>WP Engine Coding Standards</description>
44

5-
<!-- <arg name="basepath" value="."/> -->
6-
7-
<!-- Set the default file path. -->
8-
<!-- <file>views</file> -->
9-
10-
<!-- Only sniff PHP files -->
11-
<arg name="extensions" value="php"/>
12-
13-
<!-- Show sniff codes in all reports -->
14-
<arg value="s"/>
15-
16-
<!-- Up the Memory limit for large plugins -->
17-
<ini name="memory_limit" value="512M"/>
18-
19-
<!-- Exclude WP Core folders and files from being checked. -->
20-
<exclude-pattern>/docroot/wp-admin/*</exclude-pattern>
21-
<exclude-pattern>/docroot/wp-includes/*</exclude-pattern>
22-
<exclude-pattern>/docroot/wp-*.php</exclude-pattern>
23-
<exclude-pattern>/docroot/index.php</exclude-pattern>
24-
<exclude-pattern>/docroot/xmlrpc.php</exclude-pattern>
25-
<exclude-pattern>/docroot/wp-content/plugins/*</exclude-pattern>
26-
27-
<!-- Exclude the Composer Vendor directory. -->
28-
<exclude-pattern>/vendor/*</exclude-pattern>
29-
30-
<!-- Exclude the Node Modules directory. -->
31-
<exclude-pattern>/node_modules/*</exclude-pattern>
32-
33-
<!-- Exclude tests. -->
34-
<exclude-pattern>/tests/*</exclude-pattern>
35-
365
<rule ref="PHPCompatibilityWP">
376
<severity>10</severity>
387
</rule>

bin/install.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

bin/wpecbf

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,29 @@ echo -e "WP Engine Coding Standards\nVersion 1.0.0\n"
33

44
SOURCE_DIR=$(readlink "${BASH_SOURCE[0]}")
55
VENDOR_DIR="$(dirname "$(dirname "$SOURCE_DIR" )" )"
6+
PHPCS_STANDARD="WP-Engine"
7+
PHPCS_ARGS=${@}
8+
NEEDS_HELP="false"
9+
10+
if [[ $# = 0 ]]; then
11+
NEEDS_HELP="true"
12+
fi
13+
14+
if [ "${1}" = "-h" ] || [ "${1}" = "--h" ] || [ "${NEEDS_HELP}" = "true" ]
15+
then
16+
echo -e "WP Engine Coding Standards\n"
17+
echo -e "USAGE: wpecbf [--strict] [phpcbf-options] <path>\n"
18+
echo -e "<wpecs> Run the WP Engine Coding Standards\n"
19+
echo -e "<wpecbf> Attempt to fix sniffs against the WP Engine Strict Coding Standards\n"
20+
echo -e "[phpcs-options] Any argument that can be passed to PHP CodeSniffer\n"
21+
exit 0
22+
fi
23+
24+
if [ "${1}" = "--strict" ]; then
25+
PHPCS_STANDARD="WP-Engine-Strict"
26+
PHPCS_ARGS=${@:2}
27+
fi
628

729
echo -e "Attempting to beautify against WP Engine Coding Standards\n"
830

9-
${VENDOR_DIR}/vendor/bin/phpcbf --standard="WP-Engine-Strict" --basepath=. --ignore=*build*,*node_modules*,*vendor* ${@}
31+
${VENDOR_DIR}/vendor/bin/phpcbf --standard="${PHPCS_STANDARD}" --basepath=. --ignore=*build*,*node_modules*,*vendor* ${PHPCS_ARGS}

bin/wpecs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,30 @@ echo -e "WP Engine Coding Standards\nVersion 1.0.0\n"
33

44
SOURCE_DIR=$(readlink "${BASH_SOURCE[0]}")
55
VENDOR_DIR="$(dirname "$(dirname "$SOURCE_DIR" )" )"
6+
PHPCS_STANDARD="WP-Engine"
7+
PHPCS_ARGS=${@}
8+
NEEDS_HELP="false"
69

7-
#echo -e "$BASH_SOURCE\n"
8-
#echo -e "$VENDOR_DIR\n"
9-
${VENDOR_DIR}/vendor/bin/phpcs --standard="WP-Engine" --basepath=../ --ignore=*build*,*node_modules*,*vendor* --report-full=report-full.txt --report-summary=report-summary.txt --report-source ${@}
10-
#
11-
#echo -e "${VENDOR_DIR}/bin/phpcs"
10+
if [[ $# = 0 ]]; then
11+
NEEDS_HELP="true"
12+
fi
1213

13-
if [ "${1}" = "-h" ] || [ "${1}" = "--h" ]
14+
if [ "${1}" = "-h" ] || [ "${1}" = "--h" ] || [ "${NEEDS_HELP}" = "true" ]
1415
then
1516
echo -e "WP Engine Coding Standards\n"
1617
echo -e "USAGE: wpecs [--strict] [phpcs-options] <path>\n"
1718
echo -e "<wpecs> Run the WP Engine Coding Standards\n"
1819
echo -e "<wpecbf> Attempt to fix sniffs against the WP Engine Strict Coding Standards\n"
1920
echo -e "[phpcs-options] Any argument that can be passed to PHP CodeSniffer\n"
21+
exit 0
22+
fi
23+
24+
if [ "${1}" = "--strict" ]; then
25+
PHPCS_STANDARD="WP-Engine-Strict"
26+
PHPCS_ARGS=${@:2}
2027
fi
2128

29+
${VENDOR_DIR}/vendor/bin/phpcs --standard="${PHPCS_STANDARD}" --basepath=../ --ignore=*build*,*node_modules*,*vendor* --report-full=report-full.txt --report-summary=report-summary.txt --report-source ${PHPCS_ARGS}
30+
2231
echo -e "Reports can be found in the target directory as 'report-full.txt' and 'report-source.txt'\n"
2332
echo -e "Try using 'wpecbf' to attempt fix the sniff violations automatically.\n"

composer.json

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "wpengine/wpengine-coding-standards",
3-
"type": "phpcodesniffer-wrapper",
3+
"type": "phpcodesniffer-standard",
44
"description": "PHP_CodeSniffer rules (sniffs) to enforce WP Engine coding conventions",
55
"keywords": [
66
"wpecs",
77
"phpcs",
88
"standards",
99
"WordPress",
10-
"WP Engine"
10+
"WP-Engine"
1111
],
1212
"license": "MIT",
1313
"authors": [
@@ -18,10 +18,10 @@
1818
],
1919
"require": {
2020
"php": ">=5.4",
21-
"squizlabs/php_codesniffer": "^3.3.1",
22-
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
23-
"wp-coding-standards/wpcs": "1.*",
24-
"phpcompatibility/phpcompatibility-wp": "^1"
21+
"squizlabs/php_codesniffer": "^3.5",
22+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
23+
"wp-coding-standards/wpcs": "^2",
24+
"phpcompatibility/phpcompatibility-wp": "^2"
2525
},
2626
"minimum-stability": "dev",
2727
"prefer-stable" : true,
@@ -32,7 +32,23 @@
3232
},
3333
"bin": [
3434
"bin/wpecs",
35-
"bin/wpecbf",
36-
"bin/install.sh"
37-
]
35+
"bin/wpecbf"
36+
],
37+
"scripts": {
38+
"check-cs": [
39+
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs"
40+
],
41+
"fix-cs": [
42+
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
43+
],
44+
"install-codestandards": [
45+
"Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
46+
],
47+
"check-complete": [
48+
"@php ./vendor/phpcsstandards/phpcsdevtools/bin/phpcs-check-feature-completeness -q ./WP-Engine"
49+
],
50+
"check-complete-strict": [
51+
"@php ./vendor/phpcsstandards/phpcsdevtools/bin/phpcs-check-feature-completeness ./WP-Engine"
52+
]
53+
}
3854
}

0 commit comments

Comments
 (0)