Skip to content

Commit

Permalink
Chore/wp graphql cs (#162)
Browse files Browse the repository at this point in the history
* dev: implement wp-graphql-cs ruleset

* chore: phpbcf for WPGraphQL-minimum

* chore: ignore via WordPress ruleset

* chore: implement and phpbcf for WPGraphQL-Strict

* chore: implement and phpcbf for WPGraphQL ruleset

* Lint: PHPCS fixes

* Update composer.json

Co-authored-by: Dovid Levine <[email protected]>

---------

Co-authored-by: David Levine <[email protected]>
  • Loading branch information
theodesp and justlevine authored Nov 29, 2023
1 parent 7a4372a commit 2d793cf
Show file tree
Hide file tree
Showing 26 changed files with 908 additions and 706 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ artifacts
!.docker/plugins/test-cpt
docker-compose.override.yml

# phpcs cache
/tests/_output/cache.json

# Built Zip
@wpengine
103 changes: 61 additions & 42 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,45 +1,60 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards based custom ruleset for your plugin">
<description>Generally-applicable sniffs for WordPress plugins.</description>
<ruleset name="WordPress Coding Standards for WPGraphQL Plugins" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<description>Sniffs for WPGraphQL Content Blocks</description>

<file>.</file>

<!-- Exclude composer vendor directory -->
<!-- What to scan: include any root-level PHP files, and the /includes folder -->
<file>./wp-graphql-content-blocks.php</file>
<file>./includes/</file>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/node_modules/</exclude-pattern>
<exclude-pattern>/phpstan/</exclude-pattern>
<exclude-pattern>/tests/</exclude-pattern>
<exclude-pattern>**/tests/**</exclude-pattern>

<!-- How to scan -->
<!-- How to scan: include CLI args so you don't need to pass them manually -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<arg value="sp" />
<arg name="basepath" value="./" />
<arg name="colors" />
<arg name="extensions" value="php" />
<arg name="parallel" value="8" />

<!-- Rules: Check PHP version compatibility -->
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="7.4-" />

<!-- https://github.com/wpengine/wpengine-coding-standards -->
<rule ref="WP-Engine-Strict"/>

<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<rule ref="PHPCompatibilityWP" />

<!-- Rules: WordPress Coding Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<config name="minimum_supported_wp_version" value="5.3" />

<rule ref="WordPress">
<!-- Show sniff and progress -->
<arg value="sp"/>
<!-- Strip the file paths down to the relevant bit -->
<arg name="basepath" value="./"/>
<!-- Enable colors in report -->
<arg name="colors"/>
<!-- Only lint php files by default -->
<arg name="extensions" value="php"/>
<!-- Whenever possible, cache the scan results and re-use those for unchanged files on the next scan. -->
<arg name="cache" value="tests/_output/cache.json" />
<!-- Enables parallel processing when available for faster results. -->
<arg name="parallel" value="20"/>
<!-- Set severity to 1 to see everything that isn't effectively turned off. -->
<arg name="severity" value="1" />

<!-- Ruleset Config: set these to match your project constraints-->

<!--
Tests for PHP version compatibility.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#Recomended-additional-rulesets
-->
<config name="testVersion" value="7.4-"/>

<!--
Tests for WordPress version compatibility.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties
-->
<config name="minimum_supported_wp_version" value="5.3"/>

<!-- Rules: WPGraphQL Coding Standards -->
<!-- https://github.com/AxeWP/WPGraphQL-Coding-Standards/WPGraphQL/ruleset.xml -->
<rule ref="WPGraphQL">
<!-- The is the only thing missing from WPEngine-Strict -->
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
<!-- This should be excluded upstream in the ruleset-->
<exclude name="WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase" />
</rule>

<!-- Individual rule configuration -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
<property name="prefixes" type="array">
<element value="wpgraphql\content_blocks" />
<element value="WPGRAPHQL\CONTENT_BLOCKS" />
Expand All @@ -50,25 +65,30 @@
</properties>
</rule>

<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array" value="wp-graphql-content-blocks" />
</properties>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification" />
</rule>

<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
<properties>
<property name="blank_line_check" value="true" />
</properties>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification" />
</rule>

<rule ref="WordPress.Files.FileName">
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint" />
</rule>

<rule ref="WordPress.WP.I18n">
<properties>
<!-- Value: replace the text domain used. -->
<property name="text_domain" type="array" value="wp-graphql-content-blocks" />
</properties>
</rule>


<!-- Exclude rules that break PHP Unit test conventions or result in redundant comments. -->
<!-- Test functions and properties are self-describing. -->
<!-- @todo These shouldnt be necessary, since tests are excluded -->
<rule ref="Generic.Commenting.DocComment.MissingShort">
<exclude-pattern>/tests/</exclude-pattern>
</rule>
Expand Down Expand Up @@ -132,5 +152,4 @@
<exclude-pattern>/tests/</exclude-pattern>
</rule>


</ruleset>
</ruleset>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"brain/monkey": "^2.6",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpunit/phpunit": "^9.5",
"wpengine/wpengine-coding-standards": "dev-develop",
"yoast/phpunit-polyfills": "^1.0",
"squizlabs/php_codesniffer": "^3.7",
"phpstan/phpstan": "^1.10",
"phpstan/extension-installer": "^1.3",
"szepeviktor/phpstan-wordpress": "^1.3",
"axepress/wp-graphql-stubs": "^1.14",
"axepress/wp-graphql-cs": "^1.0.0-beta",
"roave/security-advisories": "dev-latest"
},
"scripts": {
Expand Down
Loading

0 comments on commit 2d793cf

Please sign in to comment.