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

Separate phpcs.xml.dist Files for Each Plugin to Isolate Text Domains #1002

Merged
merged 11 commits into from
Feb 27, 2024
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
mukeshpanchal27 marked this conversation as resolved.
Show resolved Hide resolved

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",
mukeshpanchal27 marked this conversation as resolved.
Show resolved Hide resolved
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
"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"/>

mukeshpanchal27 marked this conversation as resolved.
Show resolved Hide resolved
<!-- 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"/>
mukeshpanchal27 marked this conversation as resolved.
Show resolved Hide resolved

<!-- 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"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to my previous feedback, we could add default as an allowed text domain for all plugins, but definitely not required as long as we don't use any core strings in them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this omitted unless we require core strings.


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