From 9505f49f69ae05e04e6b9940cd1bed99b03173e9 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Mon, 5 Jun 2017 09:56:03 -0400 Subject: [PATCH 1/9] Add composer to manage phpcs and wpcs --- composer.json | 6 +++ composer.lock | 132 ++++++++++++++++++++++++++++++++++++++++++++++ vendor/.gitignore | 3 +- 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 composer.json create mode 100644 composer.lock diff --git a/composer.json b/composer.json new file mode 100644 index 0000000000000..6c142a90b7d37 --- /dev/null +++ b/composer.json @@ -0,0 +1,6 @@ +{ + "require-dev": { + "squizlabs/php_codesniffer": "2.9.x", + "wp-coding-standards/wpcs": "^0.11.0" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000000000..1739cdc97a899 --- /dev/null +++ b/composer.lock @@ -0,0 +1,132 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "1a5dd686e18346fa4dbc564b7b90f4a1", + "packages": [], + "packages-dev": [ + { + "name": "squizlabs/php_codesniffer", + "version": "2.9.1", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62", + "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "bin": [ + "scripts/phpcs", + "scripts/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "classmap": [ + "CodeSniffer.php", + "CodeSniffer/CLI.php", + "CodeSniffer/Exception.php", + "CodeSniffer/File.php", + "CodeSniffer/Fixer.php", + "CodeSniffer/Report.php", + "CodeSniffer/Reporting.php", + "CodeSniffer/Sniff.php", + "CodeSniffer/Tokens.php", + "CodeSniffer/Reports/", + "CodeSniffer/Tokenizers/", + "CodeSniffer/DocGenerators/", + "CodeSniffer/Standards/AbstractPatternSniff.php", + "CodeSniffer/Standards/AbstractScopeSniff.php", + "CodeSniffer/Standards/AbstractVariableSniff.php", + "CodeSniffer/Standards/IncorrectPatternException.php", + "CodeSniffer/Standards/Generic/Sniffs/", + "CodeSniffer/Standards/MySource/Sniffs/", + "CodeSniffer/Standards/PEAR/Sniffs/", + "CodeSniffer/Standards/PSR1/Sniffs/", + "CodeSniffer/Standards/PSR2/Sniffs/", + "CodeSniffer/Standards/Squiz/Sniffs/", + "CodeSniffer/Standards/Zend/Sniffs/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2017-05-22T02:43:20+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "0.11.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", + "reference": "407e4b85f547a5251185f89ceae6599917343388" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/407e4b85f547a5251185f89ceae6599917343388", + "reference": "407e4b85f547a5251185f89ceae6599917343388", + "shasum": "" + }, + "require": { + "squizlabs/php_codesniffer": "^2.8.1" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "time": "2017-03-20T23:17:58+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/vendor/.gitignore b/vendor/.gitignore index a6c7c2852d068..d6b7ef32c8478 100644 --- a/vendor/.gitignore +++ b/vendor/.gitignore @@ -1 +1,2 @@ -*.js +* +!.gitignore From e4532adb03644471b42e9a8c079cbc6a300be019 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Mon, 5 Jun 2017 10:05:19 -0400 Subject: [PATCH 2/9] Update docs for composer --- docs/coding-guidelines.md | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/docs/coding-guidelines.md b/docs/coding-guidelines.md index d52c747d43c04..1bea976f2335f 100644 --- a/docs/coding-guidelines.md +++ b/docs/coding-guidelines.md @@ -92,28 +92,17 @@ When making any changes to the PHP code in this project, it's recommended to install and run `phpcs` on your computer. This is a step in our Travis CI build as well, but it is better to catch errors locally. -You will need to install `phpcs` version 2.9.x, because the 3.x versions are -not yet compatible with the WordPress coding standards. For more information see -[this issue](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/718). +The easiest way to do this is using `composer`. +[Install `composer`](https://getcomposer.org/download/) +on your computer, then run `composer install`. This will install `phpcs` and +`WordPress-Coding-Standards`. -The easiest way to get `phpcs` is to download the .phar archive from the latest -2.9.x release on GitHub: -[PHP\_CodeSniffer releases](https://github.com/squizlabs/PHP_CodeSniffer/releases). - -For example: +You need to tell `phpcs` where to find the WordPress coding standards rulesets. +You can do that using the following command: ```sh -wget \ - https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.9.1/phpcs.phar \ - -O ~/bin/phpcs -chmod +x ~/bin/phpcs +vendor/bin/phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs/ ``` -(If `~/bin` is not in your `$PATH`, pick another directory that is.) - -Then you must install the `WordPress-Coding-Standards` repository and tell -`phpcs` where it lives. See instructions here: - -https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#standalone - -You should now be able to run `phpcs` from the root directory of this project. +You should now be able to run `vendor/bin/phpcs` from the root directory of +this project. From b5a9e0d64aa9aa796aae393f684159e7ffdf1fea Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 5 Jun 2017 14:20:05 -0700 Subject: [PATCH 3/9] Install wpcs to phpcs via composer post-install-cmd --- composer.json | 7 ++++++- docs/coding-guidelines.md | 12 +----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 6c142a90b7d37..7c97f7d3a73bc 100644 --- a/composer.json +++ b/composer.json @@ -2,5 +2,10 @@ "require-dev": { "squizlabs/php_codesniffer": "2.9.x", "wp-coding-standards/wpcs": "^0.11.0" - } + }, + "scripts": { + "post-install-cmd": [ + "phpcs --config-set installed_paths ../../wp-coding-standards/wpcs/" + ] + } } diff --git a/docs/coding-guidelines.md b/docs/coding-guidelines.md index 1bea976f2335f..3bc74b444c4ce 100644 --- a/docs/coding-guidelines.md +++ b/docs/coding-guidelines.md @@ -95,14 +95,4 @@ build as well, but it is better to catch errors locally. The easiest way to do this is using `composer`. [Install `composer`](https://getcomposer.org/download/) on your computer, then run `composer install`. This will install `phpcs` and -`WordPress-Coding-Standards`. - -You need to tell `phpcs` where to find the WordPress coding standards rulesets. -You can do that using the following command: - -```sh -vendor/bin/phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs/ -``` - -You should now be able to run `vendor/bin/phpcs` from the root directory of -this project. +`WordPress-Coding-Standards` which you can the run via `vendor/bin/phpcs`. From 0f266abf8f2d1e138514e69d6b17ce99e12e38e6 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 5 Jun 2017 14:22:42 -0700 Subject: [PATCH 4/9] Remove redundant composer phpcs/wpcs installation --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index dae3085e5b875..9e2a015fa936c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,11 +42,6 @@ before_script: composer global require "phpunit/phpunit=5.7.*" fi fi - - | - if [[ "$TRAVISCI" == "phpcs" ]] ; then - composer global require wp-coding-standards/wpcs - phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs - fi script: - | From be4a654e91c570c2601f9a5214cd664d5c799f4a Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 5 Jun 2017 14:25:51 -0700 Subject: [PATCH 5/9] Add composer.json to .editorconfig and clean indentation --- .editorconfig | 2 +- composer.json | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.editorconfig b/.editorconfig index 17c30a62d6a66..2541971893d69 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,7 +8,7 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[{package.json,.travis.yml}] +[{package.json,.travis.yml,composer.json}] indent_style = space indent_size = 2 diff --git a/composer.json b/composer.json index 7c97f7d3a73bc..6634332cbd38b 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,11 @@ { - "require-dev": { - "squizlabs/php_codesniffer": "2.9.x", - "wp-coding-standards/wpcs": "^0.11.0" - }, - "scripts": { - "post-install-cmd": [ - "phpcs --config-set installed_paths ../../wp-coding-standards/wpcs/" - ] - } + "require-dev": { + "squizlabs/php_codesniffer": "2.9.x", + "wp-coding-standards/wpcs": "^0.11.0" + }, + "scripts": { + "post-install-cmd": [ + "phpcs --config-set installed_paths ../../wp-coding-standards/wpcs/" + ] + } } From 592a0a80c28da8d2ab42f20247e94de4d574e068 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 5 Jun 2017 14:28:57 -0700 Subject: [PATCH 6/9] Use composer-installed phpcs in Travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9e2a015fa936c..aa5e9bc46dda1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,7 +53,7 @@ script: fi - | if [[ "$TRAVISCI" == "phpcs" ]] ; then - phpcs + ./vendor/bin/phpcs fi - | if [[ "$TRAVISCI" == "js" ]] ; then From 424ffafc327f4aad4c7b61f68b41da8bf67b7423 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 5 Jun 2017 14:31:28 -0700 Subject: [PATCH 7/9] Add missing composer install --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index aa5e9bc46dda1..720ca5e853edc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,7 @@ before_script: composer global require "phpunit/phpunit=5.7.*" fi fi + - composer install script: - | From a219225ae0843d683b70b90c3e77e1d5d36ae04a Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 5 Jun 2017 14:37:49 -0700 Subject: [PATCH 8/9] Only composer install if needing phpcs since not available on PHP 5.3 --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 720ca5e853edc..ed39d172b4c0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,10 @@ before_script: composer global require "phpunit/phpunit=5.7.*" fi fi - - composer install + - | + if [[ "$TRAVISCI" == "phpcs" ]] ; then + composer install + fi script: - | From 35f027feed61574b8a9c67e273230b7d4ff59b66 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 5 Jun 2017 17:39:34 -0700 Subject: [PATCH 9/9] Update .editorconfig to apply 2-space indents to all JSON and YML files --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 2541971893d69..446a47c3b3982 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,7 +8,7 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[{package.json,.travis.yml,composer.json}] +[{*.json,*.yml}] indent_style = space indent_size = 2