Skip to content

Commit

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

Composer/PHPCS: update to YoastCS 3.0.0
  • Loading branch information
jrfnl authored Dec 14, 2023
2 parents d0a8e4c + 2c9e056 commit 4656688
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: 'latest'
coverage: none
tools: cs2pr

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
ini-values: error_reporting=E_ALL, display_errors=On
coverage: ${{ matrix.coverage == true && 'xdebug' || 'none' }}

# YoastCS 3.0 has a PHP 7.2 minimum which conflicts with the requirements of this package.
- name: 'Composer: remove YoastCS'
run: composer remove --dev yoast/yoastcs --no-update --no-interaction

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies - normal
Expand Down
91 changes: 55 additions & 36 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Coding Standard for WP Test Utils" xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>Check the code of WP Test Utils.</description>
<description>Check the code of WP Test Utils.</description>

<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->
<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->

<file>.</file>
<file>.</file>

<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>
<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>

<!-- Show progress, show the error codes for each message (source). -->
<arg value="ps"/>
<!-- Show progress, show the error codes for each message (source). -->
<arg value="ps"/>

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>
<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>
<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>

<!-- Cache the results between runs. -->
<arg name="cache" value="./.cache/phpcs.cache"/>
Expand All @@ -41,16 +41,25 @@
</property>
</properties>

<!-- Use CamelCaps file names to be more in line with the naming conventions used in PHPUnit. -->
<exclude name="Yoast.Files.FileName"/>

<!-- The code in this package is not run in the context of a plugin. -->
<exclude name="WordPress.WP.AlternativeFunctions"/>
<exclude name="Yoast.Yoast.AlternativeFunctions"/>
<!-- Exclude some rules which are irrelevant.
The code in this package is not run in the context of a WordPress plugin. -->
<exclude name="WordPress.DB"/>
<exclude name="WordPress.Security"/>
<exclude name="WordPress.WP"/>
<exclude name="Yoast.Yoast.JsonEncodeAlternative"/>
<exclude name="WordPressVIPMinimum"/>

<!-- Exclude select "modern PHP" sniffs, which conflict with the minimum supported PHP version of this package. -->
<exclude name="Modernize.FunctionCalls.Dirname.Nested"/><!-- PHP 7.0+. -->
<exclude name="PSR12.Properties.ConstantVisibility"/><!-- PHP 7.1+. -->
<exclude name="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/><!-- PHP 7.1+. -->
</rule>

<!-- Enforce PSR1 compatible namespaces. -->
<rule ref="PSR1.Classes.ClassDeclaration"/>
<rule ref="PSR1.Classes.ClassDeclaration">
<!-- YoastCS only applies this rule to test files. Overrule it to apply to all files. -->
<include-pattern>*\.php</include-pattern>
</rule>


<!--
Expand All @@ -59,13 +68,21 @@
#############################################################################
-->

<rule ref="Yoast.NamingConventions.NamespaceName">
<rule ref="Yoast.Files.FileName">
<properties>
<property name="prefixes" type="array">
<element value="Yoast\WPTestUtils"/>
<property name="psr4_paths" type="array">
<element key="Yoast\WPTestUtils\Tests\\" value="tests/"/>
</property>
<property name="src_directory" type="array">
<element value="src"/>
</properties>

<include-pattern>/tests/*\.php</include-pattern>
</rule>

<rule ref="Yoast.NamingConventions.NamespaceName">
<properties>
<property name="psr4_paths" type="array">
<element key="Yoast\WPTestUtils\\" value="src/"/>
<element key="Yoast\WPTestUtils\Tests\\" value="tests/"/>
</property>
</properties>
</rule>
Expand All @@ -78,7 +95,7 @@

<rule ref="WordPress.PHP.NoSilencedErrors">
<properties>
<property name="custom_whitelist" type="array">
<property name="customAllowedFunctionsList" type="array">
<element value="file_exists"/>
</property>
</properties>
Expand All @@ -92,11 +109,6 @@
#############################################################################
-->

<!-- Allow filecomments in file which don't contain OO declarations. -->
<rule ref="Yoast.Commenting.FileComment.Unnecessary">
<exclude-pattern>/src/*/bootstrap*\.php$</exclude-pattern>
</rule>

<!-- Declaring a few WordPress native constants. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound">
<exclude-pattern>/src/BrainMonkey/bootstrap\.php$</exclude-pattern>
Expand All @@ -116,9 +128,16 @@
<exclude-pattern>/src/Helpers/*\.php$</exclude-pattern>
</rule>

<!-- Ignore word count for object names in tests. -->
<!-- TEST CODE -->

<!-- Final classes is irrelevant for test fixtures. -->
<rule ref="Universal.Classes.RequireFinalClass">
<exclude-pattern>/tests/*/Fixtures/*\.php$</exclude-pattern>
</rule>

<!-- Ignore word count for object names in test fixtures. -->
<rule ref="Yoast.NamingConventions.ObjectNameDepth.MaxExceeded">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
<exclude-pattern>/tests/*/Fixtures/*\.php$</exclude-pattern>
</rule>

<!-- Test fixtures are not the actual tests. -->
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"yoast/phpunit-polyfills": "^1.1.0"
},
"require-dev": {
"yoast/yoastcs": "^2.3.1"
"php-parallel-lint/php-console-highlighter": "^1.0.0",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"yoast/yoastcs": "^3.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down

0 comments on commit 4656688

Please sign in to comment.