Yoast Coding Standards
Yoast Coding Standards (YoastCS) is a project with rulesets for code style and quality tools to be used in Yoast projects.
Standards are provided as a Composer package and can be installed with:
composer create-project yoast/yoastcs:dev-master
Composer will automatically install dependencies, register standards paths, and set default PHP Code Sniffer standard to
To include standards as part of a project require them as development dependencies:
composer require --dev yoast/yoastcs:^2.0
Composer will automatically install dependencies and register the YoastCS and other external standards with PHP_CodeSniffer.
PHP Code Sniffer
Set of PHP_CodeSniffer rules.
- error level issues are considered mandatory to fix in Yoast projects and enforced in continuous integration
- warning level issues are considered recommended to fix
The YoastCS Standard
Yoast standard for PHP_CodeSniffer is comprised of the following:
WordPressruleset from the WordPress Coding Standards implementing the official WordPress PHP Coding Standards, with some select exclusions.
PHPCompatibilityWPruleset which checks code for PHP cross-version compatibility while preventing false positives for functionality polyfilled within WordPress.
- Select additional sniffs taken from
- A number of custom Yoast specific sniffs.
Files within version management and dependency related directories, such as the Composer
vendor directory, are excluded from the scans by default.
To obtain a list of all sniffs used within YoastCS:
"vendor/bin/phpcs" -e --standard=Yoast
Not all sniffs have documentation available about what they sniff for, but for those which do, this documentation can be viewed from the command-line:
"vendor/bin/phpcs" --standard=Yoast --generator=text
Running the sniffs
"vendor/bin/phpcs" --extensions=php /path/to/folder/
For more command-line options, please have a read through the PHP_CodeSniffer documentation.
Yoast plugin repositories
All Yoast plugin repositories contain a
[.]phpcs.xml.dist file contain the repository specific configuration.
From the root of these repositories, you can run PHPCS by using:
Refer to Using PHP Code Sniffer Tool in the PhpStorm documentation.
After installation, the
Yoast standard will be available as a choice in PHP Code Sniffer Validation inspection.
The changelog for this package can be found in the CHANGELOG.md file.