Skip to content

Commit

Permalink
Merge pull request #1002 from WordPress/fix/997-separate-phpcs
Browse files Browse the repository at this point in the history
Separate `phpcs.xml.dist` Files for Each Plugin to Isolate Text Domains

Co-authored-by: mukeshpanchal27 <mukesh27@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>
Co-authored-by: thelovekesh <thelovekesh@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: joemcgill <joemcgill@git.wordpress.org>
  • Loading branch information
7 people authored Feb 27, 2024
2 parents c42da44 + ade03d8 commit 3b40aa4
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 99 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
/composer.lock export-ignore
/package.json export-ignore
/package-lock.json export-ignore
/phpcs.xml.dist export-ignore
phpcs.xml.dist export-ignore
/phpcs.ruleset.xml export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ jobs:
- name: Composer Install
run: composer install --no-interaction --no-progress
- name: PHP Lint
run: composer lint
run: composer lint:all
- name: PHPStan
run: composer phpstan
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M",
"format": "build-cs/vendor/bin/phpcbf --report-summary --report-source",
"lint": "build-cs/vendor/bin/phpcs",
"lint:all": [
"@lint",
"@lint:auto-sizes"
],
"lint:auto-sizes": "@lint -- ./plugins/auto-sizes --standard=./plugins/auto-sizes/phpcs.xml.dist",
"test": "phpunit --verbose --testsuite performance-lab",
"test-multisite": "phpunit -c tests/multisite.xml --verbose --testsuite performance-lab"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lint-js": "wp-scripts lint-js",
"format-php": "composer format",
"phpstan": "composer phpstan",
"lint-php": "composer lint",
"lint-php": "composer lint:all",
"test-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer test",
"test-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer test-multisite",
"wp-env": "wp-env",
Expand Down
93 changes: 93 additions & 0 deletions phpcs.ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0"?>
<ruleset name="WPP-Base">
<description>Sniffs for WordPress plugins</description>

<rule ref="PHPCompatibility"/>
<config name="testVersion" value="7.0-"/>

<rule ref="WordPress-Docs"/>
<rule ref="WordPress-Extra" />
<rule ref="WordPress.WP.I18n"/>

<arg value="ps"/>
<arg name="extensions" value="php"/>

<!-- Do not require docblocks for unit tests -->
<rule ref="Squiz.Commenting.FunctionComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FileComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.ClassComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.ClassComment.SpacingAfter">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Generic.Commenting.DocComment.Empty">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Generic.Commenting.DocComment.MissingShort">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.VariableComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FunctionCommentThrowTag.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<!-- Do not apply filename rules for unit tests and object cache -->
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<!-- Do not apply compatibility rules to allow using the modern PHPUnit functionality -->
<rule ref="PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.stringFound">
<exclude-pattern>tests/utils/*</exclude-pattern>
</rule>
<rule ref="PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.boolFound">
<exclude-pattern>tests/utils/*</exclude-pattern>
</rule>

<!-- Ignore inapplicable WordPress-Extra sniffs in tests. -->
<rule ref="WordPress.WP.EnqueuedResourceParameters">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.Security.EscapeOutput.OutputNotEscaped">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.unlink_unlink">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.GlobalVariablesOverride.Prohibited">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.PHP.DevelopmentFunctions.error_log_var_export">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<!-- Exceptions for variable name casing. -->
<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="allowed_custom_properties" type="array">
<element value="nodeValue"/>
<element value="parentNode"/>
<element value="createTextNode"/>
<element value="textContent"/>
</property>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.Functions.StaticClosure" />
</ruleset>
105 changes: 10 additions & 95 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,108 +1,23 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Performance Plugin">
<description>Sniffs for WordPress plugins, with minor modifications for Performance</description>

<rule ref="PHPCompatibility"/>
<config name="testVersion" value="7.0-"/>

<rule ref="WordPress-Docs"/>
<rule ref="WordPress-Extra" />
<rule ref="WordPress.WP.I18n"/>
<config name="text_domain" value="performance-lab,default,auto-sizes"/>

<arg value="ps"/>
<arg name="extensions" value="php"/>

<file>./admin</file>
<file>./load.php</file>
<file>./modules</file>
<file>./plugins</file>
<file>./server-timing</file>
<file>./tests</file>
<ruleset name="WPP-PerfLab">
<description>WordPress Coding Standards for the Performance Lab Plugin</description>
<rule ref="phpcs.ruleset.xml"/>

<config name="text_domain" value="performance-lab,default"/>

<!-- Do not require file headers on generated files -->
<rule ref="Squiz.Commenting.FileComment.WrongStyle">
<exclude-pattern>default-enabled-modules.php</exclude-pattern>
<exclude-pattern>module-i18n.php</exclude-pattern>
</rule>

<!-- Do not require docblocks for unit tests -->
<rule ref="Squiz.Commenting.FunctionComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FileComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.ClassComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.ClassComment.SpacingAfter">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Generic.Commenting.DocComment.Empty">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Generic.Commenting.DocComment.MissingShort">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.VariableComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FunctionCommentThrowTag.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<!-- Do not apply filename rules for unit tests and object cache -->
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>server-timing/object-cache.copy.php</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<!-- Do not apply compatibility rules to allow using the modern PHPUnit functionality -->
<rule ref="PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.stringFound">
<exclude-pattern>tests/utils/*</exclude-pattern>
</rule>
<rule ref="PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.boolFound">
<exclude-pattern>tests/utils/*</exclude-pattern>
</rule>

<!-- Ignore inapplicable WordPress-Extra sniffs in tests. -->
<rule ref="WordPress.WP.EnqueuedResourceParameters">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.Security.EscapeOutput.OutputNotEscaped">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.unlink_unlink">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.GlobalVariablesOverride.Prohibited">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.PHP.DevelopmentFunctions.error_log_var_export">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<!-- Exceptions for variable name casing. -->
<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="allowed_custom_properties" type="array">
<element value="nodeValue"/>
<element value="parentNode"/>
<element value="createTextNode"/>
<element value="textContent"/>
</property>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.Functions.StaticClosure" />
<file>.</file>
<exclude-pattern>./build/*</exclude-pattern>
<exclude-pattern>./node_modules/*</exclude-pattern>
<exclude-pattern>./plugins/*</exclude-pattern>
<exclude-pattern>./vendor/*</exclude-pattern>
</ruleset>
1 change: 0 additions & 1 deletion plugin-tests/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@

// Start up the WP testing environment.
require $_test_root . '/includes/bootstrap.php';

10 changes: 10 additions & 0 deletions plugins/auto-sizes/phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<ruleset name="WPP-AutoSizes">
<description>WordPress Coding Standards for Auto-sizes for Lazy-loaded Images Plugin</description>

<rule ref="../../phpcs.ruleset.xml"/>

<config name="text_domain" value="auto-sizes"/>

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

0 comments on commit 3b40aa4

Please sign in to comment.