From 4631e0e55fbe349421a90ff35a2cd4faeda04a2f Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Tue, 13 Aug 2024 21:13:20 +0300 Subject: [PATCH 1/7] #108 Add phpcs-docker binary to be used in IDE's. --- bin/phpcs-docker | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 bin/phpcs-docker diff --git a/bin/phpcs-docker b/bin/phpcs-docker new file mode 100755 index 0000000..2ad229f --- /dev/null +++ b/bin/phpcs-docker @@ -0,0 +1,13 @@ +#!/bin/bash + +# Run PHP_CodeSniffer inside Docker container using the PHP 8.2 CLI image. +# The container will automatically be removed after execution (--rm). +# Mount the current working directory ($(pwd)) to the /app directory inside +# the container (-v $(pwd):/app). +# Set the working directory inside the container to /app (-w /app). +# Execute the PHP CodeSniffer command (./vendor/bin/phpcs) with the WunderAll +# standard inside the container. +# Pass any additional arguments ($*) from the script to the phpcs command. + +# @todo add "--rm" between -i and -v to remove the container after execution? Without rm it seems a bit faster when benchmarking. +docker run -i -v $(pwd):/app -w /app php:8.2-cli ./vendor/bin/phpcs --standard=WunderAll $* From 58f56e5c89741fc1a2494b190044c732794d6299 Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Tue, 13 Aug 2024 21:30:45 +0300 Subject: [PATCH 2/7] #108 Install phpcs-docker under bin. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4e9a9c3..484321f 100755 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "email": "pasi.kauraniemi@wunder.io" } ], - "bin": ["bin/check_perms"], + "bin": ["bin/check_perms", "bin/phpcs-docker"], "require": { "symfony/polyfill-iconv": "^1", "phpro/grumphp": "^2.5", From 5c82c23d9cc4bed6662a120cb4306026019dfcad Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Wed, 14 Aug 2024 10:48:00 +0300 Subject: [PATCH 3/7] #108 Finalize working setup, add initial readme. --- README.md | 16 ++++++++++++++++ composer.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a1d11e..3ab0330 100755 --- a/README.md +++ b/README.md @@ -106,3 +106,19 @@ You can easily use the code quality checkers on your CI (CircleCi/Jenkins/GitLab ``` ./vendor/bin/grumphp run --no-ansi --no-interaction ``` + +## IDE Integration + +To use PHPCS from your IDE, you can point it to the following script: + +``` +vendor/wunderio/code-quality/bin/phpcs-docker +``` + +This script runs PHP_CodeSniffer inside a Docker container using the PHP 8.2 +CLI image. It mounts the current working directory to the /app directory inside +the container and executes the PHPCS command with the WunderAll standard. + +For Visual Studio Code you'd also need this plugin +https://marketplace.visualstudio.com/items?itemName=shevaua.phpcs + diff --git a/composer.json b/composer.json index 484321f..4e9a9c3 100755 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "email": "pasi.kauraniemi@wunder.io" } ], - "bin": ["bin/check_perms", "bin/phpcs-docker"], + "bin": ["bin/check_perms"], "require": { "symfony/polyfill-iconv": "^1", "phpro/grumphp": "^2.5", From 6ac3b1bc3537eb32baf20ece0432d02bfaf880e2 Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Wed, 14 Aug 2024 16:14:46 +0300 Subject: [PATCH 4/7] #108 Update readme for IDE integration. --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++-------- bin/phpcs-docker | 13 ------------- 2 files changed, 42 insertions(+), 21 deletions(-) delete mode 100755 bin/phpcs-docker diff --git a/README.md b/README.md index 3ab0330..73093e3 100755 --- a/README.md +++ b/README.md @@ -107,18 +107,52 @@ You can easily use the code quality checkers on your CI (CircleCi/Jenkins/GitLab ./vendor/bin/grumphp run --no-ansi --no-interaction ``` -## IDE Integration +## IDE Integration (optional) -To use PHPCS from your IDE, you can point it to the following script: +### Prerequisites +#### Ubuntu +To install the necessary PHP components without Apache: ``` -vendor/wunderio/code-quality/bin/phpcs-docker +sudo apt install php-cli php-tokenizer ``` -This script runs PHP_CodeSniffer inside a Docker container using the PHP 8.2 -CLI image. It mounts the current working directory to the /app directory inside -the container and executes the PHPCS command with the WunderAll standard. +#### macOS +[Placeholder for macOS installation instructions] -For Visual Studio Code you'd also need this plugin -https://marketplace.visualstudio.com/items?itemName=shevaua.phpcs +### Configuration + +#### Visual Studio Code + +1. Install the [Drupal extension](https://marketplace.visualstudio.com/items?itemName=Stanislav.vscode-drupal). +2. Open the Drupal extension configuration. +3. Find "Drupal > Phpcs: Args" and "Drupal > Phpcbf: Args". +4. Click "Edit in settings.json" and add: + +```json +{ + "drupal.phpcs.args": [ + "--standard=WunderAll" + ], + "drupal.phpcbf.args": [ + "--standard=WunderAll" + ] +} +``` + +PHPCS usage Example in Visual Studio Code: +![PHPCS Usage Example in VSC](https://user-images.githubusercontent.com/11972062/221161739-cabcd4b5-800d-4d5b-8071-9324bf2bcc08.gif) + +#### PhpStorm + +Open settings and look for PHP_Codesniffer. Make sure these settings are the same: +![PhpStorm settings PHPCS 1/2](https://www.upload.ee/image/16969201/2024-08-14_15-59.png) + +Check the paths and validate: +![PhpStorm settings PHPCS 2/2](https://www.upload.ee/image/16969203/2024-08-14_16-01.png) + +Warnings are underlined and you can choose to fix them by right clicking: +![How to fix 1/2](https://www.upload.ee/image/16969207/2024-08-14_16-03.png) +Choose the "PHP Code Beautifier and Fixer: fix the whole file" +![How to fix 2/2](https://www.upload.ee/image/16969210/2024-08-14_16-04.png) \ No newline at end of file diff --git a/bin/phpcs-docker b/bin/phpcs-docker deleted file mode 100755 index 2ad229f..0000000 --- a/bin/phpcs-docker +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Run PHP_CodeSniffer inside Docker container using the PHP 8.2 CLI image. -# The container will automatically be removed after execution (--rm). -# Mount the current working directory ($(pwd)) to the /app directory inside -# the container (-v $(pwd):/app). -# Set the working directory inside the container to /app (-w /app). -# Execute the PHP CodeSniffer command (./vendor/bin/phpcs) with the WunderAll -# standard inside the container. -# Pass any additional arguments ($*) from the script to the phpcs command. - -# @todo add "--rm" between -i and -v to remove the container after execution? Without rm it seems a bit faster when benchmarking. -docker run -i -v $(pwd):/app -w /app php:8.2-cli ./vendor/bin/phpcs --standard=WunderAll $* From e858e7aaee35994473bb38951065061377218d7d Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Thu, 15 Aug 2024 16:53:09 +0300 Subject: [PATCH 5/7] #108 Update README.md - add phpcs IDE instructions for macOS --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73093e3..4e8e95e 100755 --- a/README.md +++ b/README.md @@ -118,7 +118,11 @@ sudo apt install php-cli php-tokenizer ``` #### macOS -[Placeholder for macOS installation instructions] +1. Install Homebrew if you don't have it installed already (see instructions on https://brew.sh/) +2. Install PHP with Homebrew +``` +brew install php +``` ### Configuration @@ -155,4 +159,4 @@ Warnings are underlined and you can choose to fix them by right clicking: ![How to fix 1/2](https://www.upload.ee/image/16969207/2024-08-14_16-03.png) Choose the "PHP Code Beautifier and Fixer: fix the whole file" -![How to fix 2/2](https://www.upload.ee/image/16969210/2024-08-14_16-04.png) \ No newline at end of file +![How to fix 2/2](https://www.upload.ee/image/16969210/2024-08-14_16-04.png) From 51967f510d05b7c2ba0c277c25ca1d1818d776ca Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Mon, 19 Aug 2024 08:09:09 +0300 Subject: [PATCH 6/7] Update README.md Minimal version requirement for IDE setup added for Code Quality. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4e8e95e..b4c469f 100755 --- a/README.md +++ b/README.md @@ -111,6 +111,8 @@ You can easily use the code quality checkers on your CI (CircleCi/Jenkins/GitLab ### Prerequisites +Minimally [Qude Quality 2.2.1](https://github.com/wunderio/code-quality/releases/tag/2.2.1) is needed because it contains the WunderAll ruleset that groups all Wunder rulesets. + #### Ubuntu To install the necessary PHP components without Apache: ``` From ad3b9a56d5ff46c10e94e1ab5d3fb7e86004d8a4 Mon Sep 17 00:00:00 2001 From: Hannes Kirsman Date: Mon, 19 Aug 2024 08:10:30 +0300 Subject: [PATCH 7/7] #108 Update README.md Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b4c469f..d76da99 100755 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ You can easily use the code quality checkers on your CI (CircleCi/Jenkins/GitLab ### Prerequisites -Minimally [Qude Quality 2.2.1](https://github.com/wunderio/code-quality/releases/tag/2.2.1) is needed because it contains the WunderAll ruleset that groups all Wunder rulesets. +Minimally [Code Quality 2.2.1](https://github.com/wunderio/code-quality/releases/tag/2.2.1) is needed because it contains the WunderAll ruleset that groups all Wunder rulesets. #### Ubuntu To install the necessary PHP components without Apache: