From 0b019f9160427098ab30f49d922cef74f26e48a6 Mon Sep 17 00:00:00 2001 From: Nick Wilde Date: Fri, 14 Sep 2018 18:42:26 -0700 Subject: [PATCH] Allow standard to be selected in composer.json --- .gitignore | 1 + README.md | 14 +++++++++++--- src/Sniffer.php | 8 +++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 57872d0..cac762f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /vendor/ +/.idea/ diff --git a/README.md b/README.md index 70b3c02..0e5021e 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,17 @@ It should just work when you `git commit`. ## Internals -By default, of the 5 different WordPress coding standards (`WordPress-VIP`, `WordPress`, `WordPress-Extra`, `WordPress-Docs` and `WordPress-Core`), this one uses the `WordPress-Extra` one. - -If you need to change it, currently you need to edit the Sniff file. Contributions on how to make this dynamic are welcome (`.env` file, different sniffs for each and choosing the appropriate hooks). +WPCS provides 5 different coding standards (`WordPress-VIP`, `WordPress`, +`WordPress-Extra`, `WordPress-Docs` and `WordPress-Core`). By default this uses +`WordPress-Extra`. If you want to use another one of the standards, you can +specify it in your project's composer.json's `extra` key: + ```json + "extra": { + "php-composter-phpcs-wpcs": { + "standard": "WordPress-VIP" + } + } +``` ## Contributing diff --git a/src/Sniffer.php b/src/Sniffer.php index ab6e30f..9a0ab02 100644 --- a/src/Sniffer.php +++ b/src/Sniffer.php @@ -39,9 +39,15 @@ public function preCommit() echo 'Running PHP CodeSniffer in ' . $this->root . PHP_EOL; $sniffer = new PHP_CodeSniffer_CLI(); + @$config = $this->getExtraKey('php-composter-phpcs-wpcs', [ + 'standard' => 'WordPress-Extra' + ]); ob_start(); - $numErrors = $sniffer->process(array('standard' => 'WordPress-Extra', 'files' => $files)); + $numErrors = $sniffer->process([ + 'standard' => $config['standard'], + 'files' => $files + ]); $output = ob_get_clean(); echo $output . PHP_EOL;