talira

WordPress Coding Standards for PHP_CodeSniffer

PHP_CodeSniffer rules that enforce WordPress coding conventions

open sourceMITfree

WordPress Coding Standards (WordPressCS) is a collection of PHP_CodeSniffer rules (sniffs) that check code written for WordPress against its official coding conventions. It ships the WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra standards to pick from with phpcs's --standard option or a custom ruleset, many configurable sniffs, and sniffs from PHPCSExtra and PHP_CodeSniffer itself. Since version 3.0 it's installed only with Composer.

Problems it solves

  • check my WordPress plugin's PHP against the WordPress coding standards
  • lint a WordPress theme in CI with phpcs
  • enforce WordPress code style in my editor

Features

  • WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra standards
  • configurable sniff properties
  • includes sniffs from PHPCSExtra and PHP_CodeSniffer
  • runs in CI and in editors through phpcs

Limitations

  • Needs PHP 7.2 or newer with the Filter, libxml, Tokenizer and XMLReader extensions.1
  • Since version 3.0, installing with Composer is the only supported way.1

Alternatives

The same job

These do what WordPress Coding Standards for PHP_CodeSniffer does.

  1. PHPCompatibilityWP PHPCompatibility ruleset for WordPress projects that skips WordPress's own polyfills
  2. PHP_CodeSniffer Standards Composer Installer Plugin Composer plugin that registers installed PHP_CodeSniffer coding standards automatically
  3. Stylelint A CSS linter that catches errors and enforces conventions in your stylesheets
  4. PHP_CodeSniffer Detect and fix coding standard violations in PHP
  5. PHPCompatibility PHP_CodeSniffer sniffs that check PHP code for cross-version compatibility
  6. Easy Coding Standard (ECS) Runs PHP_CodeSniffer and PHP-CS-Fixer rules together, fast

Compare WordPress Coding Standards for PHP_CodeSniffer with the top 3