|
| 1 | +<?xml version="1.0"?> |
| 2 | +<ruleset name="WordPress Core"> |
| 3 | + <description>Non-controversial generally-agreed upon WordPress Coding Standards</description> |
| 4 | + |
| 5 | + <!-- |
| 6 | + Handbook: PHP - Single and Double Quotes. |
| 7 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#single-and-double-quotes |
| 8 | + --> |
| 9 | + <!-- Covers rule: Use single and double quotes when appropriate. |
| 10 | + If you're not evaluating anything in the string, use single quotes. --> |
| 11 | + <rule ref="Squiz.Strings.DoubleQuoteUsage"/> |
| 12 | + <rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar"> |
| 13 | + <severity>0</severity> |
| 14 | + </rule> |
| 15 | + |
| 16 | + <!-- Rule: Text that goes into attributes should be run through esc_attr(). |
| 17 | + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/527 --> |
| 18 | + |
| 19 | + |
| 20 | + <!-- |
| 21 | + Handbook: PHP - Indentation. |
| 22 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#indentation |
| 23 | + --> |
| 24 | + <!-- Covers rule: Your indentation should always reflect logical structure. --> |
| 25 | + <rule ref="Generic.WhiteSpace.ScopeIndent"> |
| 26 | + <properties> |
| 27 | + <property name="indent" value="4"/> |
| 28 | + <property name="tabIndent" value="true"/> |
| 29 | + </properties> |
| 30 | + </rule> |
| 31 | + |
| 32 | + <!-- Covers rule: Use real tabs and not spaces. --> |
| 33 | + <arg name="tab-width" value="4"/> |
| 34 | + |
| 35 | + <!-- PATCH WordPress-Core-ns |
| 36 | + <rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/> |
| 37 | + --> |
| 38 | + |
| 39 | + <!-- Rule: For associative arrays, values should start on a new line. |
| 40 | + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/638 --> |
| 41 | + |
| 42 | + <!-- Covers rule: Note the comma after the last array item: this is recommended. --> |
| 43 | + <rule ref="WordPress.Arrays.ArrayDeclaration"> |
| 44 | + <exclude name="WordPress.Arrays.ArrayDeclaration.SingleLineNotAllowed" /> |
| 45 | + </rule> |
| 46 | + <rule ref="WordPress.Arrays.ArrayDeclarationSpacing"> |
| 47 | + <!-- Exclude the upstream checks which are already thrown by the |
| 48 | + WordPress.Arrays.ArrayDeclaration sniff. --> |
| 49 | + <exclude name="WordPress.Arrays.ArrayDeclarationSpacing.NotLowerCase" /> |
| 50 | + <exclude name="WordPress.Arrays.ArrayDeclarationSpacing.SpaceAfterKeyword" /> |
| 51 | + <exclude name="WordPress.Arrays.ArrayDeclarationSpacing.SpaceInEmptyArray" /> |
| 52 | + </rule> |
| 53 | + |
| 54 | + |
| 55 | + <!-- |
| 56 | + Handbook: PHP - Brace Style. |
| 57 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#brace-style |
| 58 | + --> |
| 59 | + <!-- Covers rule: Braces shall be used for all blocks. --> |
| 60 | + <rule ref="Squiz.ControlStructures.ControlSignature" /> |
| 61 | + <rule ref="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace"> |
| 62 | + <severity>0</severity> |
| 63 | + </rule> |
| 64 | + |
| 65 | + <!-- Covers rule: If you consider a long block unavoidable, please put a short comment at the end ... |
| 66 | + - typically this is appropriate for a logic block, longer than about 35 rows. --> |
| 67 | + <rule ref="Squiz.Commenting.LongConditionClosingComment"> |
| 68 | + <properties> |
| 69 | + <property name="lineLimit" value="35" /> |
| 70 | + <property name="commentFormat" value="// End %s()." /> |
| 71 | + </properties> |
| 72 | + <exclude name="Squiz.Commenting.LongConditionClosingComment.SpacingBefore" /> |
| 73 | + </rule> |
| 74 | + |
| 75 | + <!-- Covers rule: Braces should always be used, even when they are not required. --> |
| 76 | + <rule ref="Generic.ControlStructures.InlineControlStructure" /> |
| 77 | + |
| 78 | + |
| 79 | + <!-- |
| 80 | + Handbook: PHP - Use elseif, not else if. |
| 81 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#use-elseif-not-else-if |
| 82 | + --> |
| 83 | + <rule ref="PSR2.ControlStructures.ElseIfDeclaration"/> |
| 84 | + |
| 85 | + |
| 86 | + <!-- |
| 87 | + Handbook: PHP - Regular Expressions. |
| 88 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#regular-expressions |
| 89 | + --> |
| 90 | + <!-- Covers rule: Perl compatible regular expressions should be used in preference |
| 91 | + to their POSIX counterparts. --> |
| 92 | + <rule ref="WordPress.PHP.POSIXFunctions" /> |
| 93 | + |
| 94 | + <!-- Rule: Never use the /e switch, use preg_replace_callback instead. |
| 95 | + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/608 --> |
| 96 | + |
| 97 | + <!-- Rule: It's most convenient to use single-quoted strings for regular expressions. |
| 98 | + Already covered by Squiz.Strings.DoubleQuoteUsage --> |
| 99 | + |
| 100 | + |
| 101 | + <!-- |
| 102 | + Handbook: PHP - No Shorthand PHP Tags. |
| 103 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#no-shorthand-php-tags |
| 104 | + --> |
| 105 | + <!-- Covers rule: Never use shorthand PHP start tags. Always use full PHP tags. --> |
| 106 | + <rule ref="Generic.PHP.DisallowShortOpenTag"/> |
| 107 | + <rule ref="Generic.PHP.DisallowAlternativePHPTags"/> |
| 108 | + |
| 109 | + |
| 110 | + <!-- |
| 111 | + Handbook: PHP - Remove Trailing Spaces. |
| 112 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#remove-trailing-spaces |
| 113 | + --> |
| 114 | + <!-- Covers rule: Remove trailing whitespace at the end of each line of code. --> |
| 115 | + <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/> |
| 116 | + |
| 117 | + <!-- Covers rule: Omitting the closing PHP tag at the end of a file is preferred. --> |
| 118 | + <rule ref="PSR2.Files.ClosingTag"/> |
| 119 | + |
| 120 | + |
| 121 | + <!-- |
| 122 | + Handbook: PHP - Space Usage. |
| 123 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#space-usage |
| 124 | + --> |
| 125 | + <!-- Covers rule: Always put spaces after commas, and on both sides of logical, |
| 126 | + comparison, string and assignment operators. --> |
| 127 | + <rule ref="WordPress.WhiteSpace.OperatorSpacing"/> |
| 128 | + <rule ref="Squiz.Strings.ConcatenationSpacing"> |
| 129 | + <properties> |
| 130 | + <property name="spacing" value="1"/> |
| 131 | + <property name="ignoreNewlines" value="true"/> |
| 132 | + </properties> |
| 133 | + </rule> |
| 134 | + |
| 135 | + <!-- Covers rule: Put spaces on both sides of the opening and closing parenthesis of |
| 136 | + if, elseif, foreach, for, and switch blocks. --> |
| 137 | + <rule ref="WordPress.WhiteSpace.ControlStructureSpacing"/> |
| 138 | + |
| 139 | + <!-- Covers rule: Define a function like so: function my_function( $param1 = 'foo', $param2 = 'bar' ) { --> |
| 140 | + <rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie"/> |
| 141 | + <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing"> |
| 142 | + <properties> |
| 143 | + <property name="equalsSpacing" value="1" /> |
| 144 | + <property name="requiredSpacesAfterOpen" value="1" /> |
| 145 | + <property name="requiredSpacesBeforeClose" value="1" /> |
| 146 | + </properties> |
| 147 | + <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingBeforeClose" /> |
| 148 | + </rule> |
| 149 | + |
| 150 | + <!-- Covers rule: Call a function, like so: my_function( $param1, func_param( $param2 ) ); --> |
| 151 | + <rule ref="PEAR.Functions.FunctionCallSignature"> |
| 152 | + <properties> |
| 153 | + <property name="requiredSpacesAfterOpen" value="1" /> |
| 154 | + <property name="requiredSpacesBeforeClose" value="1" /> |
| 155 | + </properties> |
| 156 | + </rule> |
| 157 | + <rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket"> |
| 158 | + <severity>0</severity> |
| 159 | + </rule> |
| 160 | + <rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine"> |
| 161 | + <severity>0</severity> |
| 162 | + </rule> |
| 163 | + |
| 164 | + <!-- Rule: Perform logical comparisons, like so: if ( ! $foo ) { --> |
| 165 | + |
| 166 | + <!-- Covers rule: When type casting, do it like so: $foo = (boolean) $bar; --> |
| 167 | + <rule ref="Generic.Formatting.SpaceAfterCast"/> |
| 168 | + <rule ref="Squiz.WhiteSpace.CastSpacing" /> |
| 169 | + <rule ref="WordPress.WhiteSpace.CastStructureSpacing"/> |
| 170 | + |
| 171 | + <!-- Covers rule: ... array items, only include a space around the index if it is a variable. --> |
| 172 | + <rule ref="WordPress.Arrays.ArrayKeySpacingRestrictions"/> |
| 173 | + |
| 174 | + |
| 175 | + <!-- |
| 176 | + Handbook: PHP - Formatting SQL statements. |
| 177 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#formatting-sql-statements |
| 178 | + --> |
| 179 | + <!-- Rule: Always capitalize the SQL parts of the statement like UPDATE or WHERE. |
| 180 | + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/639 --> |
| 181 | + |
| 182 | + <!-- Rule: Functions that update the database should expect their parameters to lack |
| 183 | + SQL slash escaping when passed. |
| 184 | + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/640 --> |
| 185 | + |
| 186 | + <!-- Rule: in $wpdb->prepare - only %s and %d are used as placeholders. Note that they are not "quoted"! |
| 187 | + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/641 --> |
| 188 | + |
| 189 | + <!-- Covers rule: Escaping should be done as close to the time of the query as possible, |
| 190 | + preferably by using $wpdb->prepare() --> |
| 191 | + <rule ref="WordPress.WP.PreparedSQL"/> |
| 192 | + |
| 193 | + |
| 194 | + <!-- |
| 195 | + Handbook: PHP - Database Queries. |
| 196 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#database-queries |
| 197 | + --> |
| 198 | + <!-- Covers rule: Avoid touching the database directly. --> |
| 199 | + <rule ref="WordPress.DB.RestrictedFunctions"/> |
| 200 | + <rule ref="WordPress.DB.RestrictedClasses"/> |
| 201 | + |
| 202 | + |
| 203 | + <!-- |
| 204 | + Handbook: PHP - Naming Conventions. |
| 205 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#naming-conventions |
| 206 | + --> |
| 207 | + <!-- Covers rule: Use lowercase letters in variable, action, and function names. |
| 208 | + Separate words via underscores. --> |
| 209 | + <rule ref="WordPress.NamingConventions.ValidFunctionName"/> |
| 210 | + <rule ref="WordPress.NamingConventions.ValidHookName"/> |
| 211 | + <rule ref="WordPress.NamingConventions.ValidVariableName"/> |
| 212 | + |
| 213 | + <!-- Covers rule: Class names should use capitalized words separated by underscores. --> |
| 214 | + <rule ref="PEAR.NamingConventions.ValidClassName"/> |
| 215 | + |
| 216 | + <!-- Covers rule: Constants should be in all upper-case with underscores separating words. --> |
| 217 | + <rule ref="Generic.NamingConventions.UpperCaseConstantName"/> |
| 218 | + |
| 219 | + <!-- Covers rule: Files should be named descriptively using lowercase letters. |
| 220 | + Hyphens should separate words. --> |
| 221 | + <rule ref="Generic.Files.LowercasedFilename"/> |
| 222 | + <rule ref="WordPress.Files.FileName"/> |
| 223 | + |
| 224 | + <!-- Rule: Class file names should be based on the class name with "class-" |
| 225 | + prepended and the underscores in the class name replaced with hyphens. |
| 226 | + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/642 --> |
| 227 | + |
| 228 | + <!-- Rule: Files containing template tags in wp-includes should have "-template" |
| 229 | + appended to the end of the name. |
| 230 | + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/642 --> |
| 231 | + |
| 232 | + |
| 233 | + <!-- |
| 234 | + Handbook: PHP - Self-Explanatory Flag Values for Function Arguments. |
| 235 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#self-explanatory-flag-values-for-function-arguments |
| 236 | + --> |
| 237 | + |
| 238 | + |
| 239 | + <!-- |
| 240 | + Handbook: PHP - Ternary Operator. |
| 241 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#ternary-operator |
| 242 | + --> |
| 243 | + <!-- Rule: Always have Ternaries test if the statement is true, not false. |
| 244 | + An exception would be using ! empty(), as testing for false here is generally more intuitive. |
| 245 | + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/643 --> |
| 246 | + |
| 247 | + |
| 248 | + <!-- |
| 249 | + Handbook: PHP - Yoda Conditions. |
| 250 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#yoda-conditions |
| 251 | + --> |
| 252 | + <!-- Covers rule: When doing logical comparisons, always put the variable on the right side, |
| 253 | + constants or literals on the left. --> |
| 254 | + <rule ref="WordPress.PHP.YodaConditions"/> |
| 255 | + |
| 256 | + |
| 257 | + <!-- |
| 258 | + Handbook: PHP - Clever Code. |
| 259 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#clever-code |
| 260 | + --> |
| 261 | + <!-- Rule: In general, readability is more important than cleverness or brevity. |
| 262 | + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/607 --> |
| 263 | + |
| 264 | + |
| 265 | + <!-- |
| 266 | + Handbook: PHP - (No) Error Control Operator @. |
| 267 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#error-control-operator |
| 268 | + --> |
| 269 | + <rule ref="Generic.PHP.NoSilencedErrors" /> |
| 270 | + |
| 271 | + |
| 272 | + <!-- |
| 273 | + Handbook: PHP - Don't extract(). |
| 274 | + Ref: https://make.wordpress.org/core/handbook/coding-standards/php/#dont-extract |
| 275 | + --> |
| 276 | + <rule ref="WordPress.Functions.DontExtract"/> |
| 277 | + |
| 278 | + |
| 279 | + <!-- |
| 280 | + Not in the handbook: Generic sniffs. |
| 281 | + --> |
| 282 | + <!-- Important to prevent issues with content being sent before headers. --> |
| 283 | + <rule ref="Generic.Files.ByteOrderMark" /> |
| 284 | + |
| 285 | + <!-- All line endings should be \n. --> |
| 286 | + <rule ref="Generic.Files.LineEndings"> |
| 287 | + <properties> |
| 288 | + <property name="eolChar" value="\n"/> |
| 289 | + </properties> |
| 290 | + </rule> |
| 291 | + |
| 292 | + <!-- All files should end with a new line. --> |
| 293 | + <rule ref="Generic.Files.EndFileNewline"/> |
| 294 | + |
| 295 | + <!-- Lowercase PHP constants, like true, false and null. --> |
| 296 | + <!-- http://make.wordpress.org/core/handbook/coding-standards/php/#naming-conventions --> |
| 297 | + <rule ref="Generic.PHP.LowerCaseConstant"/> |
| 298 | + |
| 299 | + <!-- Lowercase PHP keywords, like class, function and case. --> |
| 300 | + <rule ref="Generic.PHP.LowerCaseKeyword"/> |
| 301 | + |
| 302 | + <!-- Class opening braces should be on the same line as the statement. --> |
| 303 | + <rule ref="Generic.Classes.OpeningBraceSameLine"/> |
| 304 | + |
| 305 | + |
| 306 | + <!-- |
| 307 | + Not in the coding standard handbook: WP specific sniffs. |
| 308 | + --> |
| 309 | + <!-- Check for correct usage of the WP i18n functions. --> |
| 310 | + <rule ref="WordPress.WP.I18n"/> |
| 311 | + |
| 312 | + |
| 313 | +</ruleset> |
0 commit comments