From 1a7933b07eed53b3125ca847e4c0e67820530831 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 24 Jan 2023 15:39:28 +0000 Subject: [PATCH 1/4] Composer: Update script names Better align with suggested script names at https://github.com/php-pds/composer-script-names --- .github/CONTRIBUTING.md | 10 +++++----- .github/workflows/basics.yml | 2 +- composer.json | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index f652edc9..60474ba7 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -34,11 +34,11 @@ This package contains Composer scripts to quickly run the developer checks which After `composer install`, you can do: - - `composer test`: **Run all checks and tests** - this should pass cleanly before you submit a pull request. + - `composer check`: **Run all checks and tests** - this should pass cleanly before you submit a pull request. - `composer lint`: Just run PHP and XML linters. - - `composer phpcs`: Just run PHPCS against this package. - - `composer phpunit`: Just run the unit tests. - - `composer ruleset`: Just run the ruleset tests. + - `composer cs`: Just run PHPCS against this package. + - `composer test`: Just run the unit tests. + - `composer test-ruleset`: Just run the ruleset tests. ## Branches @@ -190,7 +190,7 @@ The ruleset tests, previously named here as _integration tests_, are our way of An example where it might not would be when a ruleset references a local sniff or a sniff from upstream (WPCS or PHPCS), but that the violation code, sniff name or category name has changed. Without a ruleset test, this would go unnoticed. -The `composer test` or `composer ruleset` commands run the `ruleset-test.php` files (one for each standard), which internally run `phpcs` against the "dirty" test files (`ruleset-test.inc`), and looks out for a known number of errors, warnings, and messages on each line. This is then compared against the expected errors, warnings and messages to see if there are any missing or unexpected violations or difference in messages. +The `composer check` or `composer test-ruleset` commands run the `ruleset-test.php` files (one for each standard), which internally run `phpcs` against the "dirty" test files (`ruleset-test.inc`), and looks out for a known number of errors, warnings, and messages on each line. This is then compared against the expected errors, warnings and messages to see if there are any missing or unexpected violations or difference in messages. When adding or changing a sniff, the ruleset test files should be updated to match. diff --git a/.github/workflows/basics.yml b/.github/workflows/basics.yml index 6c20a10d..6dbeb9a2 100644 --- a/.github/workflows/basics.yml +++ b/.github/workflows/basics.yml @@ -74,4 +74,4 @@ jobs: # For now, just check that all sniffs have unit tests. # At a later stage the documentation check can be activated. - name: Check sniff feature completeness - run: composer check-complete + run: composer feature-completeness diff --git a/composer.json b/composer.json index 87c1f5e9..ab18ae2a 100644 --- a/composer.json +++ b/composer.json @@ -36,23 +36,23 @@ }, "scripts": { "install-codestandards": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run", - "ruleset": "bin/ruleset-tests", + "test-ruleset": "bin/ruleset-tests", "lint": [ "bin/php-lint", "bin/xml-lint" ], - "phpcs": "bin/phpcs", - "phpunit": "bin/unit-tests", - "coverage": "bin/unit-tests-coverage", - "check-complete": [ + "cs": "bin/phpcs", + "test": "bin/unit-tests", + "test-coverage": "bin/unit-tests-coverage", + "feature-completeness": [ "@php ./vendor/phpcsstandards/phpcsdevtools/bin/phpcs-check-feature-completeness -q ./WordPressVIPMinimum" ], - "test": [ + "check": [ "@lint", - "@ruleset", - "@phpunit", - "@phpcs", - "@check-complete" + "@tests-ruleset", + "@tests", + "@cs", + "@feature-completeness" ] }, "support": { From f3c3611b7272c9040058d725b894363f7e2c06d2 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 24 Jan 2023 15:47:24 +0000 Subject: [PATCH 2/4] Composer: Add script descriptions These appear when calling `composer list`. --- .github/CONTRIBUTING.md | 12 +++++++----- composer.json | 9 +++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 60474ba7..42e7700b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -34,11 +34,13 @@ This package contains Composer scripts to quickly run the developer checks which After `composer install`, you can do: - - `composer check`: **Run all checks and tests** - this should pass cleanly before you submit a pull request. - - `composer lint`: Just run PHP and XML linters. - - `composer cs`: Just run PHPCS against this package. - - `composer test`: Just run the unit tests. - - `composer test-ruleset`: Just run the ruleset tests. +- `composer lint`: Lint PHP and XML files in against parse errors. +- `composer cs`: Check the code style and code quality of the codebase via PHPCS. +- `composer test`: Run the unit tests for the VIPCS sniffs. +- `composer test-coverage`: Run the unit tests for the VIPCS sniffs with coverage enabled. +- `composer test-ruleset`: Run the ruleset tests for the VIPCS sniffs. +- `composer feature-completeness`: Check if all the VIPCS sniffs have tests. +- `composer check`: Run all checks (lint, CS, feature completeness) and tests - this should pass cleanly before you submit a pull request. ## Branches diff --git a/composer.json b/composer.json index ab18ae2a..adaa775f 100644 --- a/composer.json +++ b/composer.json @@ -55,6 +55,15 @@ "@feature-completeness" ] }, + "scripts-descriptions": { + "lint": "VIPCS: Lint PHP and XML files in against parse errors.", + "cs": "VIPCS: Check the code style and code quality of the codebase via PHPCS.", + "test": "VIPCS: Run the unit tests for the VIPCS sniffs.", + "test-coverage": "VIPCS: Run the unit tests for the VIPCS sniffs with coverage enabled.", + "test-ruleset": "VIPCS: Run the ruleset tests for the VIPCS sniffs.", + "feature-completeness": "VIPCS: Check if all the VIPCS sniffs have tests.", + "check": "VIPCS: Run all checks (lint, CS, feature completeness) and tests." + }, "support": { "issues": "https://github.com/Automattic/VIP-Coding-Standards/issues", "wiki": "https://github.com/Automattic/VIP-Coding-Standards/wiki", From 7d13f3390053ef2f48aa17570f3143fafb17e135 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 24 Jan 2023 15:49:23 +0000 Subject: [PATCH 3/4] Composer: Remove install-codestandards script This is no longer needed; the list of installed code standards for PHPCS is reliably updated on `composer install` and `composer update`. --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index adaa775f..36705b32 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,6 @@ } }, "scripts": { - "install-codestandards": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run", "test-ruleset": "bin/ruleset-tests", "lint": [ "bin/php-lint", From 6d52e986047845590a9c279514471de7c0355f03 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 24 Jan 2023 16:40:24 +0000 Subject: [PATCH 4/4] Composer: Remove script and call PHPCS directly Has the advantages of: - working on Windows machines. - extra CLI args such as `--sniffs` can be passed when calling `composer cs`. --- bin/phpcs | 12 ------------ composer.json | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100755 bin/phpcs diff --git a/bin/phpcs b/bin/phpcs deleted file mode 100755 index 5fe70f99..00000000 --- a/bin/phpcs +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# -# Run PHPCS against VIP Coding Standards. -# -# This ensures that the code in the Sniffs and Tests follow the rules -# defined in the custom ruleset for this repo, `.phpcs.xml.dist`. -# -# EXAMPLE TO RUN LOCALLY: -# -# ./bin/phpcs - -"$(pwd)/vendor/bin/phpcs" diff --git a/composer.json b/composer.json index 36705b32..3b99fc37 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "bin/php-lint", "bin/xml-lint" ], - "cs": "bin/phpcs", + "cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs", "test": "bin/unit-tests", "test-coverage": "bin/unit-tests-coverage", "feature-completeness": [