Skip to content

Commit

Permalink
Merge pull request #219 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 b4aaf93 + c9fb440 commit e333d2a
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 41 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
15 changes: 14 additions & 1 deletion .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 @@ -93,4 +93,17 @@
</properties>
</rule>


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

<!-- These all implement an interface with a required parameter. Can't be helped. -->
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable">
<exclude-pattern>/src/wordpress-plugins/(?:(?:local|news|video|woocommerce)-seo|yoast-seo-premium)\.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 @@ -19,7 +19,7 @@
"ext-zip": "*"
},
"require-dev": {
"yoast/yoastcs": "^2.3.1"
"yoast/yoastcs": "^3.0"
},
"autoload": {
"classmap": [
Expand Down Expand Up @@ -47,7 +47,7 @@
"Yoast\\WP\\Test_Helper\\Config\\Composer\\Actions::check_coding_standards"
],
"check-cs-thresholds": [
"@putenv YOASTCS_THRESHOLD_ERRORS=0",
"@putenv YOASTCS_THRESHOLD_ERRORS=32",
"@putenv YOASTCS_THRESHOLD_WARNINGS=0",
"Yoast\\WP\\Test_Helper\\Config\\Composer\\Actions::check_cs_thresholds"
],
Expand Down
Loading

0 comments on commit e333d2a

Please sign in to comment.