|
| 1 | +<?xml version="1.0"?> |
| 2 | +<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WP_CLI_CS_Feature_Files" xsi:noNamespaceSchemaLocation="../vendor/squizlabs/php_codesniffer/phpcs.xsd"> |
| 3 | + |
| 4 | + <description>Coding standard for the PHP blocks embedded in Behat feature files</description> |
| 5 | + |
| 6 | + <!-- |
| 7 | + The defaults for the code style check of the PHP blocks that Behat feature |
| 8 | + files embed in docstrings, used by `run-phpcs-tests` and by |
| 9 | + `run-phpcbf-cleanup`. |
| 10 | +
|
| 11 | + Keeping them in one place is what makes the check and the fixer agree: a |
| 12 | + sniff left out for one but not the other would have the fixer rewrite |
| 13 | + feature files over something the check never reports, or have the check |
| 14 | + report something the fixer refuses to touch. |
| 15 | +
|
| 16 | + A package replaces these defaults wholesale by adding a |
| 17 | + `phpcs-feature-files.xml` (or `phpcs-feature-files.xml.dist`) ruleset to its |
| 18 | + root, which is then used as the standard instead. |
| 19 | + --> |
| 20 | + |
| 21 | + <!-- Warnings are advisory, and the fixer must not rewrite a feature file |
| 22 | + over something the check does not report. --> |
| 23 | + <arg name="warning-severity" value="0"/> |
| 24 | + |
| 25 | + <rule ref="WP_CLI_CS"> |
| 26 | + |
| 27 | + <!-- |
| 28 | + A block is not a file. It is padded with one empty line per preceding |
| 29 | + line of the feature file so that reported line numbers match it, and one |
| 30 | + that does not bring its own opening tag is given one. Neither is part of |
| 31 | + the snippet, and the shared docstring indentation is taken off before the |
| 32 | + check and put back afterwards, so none of the sniffs looking at a file as |
| 33 | + a whole apply. |
| 34 | + --> |
| 35 | + <exclude name="Generic.Files.InlineHTML"/> |
| 36 | + <exclude name="Generic.Files.LineEndings"/> |
| 37 | + <exclude name="PSR2.Files.EndFileNewline"/> |
| 38 | + <exclude name="PSR12.Files.FileHeader"/> |
| 39 | + <exclude name="Squiz.Commenting.FileComment"/> |
| 40 | + <exclude name="Generic.PHP.RequireStrictTypes"/> |
| 41 | + <exclude name="WordPress.Files.FileName"/> |
| 42 | + <exclude name="Universal.WhiteSpace.PrecisionAlignment"/> |
| 43 | + |
| 44 | + <!-- |
| 45 | + A block is a fixture, not production code. Snippets exist to set up a |
| 46 | + scenario, run inside a throwaway WordPress installation, are written to |
| 47 | + be read at a glance, and are routinely a single class or function on |
| 48 | + their own. |
| 49 | + --> |
| 50 | + <exclude name="WordPress.NamingConventions.PrefixAllGlobals"/> |
| 51 | + <exclude name="WordPress.WP.GlobalVariablesOverride"/> |
| 52 | + <exclude name="WordPress.PHP.YodaConditions"/> |
| 53 | + <exclude name="Universal.Files.SeparateFunctionsFromOO"/> |
| 54 | + <exclude name="Generic.Files.OneObjectStructurePerFile"/> |
| 55 | + <exclude name="Universal.Namespaces.OneDeclarationPerFile"/> |
| 56 | + <exclude name="Universal.Namespaces.DisallowCurlyBraceSyntax"/> |
| 57 | + <exclude name="Universal.Namespaces.DisallowDeclarationWithoutName"/> |
| 58 | + <exclude name="PSR2.Methods.FunctionClosingBrace"/> |
| 59 | + |
| 60 | + <!-- A snippet testing error handling is deliberately incomplete. --> |
| 61 | + <exclude name="Generic.CodeAnalysis.EmptyStatement"/> |
| 62 | + |
| 63 | + <!-- A feature file indents with spaces. --> |
| 64 | + <exclude name="Generic.WhiteSpace.DisallowSpaceIndent"/> |
| 65 | + </rule> |
| 66 | + |
| 67 | + <!-- The other way round, so that a block arriving with tabs is brought in line. --> |
| 68 | + <rule ref="Generic.WhiteSpace.DisallowTabIndent"/> |
| 69 | + |
| 70 | + <rule ref="Generic.WhiteSpace.ScopeIndent"> |
| 71 | + <properties> |
| 72 | + <property name="tabIndent" value="false"/> |
| 73 | + </properties> |
| 74 | + </rule> |
| 75 | + |
| 76 | + <rule ref="WordPress.Arrays.ArrayIndentation"> |
| 77 | + <properties> |
| 78 | + <property name="tabIndent" value="false"/> |
| 79 | + </properties> |
| 80 | + </rule> |
| 81 | + |
| 82 | + <!-- |
| 83 | + The fixer leaves whitespace behind wherever it breaks a line, so this sniff |
| 84 | + has to run. Only the two message codes that look at the file as a whole are |
| 85 | + in the way: taking the padding off a block would shift every line number |
| 86 | + reported against the feature file it came from. |
| 87 | + --> |
| 88 | + <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"> |
| 89 | + <exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile"/> |
| 90 | + <exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile"/> |
| 91 | + </rule> |
| 92 | + |
| 93 | +</ruleset> |
0 commit comments