Skip to content

Commit

Permalink
Merge pull request #2439 from WordPress/develop
Browse files Browse the repository at this point in the history
Release WordPressCS 3.1.0
  • Loading branch information
jrfnl committed Mar 25, 2024
2 parents b4caf96 + cf2cffe commit 9333efc
Show file tree
Hide file tree
Showing 50 changed files with 496 additions and 228 deletions.
16 changes: 8 additions & 8 deletions .github/CONTRIBUTING.md
Expand Up @@ -14,7 +14,7 @@ Bug reports containing a minimal code sample which can be used to reproduce the
Since WordPressCS employs many sniffs that are part of PHP_CodeSniffer itself or PHPCSExtra, sometimes an issue will be caused by a bug in PHPCS or PHPCSExtra and not in WordPressCS itself.
If the error message in question doesn't come from a sniff whose name starts with `WordPress`, the issue is probably a bug in PHPCS or PHPCSExtra.

* Bugs for sniffs starting with `Generic`, `PEAR`, `PSR1`, `PSR2`, `PSR12`, `Squiz` or `Zend` should be [reported to PHPCS](https://github.com/squizlabs/PHP_CodeSniffer/issues).
* Bugs for sniffs starting with `Generic`, `PEAR`, `PSR1`, `PSR2`, `PSR12`, `Squiz` or `Zend` should be [reported to PHPCS](https://github.com/PHPCSStandards/PHP_CodeSniffer/issues).
* Bugs for sniffs starting with `Modernize`, `NormalizedArrays` or `Universal` should be [reported to PHPCSExtra](https://github.com/PHPCSStandards/PHPCSExtra/issues).

# Contributing patches and new features
Expand All @@ -39,10 +39,10 @@ When you introduce new `public` sniff properties, or your sniff extends a class

## Pre-requisites
* WordPress-Coding-Standards
* PHP_CodeSniffer 3.7.2 or higher
* PHPCSUtils 1.0.8 or higher
* PHPCSExtra 1.1.0 or higher
* PHPUnit 4.x, 5.x, 6.x or 7.x
* PHP_CodeSniffer 3.9.0 or higher
* PHPCSUtils 1.0.10 or higher
* PHPCSExtra 1.2.1 or higher
* PHPUnit 4.x - 9.x

The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test framework for unit testing the sniffs.

Expand Down Expand Up @@ -85,9 +85,9 @@ phpunit --filter WordPress /path/to/PHP_CodeSniffer/tests/AllTests.php

Expected output:
```
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
PHPUnit 9.6.15 by Sebastian Bergmann and contributors.
Runtime: PHP 7.4.33
Runtime: PHP 8.3.0
Configuration: /WordPressCS/phpunit.xml.dist
......................................................... 57 / 57 (100%)
Expand Down Expand Up @@ -138,7 +138,7 @@ Also note the class name convention. The method `getErrorList()` MUST return an
If you run the following from the root directory of your WordPressCS clone:

```sh
$ "vendor/bin/phpcs" --standard=Wordpress -s ./Tests/PHP/POSIXFunctionsUnitTest.inc --sniffs=WordPress.PHP.POSIXFunctions
$ "vendor/bin/phpcs" --standard=Wordpress -s ./WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc --sniffs=WordPress.PHP.POSIXFunctions
...
--------------------------------------------------------------------------------
FOUND 7 ERRORS AFFECTING 7 LINES
Expand Down
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
@@ -1 +1 @@
custom: "https://opencollective.com/thewpcc/contribute/wp-php-63406"
custom: "https://opencollective.com/php_codesniffer"
17 changes: 17 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,17 @@
# Dependabot configuration.
#
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
time: "09:00"
open-pull-requests-limit: 5
commit-message:
prefix: "GH Actions:"
labels:
- "Type: Chores/Cleanup"
2 changes: 1 addition & 1 deletion .github/release-checklist.md
Expand Up @@ -64,7 +64,7 @@ PR for tracking changes for the x.x.x release. Target release date: **DOW MONTH
- [ ] Submit for ["Month in WordPress"][month-in-wp].
- [ ] Submit for the ["Monthy Dev Roundup"][dev-roundup].

[phpcs-releases]: https://github.com/squizlabs/PHP_CodeSniffer/releases
[phpcs-releases]: https://github.com/PHPCSStandards/PHP_CodeSniffer/releases
[phpcsutils-releases]: https://github.com/PHPCSStandards/PHPCSUtils/releases
[phpcsextra-releases]: https://github.com/PHPCSStandards/PHPCSExtra/releases
[month-in-wp]: https://make.wordpress.org/community/month-in-wordpress-submissions/
Expand Down
67 changes: 42 additions & 25 deletions .github/workflows/basic-qa.yml
Expand Up @@ -12,6 +12,11 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
PHPCS_DEV: 'dev-master'
UTILS_DEV: 'dev-develop'
EXTRA_DEV: 'dev-develop'

jobs:
# Check code style of sniffs, rulesets and XML documentation.
# Check that all sniffs are feature complete.
Expand All @@ -24,7 +29,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -37,12 +42,16 @@ jobs:
- name: Validate the composer.json file
run: composer validate --no-check-all --strict

# Using PHPCS `master` as an early detection system for bugs upstream.
- name: Set PHPCS version
run: composer require squizlabs/php_codesniffer:"dev-master" --no-update --no-scripts --no-interaction
# Using dev versions of the dependencies as an early detection system for bugs upstream.
- name: "Composer: set PHPCS dependencies (dev)"
run: >
composer require --no-update --no-scripts --no-interaction
squizlabs/php_codesniffer:"${{ env.PHPCS_DEV }}"
phpcsstandards/phpcsutils:"${{ env.UTILS_DEV }}"
phpcsstandards/phpcsextra:"${{ env.EXTRA_DEV }}"
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
Expand All @@ -54,7 +63,8 @@ jobs:
# Show XML violations inline in the file diff.
# @link https://github.com/marketplace/actions/xmllint-problem-matcher
- uses: korelstar/xmllint-problem-matcher@v1
- name: Enable showing XML issues inline
uses: korelstar/xmllint-problem-matcher@v1

- name: Check the code style of the PHP files
id: phpcs
Expand Down Expand Up @@ -92,19 +102,19 @@ jobs:

# Makes sure the rulesets don't throw unexpected errors or warnings.
# This workflow needs to be run against a high PHP version to prevent triggering the syntax error check.
# It also needs to be run against all PHPCS versions WPCS is tested against.
# It also needs to be run against all dependency versions WPCS is tested against.
ruleset-tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ 'latest' ]
phpcs_version: [ 'lowest', 'dev-master' ]
dependencies: [ 'lowest', 'stable', 'dev' ]

name: "Ruleset test: PHP ${{ matrix.php }} on PHPCS ${{ matrix.phpcs_version }}"
name: "Ruleset test: PHP ${{ matrix.php }} on PHPCS ${{ matrix.dependencies }}"

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
Expand All @@ -114,20 +124,28 @@ jobs:
ini-values: error_reporting = E_ALL & ~E_DEPRECATED
coverage: none

- name: "Set PHPCS version (master)"
if: ${{ matrix.phpcs_version != 'lowest' }}
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
- name: "Composer: set PHPCS dependencies for tests (dev)"
if: ${{ matrix.dependencies == 'dev' }}
run: >
composer require --no-update --no-scripts --no-interaction
squizlabs/php_codesniffer:"${{ env.PHPCS_DEV }}"
phpcsstandards/phpcsutils:"${{ env.UTILS_DEV }}"
phpcsstandards/phpcsextra:"${{ env.EXTRA_DEV }}"
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3
with:
composer-options: --no-dev
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Set PHPCS version (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
- name: "Composer: downgrade PHPCS dependencies for tests (lowest)"
if: ${{ matrix.dependencies == 'lowest' }}
run: >
composer update --prefer-lowest --no-scripts --no-interaction
squizlabs/php_codesniffer
phpcsstandards/phpcsutils
phpcsstandards/phpcsextra
- name: Test the WordPress-Core ruleset
run: $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress-Core
Expand All @@ -150,15 +168,14 @@ jobs:
# Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files.
# This is not an exhaustive test, but should give an early indication for typical fixer conflicts.
# If only fixable errors are found, the exit code will be 1, which can be interpreted as success.
#
# Note: the ValidVariableNameUnitTest.inc file is temporarily ignored until upstream PHPCS PR 3833 has been merged.
# This check is only run against "dev" as conflicts can not be fixed for already released versions.
- name: Test for fixer conflicts (fixes expected)
if: ${{ matrix.phpcs_version == 'dev-master' }}
if: ${{ matrix.dependencies == 'dev' }}
id: phpcbf
continue-on-error: true
run: |
set +e
$(pwd)/vendor/bin/phpcbf -pq ./WordPress/Tests/ --standard=WordPress --extensions=inc --exclude=Generic.PHP.Syntax --report=summary --ignore=/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc,/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.7.inc
$(pwd)/vendor/bin/phpcbf -pq ./WordPress/Tests/ --standard=WordPress --extensions=inc --exclude=Generic.PHP.Syntax --report=summary --ignore=/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.7.inc
exitcode="$?"
echo "EXITCODE=$exitcode" >> $GITHUB_OUTPUT
exit "$exitcode"
Expand All @@ -174,20 +191,20 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: 'latest'
coverage: none
tools: phpstan

# Install dependencies and handle caching in one go.
# Dependencies need to be installed to make sure the PHPCS and PHPUnit classes are recognized.
# @link https://github.com/marketplace/actions/install-composer-dependencies
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/manage-labels.yml
Expand Up @@ -17,7 +17,7 @@ jobs:
name: Clean up labels on PR merge

steps:
- uses: mondeja/remove-labels-gh-action@v1
- uses: mondeja/remove-labels-gh-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: |
Expand All @@ -31,7 +31,7 @@ jobs:
name: Clean up labels on PR close

steps:
- uses: mondeja/remove-labels-gh-action@v1
- uses: mondeja/remove-labels-gh-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: |
Expand All @@ -46,7 +46,7 @@ jobs:
name: Clean up labels on issue close

steps:
- uses: mondeja/remove-labels-gh-action@v1
- uses: mondeja/remove-labels-gh-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: |
Expand Down
68 changes: 23 additions & 45 deletions .github/workflows/quicktest.yml
Expand Up @@ -23,74 +23,52 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '5.4', '7.4', 'latest' ]
phpcs_version: [ 'lowest', 'dev-master' ]
php: [ '5.4', 'latest' ]
dependencies: [ 'lowest', 'stable' ]

name: QTest - PHP ${{ matrix.php }} on PHPCS ${{ matrix.phpcs_version }}
name: QTest - PHP ${{ matrix.php }} on PHPCS ${{ matrix.dependencies }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

# On stable PHPCS versions, allow for PHP deprecation notices.
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
- name: Setup ini config
id: set_ini
run: |
if [ "${{ matrix.phpcs_version }}" != "dev-master" ]; then
echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' >> $GITHUB_OUTPUT
else
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT
fi
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
# With stable PHPCS dependencies, allow for PHP deprecation notices.
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
ini-values: error_reporting=-1, display_errors=On
coverage: ${{ github.ref_name == 'develop' && 'xdebug' || 'none' }}

- name: "Set PHPCS version (master)"
if: ${{ matrix.phpcs_version != 'lowest' }}
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction

- name: Install Composer dependencies (PHP < 8.0 )
if: ${{ matrix.php < 8.0 && matrix.php != 'latest' }}
uses: ramsey/composer-install@v2
- name: Install Composer dependencies
uses: ramsey/composer-install@v3
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Install Composer dependencies (PHP >= 8.0)
if: ${{ matrix.php >= 8.0 || matrix.php == 'latest' }}
uses: ramsey/composer-install@v2
with:
composer-options: --ignore-platform-req=php+
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Set PHPCS version (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
- name: "Composer: downgrade PHPCS dependencies for tests (lowest)"
if: ${{ matrix.dependencies == 'lowest' }}
run: >
composer update --prefer-lowest --no-scripts --no-interaction
squizlabs/php_codesniffer
phpcsstandards/phpcsutils
phpcsstandards/phpcsextra
- name: Lint PHP files against parse errors
if: ${{ matrix.phpcs_version == 'dev-master' }}
run: composer lint -- --checkstyle
if: ${{ matrix.dependencies == 'stable' }}
run: composer lint

- name: Run the unit tests without code coverage - PHP 5.4 - 8.0
if: ${{ matrix.php == '5.4' && github.ref_name != 'develop' }}
- name: Run the unit tests without code coverage
if: ${{ github.ref_name != 'develop' }}
run: composer run-tests

# Until PHPCS supports PHPUnit 9, we cannot run code coverage on PHP 8.0+, so run it on PHP 5.4 and 7.4.
- name: Run the unit tests with code coverage - PHP 5.4 - 8.0
if: ${{ matrix.php != 'latest' && github.ref_name == 'develop' }}
- name: Run the unit tests with code coverage
if: ${{ github.ref_name == 'develop' }}
run: composer coverage

- name: Run the unit tests without code coverage - PHP >= 8.1
if: ${{ matrix.php == 'latest' }}
run: composer run-tests -- --no-configuration --bootstrap=./Tests/bootstrap.php --dont-report-useless-tests

- name: Send coverage report to Codecov
if: ${{ success() && github.ref_name == 'develop' && matrix.php != 'latest' }}
if: ${{ success() && github.ref_name == 'develop' }}
uses: codecov/codecov-action@v3
with:
files: ./build/logs/clover.xml
Expand Down

0 comments on commit 9333efc

Please sign in to comment.