Skip to content

Instantly share code, notes, and snippets.

@drazenbebic
Created May 16, 2024 07:18
Show Gist options
  • Save drazenbebic/75e2237dbbbab681be429e7b92a6f014 to your computer and use it in GitHub Desktop.
Save drazenbebic/75e2237dbbbab681be429e7b92a6f014 to your computer and use it in GitHub Desktop.
Example PHP Code Sniffer Configuration File for WordPress
<?xml version="1.0" ?>
<ruleset
name="MyProject"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"
>
<description>My Project Coding Standard</description>
<!-- Set the coding standard -->
<rule ref="WordPress">
<!-- Exclude specific rules -->
<exclude name="Generic.Commenting.DocComment"/>
<exclude name="Squiz.Commenting.ClassComment"/>
<exclude name="Squiz.Commenting.FileComment"/>
<exclude name="Universal.Operators.DisallowShortTernary"/>
<exclude name="WordPress.Files.FileName"/>
<exclude name="WordPress.PHP.YodaConditions"/>
<exclude name="WordPress.Security.NonceVerification"/>
</rule>
<!-- Add the text domain -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="my-plugin"/>
</property>
</properties>
</rule>
<!-- Add custom capabilities -->
<rule ref="WordPress.WP.Capabilities">
<properties>
<property name="custom_capabilities" type="array">
<element value="manage_my_plugin"/>
</property>
</properties>
</rule>
<!-- Add custom sanitization functions -->
<rule ref="WordPress.Security.ValidatedSanitizedInput">
<properties>
<property name="customSanitizingFunctions" type="array">
<element value="my_plugin_clean_string"/>
</property>
</properties>
</rule>
<!-- Set the target directories -->
<file>my-plugin.php</file>
<file>includes</file>
<!-- Set the excluded directories -->
<exclude-pattern>./vendor/*</exclude-pattern>
<exclude-pattern>./tests/*</exclude-pattern>
<!-- Set the options -->
<arg name="extensions" value="php,inc"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs.cache"/>
</ruleset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment