Skip to content

Instantly share code, notes, and snippets.

@renakdup
Last active December 12, 2022 23:46
Show Gist options
  • Save renakdup/50f2185557277b826794642f8f6c5b47 to your computer and use it in GitHub Desktop.
Save renakdup/50f2185557277b826794642f8f6c5b47 to your computer and use it in GitHub Desktop.
WordPress tooling
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards">
<description>A custom set of code standard rules to check for WordPress plugins.</description>
<config name="testVersion" value="7.3"/>
<!-- How to scan -->
<!-- Show sniff and progress -->
<arg value="sp"/>
<!-- Strip the file paths down to the relevant bit -->
<arg name="basepath" value="./"/>
<arg name="extensions" value="php"/>
<!-- Enables parallel processing when available for faster results. -->
<!-- <arg name="parallel" value="10"/>
<arg name="cache" value=".phpcs.cache"/>
<!-- What to scan -->
<file>wp-content/mu-plugins/</file>
<file>wp-content/plugins/</file>
<file>wp-content/themes/</file>
<!-- Exclude common files -->
<exclude-pattern>*/\.github/*</exclude-pattern>
<exclude-pattern>*/\.make/*</exclude-pattern>
<exclude-pattern>*/\.wordpress-org/*</exclude-pattern>
<exclude-pattern>*/assets/*</exclude-pattern>
<exclude-pattern>*/languages/*</exclude-pattern>
<exclude-pattern>*/lib/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/src/js/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*\.js</exclude-pattern>
<exclude-pattern>*\.mo</exclude-pattern>
<exclude-pattern>*\.po</exclude-pattern>
<exclude-pattern>*\.twig</exclude-pattern>
<exclude-pattern>*\.css</exclude-pattern>
<exclude-pattern>*\.scss</exclude-pattern>
<!-- Exclude plugins that are installed from the composer -->
<!-- Rules: Check PHP version compatibility -->
<rule ref="PHPCompatibility"/>
<rule ref="PHPCompatibilityWP"/>
<!-- Rules: WordPress Coding Standards -->
<config name="minimum_supported_wp_version" value="5.4.1"/>
<rule ref="WordPress">
<!-- Allow short ternary syntax and short arrays and short open tag -->
<exclude name="Generic.Arrays.DisallowShortArraySyntax" />
<exclude name="WordPress.PHP.DisallowShortTernary.Found" />
<exclude name="Generic.PHP.DisallowShortOpenTag" />
<!-- Disable dot of end string docblock -->
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
<exclude name="WordPress.PHP.YodaConditions" />
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
<exclude name="PEAR.NamingConventions.ValidClassName.Invalid" />
</rule>
<!-- Disable comments blocks -->
<rule ref="WordPress-Docs">
<exclude name="Squiz.Commenting.FileComment.Missing" />
<exclude name="Squiz.Commenting.FileComment.MissingPackageTag" />
<exclude name="Squiz.Commenting.ClassComment.Missing" />
<exclude name="Squiz.Commenting.FunctionComment.Missing" />
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamType" />
<exclude name="Squiz.Commenting.VariableComment.Missing" />
</rule>
<!-- Allow symbol `/` in hook names. -->
<rule ref="WordPress.NamingConventions.ValidHookName">
<properties>
<property name="additionalWordDelimiters" value="/" />
</properties>
</rule>
<!-- Allow for underscores in theme template file names -->
<rule ref="WordPress.Files.FileName">
<properties>
<property name="is_theme" value="true" />
</properties>
</rule>
<!--<rule ref="Generic.Metrics.CyclomaticComplexity">
<properties>
<property name="complexity" value="3"/>
<property name="absoluteComplexity" value="5"/>
</properties>
</rule>-->
<rule ref="Generic.Metrics.NestingLevel">
<properties>
<property name="absoluteNestingLevel" value="4"/>
</properties>
</rule>
<!-- Disallow long array syntax. -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"/>
<!-- Prohibit Yoda Conditions expressions -->
<rule ref="Generic.ControlStructures.DisallowYodaConditions"/>
<!-- Ignore alignment DoubleArrow symbol for some directories. -->
<rule ref="WordPress.Arrays.MultipleStatementAlignment">
<!-- <exclude-pattern>wp-content/plugins/some-plugin/</exclude-pattern> -->
</rule>
<!-- Disable checks alignment of assignment operators -->
<!-- Require 1 space character before and after assignment operators `=` -->
<rule ref="Generic.Formatting.MultipleStatementAlignment">
<properties>
<property name="alignAtEnd" value="false" />
<property name="maxPadding" value="1" />
</properties>
</rule>
<!-- Namespacing required for classes. -->
<!-- <rule ref="PSR1.Classes.ClassDeclaration" /> -->
<!-- Namespacing required for functions. -->
<!-- <rule ref="PSR2.Namespaces.NamespaceDeclaration" /> -->
<!-- Forbidden functions -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="delete" value="unset"/>
<element key="print" value="echo"/>
<element key="create_function" value="null"/>
<element key="sizeof" value="count"/>
<element key="var_dump" value="null"/>
<element key="print_r" value="null"/>
<element key="eval" value="null"/>
</property>
</properties>
</rule>
</ruleset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment