2017 © Pedro Peláez
 

phpcodesniffer-standard yoastcs

PHP_CodeSniffer rules for Yoast projects

image

yoast/yoastcs

PHP_CodeSniffer rules for Yoast projects

  • Tuesday, July 31, 2018
  • by omarreiss
  • Repository
  • 16 Watchers
  • 12 Stars
  • 24,460 Installations
  • PHP
  • 12 Dependents
  • 0 Suggesters
  • 4 Forks
  • 9 Open issues
  • 33 Versions
  • 10 % Grown

The README.md

Yoast Coding Standards

Coverage Status, (*1)

Yoast Coding Standards (YoastCS) is a project with rulesets for code style and quality tools to be used in Yoast projects., (*2)

Installation

Standalone

Standards are provided as a Composer package and can be installed with:, (*3)

composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev yoast/yoastcs:"^3.0"

As dependency

To include standards as part of a project require them as development dependencies:, (*4)

composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --dev yoast/yoastcs:"^3.0"

Composer will automatically install dependencies and register YoastCS and other external standards with PHP_CodeSniffer., (*5)

Tools provided via YoastCS

  • PHP Parallel Lint
  • PHP_CodeSniffer and select standards for PHP_CodeSniffer, including a number of Yoast native sniffs.

PHP Parallel Lint

PHP Parallel Lint is a tool to lint PHP files against parse errors., (*6)

PHP Parallel Lint does not use a configuration file, so command-line options need to be passed to configure what files to scan., (*7)

It is best practice within the Yoast projects, to add a script to the composer.json file which encapsules the command with the appropriate command-line options to ensure that running the tool will yield the same results each time., (*8)

Typically, (a variation on) the following snippet would be added to the composer.json file for a project:, (*9)

    "scripts" : {
        "lint": [
            "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git"
        ]
    }

PHP Code Sniffer

Set of PHP_CodeSniffer rules., (*10)

Severity levels:, (*11)

  • 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

The Yoast standard for PHP_CodeSniffer is comprised of the following: * The WordPress ruleset from the WordPress Coding Standards implementing the official WordPress PHP Coding Standards, with some select exclusions. * The PHPCompatibilityWP ruleset which checks code for PHP cross-version compatibility while preventing false positives for functionality polyfilled within WordPress. * The VariableAnalysis ruleset. * Select additional sniffs taken from PHP_CodeSniffer. * Select additional sniffs taken from PHPCSExtra. * Select additional sniffs taken from SlevomatCodingStandard. * Select additional sniffs taken from WordPress VIP Coding Standards. * A number of custom Yoast specific sniffs., (*12)

Files within version management and dependency related directories, such as the Composer vendor directory, are excluded from the scans by default., (*13)

Sniffs

To obtain a list of all sniffs used within YoastCS:, (*14)

"vendor/bin/phpcs" -e --standard=Yoast

Sniff Documentation

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:, (*15)

"vendor/bin/phpcs" --standard=Yoast --generator=Text

Running the sniffs

Command line

"vendor/bin/phpcs" --extensions=php /path/to/folder/

For more command-line options, please have a read through the PHP_CodeSniffer documentation., (*16)

Yoast plugin repositories

All Yoast plugin repositories contain a [.]phpcs.xml.dist file which contains the repository specific configuration., (*17)

From the root of these repositories, you can run PHPCS by using:, (*18)

composer check-cs-warnings

PhpStorm

Refer to Using PHP Code Sniffer Tool in the PhpStorm documentation., (*19)

After installation, the Yoast standard will be available as a choice in PHP Code Sniffer Validation inspection., (*20)

The YoastCS "Threshold" report

The YoastCS package includes a custom YoastCS\Yoast\Reports\Threshold report for PHP_CodeSniffer to compare the current PHPCS run results with predefined "threshold" settings., (*21)

The report will look in the runtime environment for the following two environment variables and will take the values of those as the thresholds to compare the PHPCS run results against: * YOASTCS_THRESHOLD_ERRORS * YOASTCS_THRESHOLD_WARNINGS, (*22)

If the environment variables are not set, they will default to 0 for both, i.e. no errors or warnings allowed., (*23)

The report will not print any details about the issues found, it just shows a summary based on the thresholds:, (*24)

PHP CODE SNIFFER THRESHOLD COMPARISON
------------------------------------------------------------------------------------------------------------------------
Coding standards ERRORS: 148/130.
Coding standards WARNINGS: 539/539.

Please fix any errors introduced in your code and run PHPCS again to verify.
Please fix any warnings introduced in your code and run PHPCS again to verify.

After the report has run, a global YOASTCS_ABOVE_THRESHOLD constant (boolean) will be available which can be used in calling scripts., (*25)

To use this report, run PHPCS with the following command-line argument: --report=YoastCS\Yoast\Reports\Threshold. Note: depending on the OS the command is run on, the backslashes in the report name may need to be escaped (doubled)., (*26)

For those Yoast plugin repositories which use thresholds, the status can be checked locally by running:, (*27)

composer check-cs-thresholds

Changelog

The changelog for this package can be found in the CHANGELOG.md file., (*28)

The Versions

31/07 2018

dev-JRF/WIP/sniff-check-placement-testdoubles

dev-JRF/WIP/sniff-check-placement-testdoubles

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

30/07 2018
30/07 2018

dev-JRF/add-function-close-sniff

dev-JRF/add-function-close-sniff

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

30/07 2018

dev-74-introduce-required-parameters-sniff

dev-74-introduce-required-parameters-sniff

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

30/07 2018

dev-JRF/dont-allow-warnings

dev-JRF/dont-allow-warnings

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

30/07 2018

dev-JRF/add-functionspacing-sniff

dev-JRF/add-functionspacing-sniff

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

26/07 2018

dev-JRF/update-for-new-releases-phpcompatibility-wpcs

dev-JRF/update-for-new-releases-phpcompatibility-wpcs

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

26/07 2018

dev-JRF/yoastcs-native-ruleset-phpcs-3.3.0-adjustment

dev-JRF/yoastcs-native-ruleset-phpcs-3.3.0-adjustment

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

26/07 2018

dev-JRF/remove-end-comments

dev-JRF/remove-end-comments

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

16/05 2018

dev-JRF/composer-add-explanation-to-suggest

dev-JRF/composer-add-explanation-to-suggest

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

04/04 2018

dev-74-introduce-optional-parameters-sniff

dev-74-introduce-optional-parameters-sniff

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

19/03 2018

dev-master

9999999-dev

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

The Development Requires

wordpress phpcs standards yoast

25/01 2018

0.5

0.5.0.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards yoast

22/01 2018

dev-JRF/improve-ifelse-sniff

dev-JRF/improve-ifelse-sniff

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards yoast

30/11 2017

dev-JRF/update-to-wpcs-0.14.0

dev-JRF/update-to-wpcs-0.14.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards yoast

30/11 2017

dev-JRF/phpcompatibility-allow-for-wp-backfills

dev-JRF/phpcompatibility-allow-for-wp-backfills

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards yoast

30/11 2017

dev-JRF/add-checking-for-codestyle

dev-JRF/add-checking-for-codestyle

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards yoast

18/08 2017

dev-JRF/no-tests-in-production

dev-JRF/no-tests-in-production

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards yoast

16/08 2017

dev-JRF/update-for-WPCS-0.11.0

dev-JRF/update-for-WPCS-0.11.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

16/08 2017

dev-stories/JM/check-vip-function-exclusions

dev-stories/JM/check-vip-function-exclusions

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

02/08 2017

0.4.3

0.4.3.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

12/06 2017

dev-exclude-url-to-postid

dev-exclude-url-to-postid

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

23/03 2017

dev-WAIT-0.11.0/JRF/update-for-WPCS0.11.0

dev-WAIT-0.11.0/JRF/update-for-WPCS0.11.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

22/03 2017

dev-JRF/add-some-more-VIP-exclusions

dev-JRF/add-some-more-VIP-exclusions

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

22/03 2017

dev-JRF/maintain-existing-exclusion

dev-JRF/maintain-existing-exclusion

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

22/03 2017

dev-JRF/exclude-syntax-sniff

dev-JRF/exclude-syntax-sniff

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

22/03 2017

0.4.2

0.4.2.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

21/03 2017

dev-feature/re-enable-phpcompatibility

dev-feature/re-enable-phpcompatibility

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

21/03 2017

0.4.1

0.4.1.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

06/09 2016

0.4

0.4.0.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

03/05 2016

0.3

0.3.0.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

01/04 2016

0.2

0.2.0.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards

08/01 2016

0.1

0.1.0.0

PHP_CodeSniffer rules for Yoast projects

  Sources   Download

MIT

The Requires

 

wordpress phpcs standards