Skip to content

Instantly share code, notes, and snippets.

@DamChtlv
Created February 4, 2020 14:00
Show Gist options
  • Save DamChtlv/c563cfc153a40b7d097cbf342cbc00c4 to your computer and use it in GitHub Desktop.
Save DamChtlv/c563cfc153a40b7d097cbf342cbc00c4 to your computer and use it in GitHub Desktop.
Personal PHPCS ruleset for linting & formatting based on WordPress & Pilot'In
<?xml version="1.0"?>
<ruleset name="PilotIn">
<description>Pilot'In Coding Standards</description>
<!-- To customize properties: -->
<!-- https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<!-- https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/WordPress-Core/ruleset.xml -->
<!-- https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/WordPress-Docs/ruleset.xml -->
<!-- https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/WordPress-Extra/ruleset.xml -->
<!-- https://github.com/olefredrik/FoundationPress/blob/master/codesniffer.ruleset.xml -->
<rule ref="WordPress">
<!-- Allow "Commented out code" -->
<exclude name="Squiz.PHP.CommentedOutCode" />
<!-- Allow "Missing comments" -->
<exclude name="Squiz.Commenting.InlineComment" />
<exclude name="Squiz.Commenting.FileComment" />
<exclude name="Squiz.Commenting.FunctionComment" />
<!-- Allow "Space indent" -->
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent" />
<!-- Prevent duplicate messages + deprecation notice from deprecated sniff. -->
<exclude name="WordPress.WP.TimezoneChange.timezone_change_date_default_timezone_set" />
<exclude name="WordPress.WP.TimezoneChange.DeprecatedSniff" />
<!-- Disable Yoda conditions check. -->
<exclude name="WordPress.PHP.YodaConditions" />
<!-- Allow "Default spacing" for functions & conditions -->
<exclude name="Generic.Functions.FunctionCallArgumentSpacing" />
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterOpenParenthesis" />
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeCloseParenthesis" />
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpenHint" />
<!-- Allow "Default array" handling -->
<exclude name="WordPress.Arrays.ArrayDeclaration.NoSpaceAfterOpenParenthesis" />
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing.NoSpaceAfterArrayOpener" />
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing.NoSpaceBeforeArrayCloser" />
<!-- Allow "Escaped output" not mandatory -->
<exclude name="WordPress.XSS.EscapeOutput.UnsafePrintingFunction" />
<exclude name="WordPress.XSS.EscapeOutput.OutputNotEscaped" />
</rule>
<!-- No space inside function parentheses -->
<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="requiredSpacesAfterOpen" value="0" />
<property name="requiredSpacesBeforeClose" value="0" />
<property name="allowMultipleArguments" value="true" />
</properties>
<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket"/>
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine"/>
</rule>
<rule ref="PSR2.ControlStructures.ControlStructureSpacing">
<properties>
<property name="requiredSpacesAfterOpen" value="0" />
<property name="requiredSpacesBeforeClose" value="0" />
</properties>
</rule>
<rule ref="Generic.WhiteSpace.ArbitraryParenthesesSpacing">
<properties>
<property name="spacing" value="0" />
<property name="ignoreNewlines" value="true" />
</properties>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="0" />
<property name="requiredSpacesAfterOpen" value="0" />
<property name="requiredSpacesBeforeClose" value="0" />
</properties>
</rule>
<!-- No space after not -->
<rule ref="Generic.Formatting.SpaceAfterNot">
<properties>
<property name="spacing" value="0" />
</properties>
</rule>
<!-- Add extra words delimiter for hook names -->
<rule ref="WordPress.NamingConventions.ValidHookName">
<properties>
<property name="additionalWordDelimiters" value="-/." />
</properties>
</rule>
</ruleset>
@DamChtlv
Copy link
Author

DamChtlv commented Feb 4, 2020

Add this to settings.json in VSCode:

/** Formatte le code selon les standards "PilotIn" */
    "phpcs.standard": "PilotIn",
    "phpcbf.standard": "PilotIn",
    "phpcbf.debug": true,
    "phpcbf.executablePath": "phpcbf.bat",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment