Skip to content

Commit

Permalink
Build/PHPCS: set up the PHPCS ruleset properly
Browse files Browse the repository at this point in the history
* Add XSD schema.
* Set the command line arguments.
* Remove `exclude-pattern`s which are already set via YoastCS.
* Add configuration for the `WordPress.WP.I18n` sniff.
* Add configuration for the `Yoast.Files.Filename` sniff and remove the exclusion.
* Add configuration for the `WordPress.NamingConventions.PrefixAllGlobals` sniff.
  • Loading branch information
jrfnl committed Dec 12, 2019
1 parent e69a32d commit 01e7570
Showing 1 changed file with 80 additions and 10 deletions.
90 changes: 80 additions & 10 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,88 @@
<?xml version="1.0"?>
<ruleset name="Yoast Comment Hacks">
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Yoast Comment Hacks"
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">

<description>Yoast Comment Hacks rules for PHP_CodeSniffer</description>

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

<file>.</file>

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

<!-- 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="./"/>

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


<!--
#############################################################################
USE THE YoastCS RULESET
#############################################################################
-->

<rule ref="Yoast"/>


<!--
#############################################################################
SNIFF SPECIFIC CONFIGURATION
#############################################################################
-->

<!-- Verify that all gettext calls use the correct text domain. -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="yoast-comment-hacks"/>
</property>
</properties>
</rule>

<rule ref="Yoast.Files.FileName">
<properties>
<!-- Don't trigger on the main file as renaming it would deactivate the plugin. -->
<property name="exclude" type="array">
<element value="yoast-comment-hacks.php"/>
</property>

<!-- Remove the following prefixes from the names of object structures. -->
<property name="prefixes" type="array">
<element value="yoast_comment"/>
</property>
</properties>

<exclude-pattern>*/deprecated/deprecated-classes\.php$</exclude-pattern>
</rule>

<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>node_modules/*</exclude-pattern>
<!-- Verify that everything in the global namespace is prefixed with a plugin specific prefix. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Provide the prefixes to look for. -->
<property name="prefixes" type="array">
<!-- Temporarily allowed until the prefixes are fixed. -->
<element value="yoast_ch"/>
<element value="yst_comment"/>

<arg name="extensions" value="php" />
<arg value="nsp" />
<!-- These are the new prefixes which all code should comply with in the future. -->
<element value="yoast_comment"/>
<element value="Yoast\WP\Comment"/>
</property>
</properties>

<rule ref="Yoast">
<exclude name="Yoast.Files.FileName.InvalidClassFileName"/>
</rule>
<exclude-pattern>*/deprecated/*\.php$</exclude-pattern>
</rule>

</ruleset>

0 comments on commit 01e7570

Please sign in to comment.