Skip to content

Commit

Permalink
Merge pull request #373 from Yoast/JRF/CS/update-phpcs-ruleset-yoastc…
Browse files Browse the repository at this point in the history
…s-3.0.0

Composer/PHPCS: update to YoastCS 3.0.0
  • Loading branch information
jrfnl authored Dec 16, 2023
2 parents da09ba1 + 36fe88d commit 1844f3a
Show file tree
Hide file tree
Showing 4 changed files with 502 additions and 82 deletions.
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

0 comments on commit 1844f3a

Please sign in to comment.