Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer/PHPCS: update to YoastCS 3.0.0 #373

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,26 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Determine the base branch for the file diff
id: base_branch
env:
BASE_REF: ${{ github.base_ref }}
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "NAME=$BASE_REF" >> $GITHUB_OUTPUT
echo "REF=origin/$BASE_REF" >> $GITHUB_OUTPUT
else
echo 'NAME=develop' >> $GITHUB_OUTPUT
echo "REF=origin/develop" >> $GITHUB_OUTPUT
fi

- name: Fetch base branch
run: git fetch --no-tags --depth=1 origin ${{ steps.base_branch.outputs.NAME }}

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

Expand All @@ -58,12 +74,18 @@ jobs:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

# Check the codestyle of the files.
# The results of the CS check will be shown inline in the PR via the CS2PR tool.
# Check the codestyle of the files against a threshold of expected errors and warnings.
- name: Check PHP code style against the thresholds
run: composer check-cs-thresholds

# Check the codestyle only of the files which were changed in the current branch.
# This step will only be executed if the threshold check exited with a failure status.
# The results of this CS check will be shown inline in the PR via the CS2PR tool.
# @link https://github.com/staabm/annotate-pull-request-from-checkstyle/
- name: Check PHP code style
- name: Check PHP code style for the changes made in the branch only
if: ${{ failure() }}
id: phpcs
run: composer check-cs-warnings -- --no-cache --report-full --report-checkstyle=./phpcs-report.xml
run: composer check-branch-cs -- ${{ steps.base_branch.outputs.REF }}

- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
Expand Down
48 changes: 6 additions & 42 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->

Expand Down Expand Up @@ -46,6 +46,10 @@
<element value="Yoast\WP\ACF"/>
<element value="yoast_acf"/>
</property>

<property name="psr4_paths" type="array">
<element key="Yoast\WP\ACF\Tests\\" value="tests/"/>
</property>
</properties>
</rule>

Expand Down Expand Up @@ -80,40 +84,6 @@
</properties>
</rule>

<rule ref="Yoast.Files.TestDoubles">
<properties>
<property name="doubles_path" type="array">
<element value="/tests/Unit/Doubles"/>
</property>
</properties>
</rule>

<rule ref="Yoast.NamingConventions.NamespaceName">
<properties>
<!-- Treat the "tests/Unit" directory as a project root for path to namespace translations. -->
<property name="src_directory" type="array">
<element value="tests/Unit"/>
</property>

<property name="prefixes" type="array" extend="true">
<element value="Yoast\WP\ACF\Tests\Unit"/>
</property>
</properties>
</rule>


<!--
#############################################################################
SELECTIVE EXCLUSIONS
Exclude specific files for specific sniffs and/or exclude sub-groups in sniffs.
#############################################################################
-->

<!-- Valid usage: For testing purposes, some non-prefixed globals are being created. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<exclude-pattern>/tests/Unit/bootstrap\.php$</exclude-pattern>
</rule>


<!--
#############################################################################
Expand All @@ -133,15 +103,9 @@
</rule>

<!-- Namespaced test classes imported via a use statement are not yet correctly excluded
by WPCS. This will most likely be fixed once PHPCS 3.5.0 has been released and
WPCS has upgraded to that version. -->
by WPCS. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound">
<exclude-pattern>/tests/Unit/Dependencies/Dependency_Yoast_SEO_Test\.php$</exclude-pattern>
</rule>

<!-- The below issue will be fixed in YoastCS 3.0, after which this exclude can be removed. -->
<rule ref="Yoast.Files.FileName.InvalidClassFileName">
<exclude-pattern>/tests/Unit/*\.php$</exclude-pattern>
</rule>

</ruleset>
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"require-dev": {
"yoast/wp-test-utils": "^1.2.0",
"yoast/yoastcs": "^2.3.1"
"yoast/yoastcs": "^3.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down Expand Up @@ -85,7 +85,7 @@
"Yoast\\WP\\ACF\\Config\\Composer\\Actions::check_coding_standards"
],
"check-cs-thresholds": [
"@putenv YOASTCS_THRESHOLD_ERRORS=0",
"@putenv YOASTCS_THRESHOLD_ERRORS=11",
"@putenv YOASTCS_THRESHOLD_WARNINGS=0",
"Yoast\\WP\\ACF\\Config\\Composer\\Actions::check_cs_thresholds"
],
Expand Down
Loading