|
| 1 | +<?xml version="1.0"?> |
| 2 | +<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WP_CLI_CS" xsi:noNamespaceSchemaLocation="../vendor/squizlabs/php_codesniffer/phpcs.xsd"> |
| 3 | + |
| 4 | + <description>Coding standard for WP-CLI projects</description> |
| 5 | + |
| 6 | + <!-- |
| 7 | + To include this ruleset in a WP-CLI project, use `rule ref="WP_CLI_CS"` in brackets. |
| 8 | + See the instructions in the README/USING for an example. |
| 9 | +
|
| 10 | + For help using PHPCS: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage |
| 11 | + For help understanding this file: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml |
| 12 | + --> |
| 13 | + |
| 14 | + <!-- |
| 15 | + ############################################################################# |
| 16 | + COMMAND LINE ARGUMENTS |
| 17 | + ############################################################################# |
| 18 | + --> |
| 19 | + |
| 20 | + <!-- Ignoring select files/folders for all projects. |
| 21 | + https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders --> |
| 22 | + <exclude-pattern>*/.git/*</exclude-pattern> |
| 23 | + <exclude-pattern>*/node_modules/*</exclude-pattern> |
| 24 | + <exclude-pattern>*/vendor/*</exclude-pattern> |
| 25 | + |
| 26 | + |
| 27 | + <!-- |
| 28 | + ############################################################################# |
| 29 | + USE THE PHPCOMPATIBILITY RULESET |
| 30 | +
|
| 31 | + This checks code for PHP cross-version compatibility. |
| 32 | + See: https://github.com/PHPCompatibility/PHPCompatibility |
| 33 | + ############################################################################# |
| 34 | + --> |
| 35 | + |
| 36 | + <rule ref="PHPCompatibility"> |
| 37 | + <!-- Only scan PHP files for PHP compatibility. --> |
| 38 | + <include-pattern>*\.php$</include-pattern> |
| 39 | + |
| 40 | + <!-- Polyfill package is included with WP-CLI, so available to all projects. --> |
| 41 | + <exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_columnFound"/> |
| 42 | + </rule> |
| 43 | + |
| 44 | + <!-- |
| 45 | + ############################################################################# |
| 46 | + USE THE WORDPRESS-EXTRA RULESET |
| 47 | +
|
| 48 | + This checks code against the WordPress Core code style requirements, as well as |
| 49 | + a number of modern PHP style rules and other best practices which are |
| 50 | + currently not yet covered in the Core style handbook. |
| 51 | + See: https://make.wordpress.org/core/handbook/best-practices/coding-standards/ |
| 52 | + See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards |
| 53 | + ############################################################################# |
| 54 | + --> |
| 55 | + |
| 56 | + <rule ref="WordPress-Extra"> |
| 57 | + |
| 58 | + <!-- No need for this sniff as the parallel linter command takes care of linting. --> |
| 59 | + <exclude name="Generic.PHP.Syntax"/> |
| 60 | + |
| 61 | + <!-- To make autoloading easier, PSR-4 is mostly adhered to for file naming. --> |
| 62 | + <exclude name="WordPress.Files.FileName"/> |
| 63 | + |
| 64 | + <!-- Output is sent to cli, not to HTML, so this sniff is not applicable to WP-CLI. |
| 65 | + Note: some output escaping may still be needed/beneficial, however this would probably |
| 66 | + require a custom sniff. --> |
| 67 | + <exclude name="WordPress.Security.EscapeOutput"/> |
| 68 | + |
| 69 | + <!-- WP-CLI is intended as a developer tool, so using development functions should be fine. --> |
| 70 | + <exclude name="WordPress.PHP.DevelopmentFunctions"/> |
| 71 | + |
| 72 | + <!-- Make some allowance for the fact that the code will be run in a command-line environment. --> |
| 73 | + <exclude name="Generic.PHP.BacktickOperator"/> |
| 74 | + |
| 75 | + </rule> |
| 76 | + |
| 77 | + |
| 78 | + <!-- |
| 79 | + ############################################################################# |
| 80 | + SPECIFIC CONFIGURATION FOR SNIFFS |
| 81 | + ############################################################################# |
| 82 | + --> |
| 83 | + |
| 84 | + <!-- Verify that everything in the global namespace is either namespaced or prefixed. |
| 85 | + See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace --> |
| 86 | + <rule ref="WordPress.NamingConventions.PrefixAllGlobals"> |
| 87 | + <properties> |
| 88 | + <property name="prefixes" type="array"> |
| 89 | + <element value="WP_CLI"/><!-- Namespaces and non-namespaced classes. --> |
| 90 | + <element value="wpcli"/><!-- Global variables and functions. --> |
| 91 | + </property> |
| 92 | + </properties> |
| 93 | + </rule> |
| 94 | + |
| 95 | + <!-- Allow for silencing errors in combination with a select list of functions. |
| 96 | + See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#error-silencing-use-build-in-function-whitelist --> |
| 97 | + <rule ref="WordPress.PHP.NoSilencedErrors"> |
| 98 | + <properties> |
| 99 | + <property name="use_default_whitelist" value="true"/> |
| 100 | + </properties> |
| 101 | + </rule> |
| 102 | + |
| 103 | + <!-- Make some allowance for the fact that the code will be run in a command-line environment. |
| 104 | + See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#excluding-a-group-of-checks --> |
| 105 | + <rule ref="WordPress.PHP.DiscouragedPHPFunctions"> |
| 106 | + <properties> |
| 107 | + <property name="exclude" type="array"> |
| 108 | + <element value="runtime_configuration"/> |
| 109 | + <element value="system_calls"/> |
| 110 | + </property> |
| 111 | + </properties> |
| 112 | + </rule> |
| 113 | + |
| 114 | + <rule ref="WordPress.WP.AlternativeFunctions"> |
| 115 | + <properties> |
| 116 | + <property name="exclude" type="array"> |
| 117 | + <element value="curl"/> |
| 118 | + <element value="file_get_contents"/> |
| 119 | + <element value="file_system_read"/> |
| 120 | + <!-- As PHP 5.4. is the minimum for most projects, using json_encode() is fine. --> |
| 121 | + <element value="json_encode"/> |
| 122 | + </property> |
| 123 | + </properties> |
| 124 | + </rule> |
| 125 | + |
| 126 | +</ruleset> |
0 commit comments