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

Commit eda9262

Browse files
author
Chris Wiegman
authored
Merge pull request #7 from wpengine/develop
Merge to master
2 parents 714ea56 + 2b942d4 commit eda9262

File tree

8 files changed

+215
-81
lines changed

8 files changed

+215
-81
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: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,122 @@
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:
6+
7+
- help developers achieve greater consistency within their themes and plugins
8+
- assist developers in meeting the requirements of a WP Engine Solution Partner
9+
- ensure that all software listed in the WP Engine Solution Center is of the highest quality
10+
- offer users maximum performance and security benefits when using those themes and plugins in a modern hosting environment (PHP 7+)
11+
12+
The information included here walks you through the process of installing and using WP Engine Coding Standards to lint your code.
13+
514
## Requirements
615

16+
WP Engine Coding Standards (WPECS) uses [Composer](https://getcomposer.org/) to install these main dependencies:
17+
18+
* [PHP_Codesniffer (PHPCS)](https://github.com/squizlabs/PHP_CodeSniffer)
19+
* [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
20+
* [PHPCompatibilityWP](https://github.com/PHPCompatibility/PHPCompatibilityWP).
21+
22+
If you're using Homebrew on Mac, you can install Composer with: `brew install composer`. Otherwise, follow the official installation instructions for Composer.
23+
724
## Installation
825

9-
You can install WPECS globally with the following command:
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+
73+
Clone or download this repository. From terminal, navigate to the download location and install WPECS globally with the following command:
1074

1175
make install
1276

13-
You will then be able to run WPECS from the any directory:
77+
You will then be able to run WPECS from any directory.
78+
79+
Running `make install` will install WPECS dependencies and register coding standards with PHPCS.
80+
81+
* Note you might need to manually move the binaries to your path, or properly set path, if make fails.
82+
83+
## Usage
84+
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+
```
92+
93+
**WP-Engine Coding Standard**
94+
95+
_The required standard for secure WordPress development._
96+
97+
`wpecs .`
98+
99+
**WP-Engine-Strict Coding Standard**
100+
101+
_The recommend standard for WP Engine authored plugins._
102+
103+
`wpecs --standard="WP-Engine-Strict" .`
104+
105+
### Using PHPCS and WP Engine Coding Standards from within your IDE
106+
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.
108+
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.
114+
115+
### Alternative usage (wpecs)
116+
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
14120

15-
USAGE: wpecs [--strict] [phpcs-options] <path>
16-
<wpecs> Run the specified path against the WP Engine Coding Standards
17-
<wpecbf> Attempt to fix sniffs against the WP Engine Strict Coding Standards
121+
## Results
18122

19-
Try using 'wpecbf' to fix the sniff violations automatically.
123+
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/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: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
#!/bin/bash
2-
echo -e "WP Engine Coding Standards\nVersion 0.1.0\n"
2+
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-
${VENDOR_DIR}/vendor/bin/phpcs --basepath=../ --report-full=report-full.txt --report-source=report-source.txt --report-summary ${@}
10+
if [[ $# = 0 ]]; then
11+
NEEDS_HELP="true"
12+
fi
813

9-
if [ "${1}" = "-h" ] || [ "${1}" = "--h" ]
14+
if [ "${1}" = "-h" ] || [ "${1}" = "--h" ] || [ "${NEEDS_HELP}" = "true" ]
1015
then
1116
echo -e "WP Engine Coding Standards\n"
1217
echo -e "USAGE: wpecs [--strict] [phpcs-options] <path>\n"
1318
echo -e "<wpecs> Run the WP Engine Coding Standards\n"
1419
echo -e "<wpecbf> Attempt to fix sniffs against the WP Engine Strict Coding Standards\n"
1520
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}
1627
fi
1728

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+
1831
echo -e "Reports can be found in the target directory as 'report-full.txt' and 'report-source.txt'\n"
1932
echo -e "Try using 'wpecbf' to attempt fix the sniff violations automatically.\n"

composer.json

Lines changed: 27 additions & 8 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": [
@@ -17,19 +17,38 @@
1717
}
1818
],
1919
"require": {
20-
"wp-coding-standards/wpcs": "1.*",
21-
"phpcompatibility/phpcompatibility-wp": "^1"
22-
},
23-
"require-dev": {
2420
"php": ">=5.4",
25-
"squizlabs/php_codesniffer": "^3.3.1",
26-
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0"
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"
2725
},
2826
"minimum-stability": "dev",
2927
"prefer-stable" : true,
3028
"support": {
3129
"issues": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues",
3230
"wiki": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki",
3331
"source": "https://github.com/wpengine/WPEngine-Coding-Standards"
32+
},
33+
"bin": [
34+
"bin/wpecs",
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+
]
3453
}
3554
}

0 commit comments

Comments
 (0)