yutahaga/wpcs-psr2

PHP_CodeSniffer ruleset to enforce WordPress & PSR-2 coding conventions

Installs: 29

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:phpcodesniffer-standard

v1.0.3 2019-03-22 11:36 UTC

This package is auto-updated.

Last update: 2024-04-22 23:05:20 UTC


README

PHP_CodeSniffer ruleset to enforce WordPress & PSR-2 coding conventions

Introduction

A rule set that combines WordPress Coding Standards and PSR-2. The goal is to reduce the stress on developers by reducing the differences in coding conventions with other PHP applications.

Installation

Automatic install

Add the following scripts in composer.json

{
  "scripts": {
    "install-codestandards": ["Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"],
    "post-install-cmd": ["@install-codestandards"]
  }
}
composer require --dev dealerdirect/phpcodesniffer-composer-installer
composer require --dev yutahaga/wpcs-psr2

Manually install

composer require --dev yutahaga/wpcs-psr2
phpcs --config-set installed_paths ./vendor/yutahaga/wpcs-psr2,./vendor/wp-coding-standards/wpcs,other-ruleset

Usage

Here is an example of the phpcs.xml

<?xml version="1.0"?>
<ruleset name="My Coding Standards">
  <description>My Coding Standards extends WordPress-Extra and PSR-2</description>

  <rule ref="WordPress-PSR2" />

  <file>./app</file>
  <file>./bootstrap</file>
  <file>./config</file>
  <file>./functions.php</file>

  <exclude-pattern>bootstrap/cache/*.php</exclude-pattern>
  <exclude-pattern>*/*.js</exclude-pattern>
  <exclude-pattern>*/*.css</exclude-pattern>
  <exclude-pattern>*/*.xml</exclude-pattern>
  <exclude-pattern>*/node_modules/*</exclude-pattern>
  <exclude-pattern>*/vendor/*</exclude-pattern>
</ruleset>