|
| 1 | +<?xml version="1.0"?> |
| 2 | +<ruleset name="TheWebSolver Codegarage Coding Standards"> |
| 3 | + <!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml --> |
| 4 | + <!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards --> |
| 5 | + <!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki --> |
| 6 | + <!-- See https://github.com/wimg/PHPCompatibility --> |
| 7 | + <!-- See https://tommcfarlin.com/php-codesniffer/ --> |
| 8 | + <!-- See https://tommcfarlin.com/php-codesniffer-in-visual-studio-code/ --> |
| 9 | + |
| 10 | + <!-- Set a description for this ruleset. --> |
| 11 | + <description>A custom set of code standard rules to check.</description> |
| 12 | + |
| 13 | + |
| 14 | + <!-- |
| 15 | + ############################################################################# |
| 16 | + COMMAND LINE ARGUMENTS |
| 17 | + https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml |
| 18 | + ############################################################################# |
| 19 | + --> |
| 20 | + |
| 21 | + <!-- Pass some flags to PHPCS: |
| 22 | + p flag: Show progress of the run. |
| 23 | + s flag: Show sniff codes in all reports. |
| 24 | + v flag: Print verbose output. |
| 25 | + n flag: Do not print warnings. |
| 26 | + --> |
| 27 | + <arg value="psvn"/> |
| 28 | + |
| 29 | + <!-- Check up to 8 files simultanously. --> |
| 30 | + <arg name="parallel" value="8"/> |
| 31 | + |
| 32 | + <!-- |
| 33 | + Only check the PHP, CSS and SCSS files. |
| 34 | + JS files are checked separately with ESLint. |
| 35 | + --> |
| 36 | + <arg name="extensions" value="php,css,scss/css"/> |
| 37 | + |
| 38 | + <!-- Check all files in this directory and the directories below it. --> |
| 39 | + <file>.</file> |
| 40 | + |
| 41 | + <!-- Exclude node modules --> |
| 42 | + <exclude-pattern>*/node_modules/*</exclude-pattern> |
| 43 | + |
| 44 | + <!-- Exclude vendors except first-party libraries. --> |
| 45 | + <exclude-pattern>*/vendor(?!\/thewebsolver\/).*</exclude-pattern> |
| 46 | + |
| 47 | + <!-- Ignore PHP files on asset directory. --> |
| 48 | + <exclude-pattern>*/assets/css*.php</exclude-pattern> |
| 49 | + <exclude-pattern>*/assets/js*.php</exclude-pattern> |
| 50 | + |
| 51 | + <!-- |
| 52 | + Set the minimum supported WP version. This is used by several sniffs. |
| 53 | + The minimum version set here should be in line with the minimum WP version |
| 54 | + as set in the "Requires at least" tag in the readme.txt file. |
| 55 | + --> |
| 56 | + <config name="minimum_supported_wp_version" value="6.4"/> |
| 57 | + <config name="testVersion" value="8.2"/> |
| 58 | + |
| 59 | + <!-- |
| 60 | + ############################################################################# |
| 61 | + USE THE WordPress-Coding-Standards RULESET |
| 62 | + ############################################################################# |
| 63 | + --> |
| 64 | + |
| 65 | + <rule ref="WordPress"/> |
| 66 | + <rule ref="WordPress-Core" /> |
| 67 | + <rule ref="WordPress-Docs" /> |
| 68 | + <rule ref="WordPress-Extra" /> |
| 69 | + |
| 70 | + <!-- |
| 71 | + ############################################################################# |
| 72 | + USE THE PHPCompatibility RULESET |
| 73 | + ############################################################################# |
| 74 | + --> |
| 75 | + |
| 76 | + <rule ref="PHPCompatibility" /> |
| 77 | + |
| 78 | + <!-- |
| 79 | + ############################################################################# |
| 80 | + SNIFF SPECIFIC CONFIGURATION |
| 81 | +
|
| 82 | + https://github-wiki-see.page/m/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties |
| 83 | + ############################################################################# |
| 84 | + --> |
| 85 | + |
| 86 | + <!-- |
| 87 | + Allow for named specific exceptions to the file name rules based |
| 88 | + on the directory hierarchy and ensure PSR-4 autoloading compatibility. |
| 89 | + - Remove strict class file name requirement. |
| 90 | + - Remove no hyphenated lowercase requirement. |
| 91 | + --> |
| 92 | + <rule ref="WordPress.Files.FileName"> |
| 93 | + <properties> |
| 94 | + <property name="strict_class_file_names" value="false" /> |
| 95 | + </properties> |
| 96 | + <exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" /> |
| 97 | + </rule> |
| 98 | + |
| 99 | + <rule ref="WordPress.Arrays.MultipleStatementAlignment"> |
| 100 | + <properties> |
| 101 | + <!-- No need to adjust alignment of large arrays when the item with the largest key is removed. --> |
| 102 | + <property name="exact" value="false"/> |
| 103 | + <!-- Don't align multi-line items if ALL items in the array are multi-line. --> |
| 104 | + <property name="alignMultilineItems" value="!=100"/> |
| 105 | + <!-- Array assignment operator should always be on the same line as the array key. --> |
| 106 | + <property name="ignoreNewlines" value="false"/> |
| 107 | + </properties> |
| 108 | + </rule> |
| 109 | + |
| 110 | + <!-- |
| 111 | + Since this happens rarely, we are whitelisting below sniffs. |
| 112 | + - When multiple variables need to be assigned the same value. |
| 113 | + - When variable needs to be assigned in the condition. |
| 114 | + --> |
| 115 | + <rule ref="Generic.CodeAnalysis.AssignmentInCondition"> |
| 116 | + <!-- |
| 117 | + Allow variable assignment in the condition. |
| 118 | + Eg: if( $x = file_exists( $y ) ) { require $x; } |
| 119 | + --> |
| 120 | + <exclude name="Generic.CodeAnalysis.AssignmentInCondition.Found" /> |
| 121 | + |
| 122 | + <!-- |
| 123 | + Allow variable assignment in the ternary operator. |
| 124 | + Eg: true === ( $z = file_exists( $y ) ) ? $z : $x; |
| 125 | + --> |
| 126 | + <exclude name="Generic.CodeAnalysis.AssignmentInCondition.FoundInTernaryCondition" /> |
| 127 | + <exclude name="Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition" /> |
| 128 | + </rule> |
| 129 | + |
| 130 | + <rule ref="WordPress.CodeAnalysis.AssignmentInTernaryCondition"> |
| 131 | + <exclude name="WordPress.CodeAnalysis.AssignmentInTernaryCondition.FoundInTernaryCondition"/> |
| 132 | + </rule> |
| 133 | + |
| 134 | + <rule ref="Squiz.PHP.DisallowMultipleAssignments"> |
| 135 | + <!-- |
| 136 | + Allow assignment in the control structure. |
| 137 | + Eg: if( $x = adding( $y + $z ) > 0 ) { return $x; } |
| 138 | + --> |
| 139 | + <exclude name="Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure" /> |
| 140 | + |
| 141 | + <!-- |
| 142 | + Allow multiple assignment in the same line. |
| 143 | + Eg: $x = $y = 'value' |
| 144 | + --> |
| 145 | + <exclude name="Squiz.PHP.DisallowMultipleAssignments.Found" /> |
| 146 | + </rule> |
| 147 | + |
| 148 | + <rule ref="Universal.Operators.DisallowShortTernary"> |
| 149 | + <!-- |
| 150 | + Allow short ternary operator. |
| 151 | + Eg: $x ?: $y |
| 152 | + --> |
| 153 | + <exclude name="Universal.Operators.DisallowShortTernary.Found" /> |
| 154 | + </rule> |
| 155 | + |
| 156 | + <!-- |
| 157 | + ############################################################################# |
| 158 | + IGNORE RULES SPECIFIC FILES AND DIRECTORIES |
| 159 | + ############################################################################# |
| 160 | + --> |
| 161 | + <rule ref="Squiz.Commenting"> |
| 162 | + <exclude name="Squiz.Commenting.FunctionComment.Missing"/> |
| 163 | + <exclude name="Squiz.Commenting.ClassComment.Missing"/> |
| 164 | + <exclude name="Squiz.Commenting.VariableComment.Missing"/> |
| 165 | + <exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop"/> |
| 166 | + <exclude name="Squiz.Commenting.FunctionComment.MissingParamComment"/> |
| 167 | + <exclude name="Squiz.Commenting.VariableComment.MissingVar"/> |
| 168 | + |
| 169 | + <!-- Assigning value to the non-snakeCased property. --> |
| 170 | + <exclude name="WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase"/> |
| 171 | + |
| 172 | + <!-- Comments can appear on same line as code. --> |
| 173 | + <exclude name="Squiz.Commenting.PostStatementComment.Found"/> |
| 174 | + |
| 175 | + <!-- Comments after param names in docComment. --> |
| 176 | + <exclude name="Squiz.Commenting.FunctionComment.MissingParamTag"/> |
| 177 | + |
| 178 | + </rule> |
| 179 | + |
| 180 | + <rule ref="Generic.Commenting.DocComment"> |
| 181 | + <exclude name="Generic.Commenting.DocComment.MissingShort"/> |
| 182 | + </rule> |
| 183 | + |
| 184 | + <rule ref="PSR12.Traits.UseDeclaration"> |
| 185 | + <exclude name="PSR12.Traits.UseDeclaration.MultipleImport"/> |
| 186 | + </rule> |
| 187 | + |
| 188 | + <rule ref="PSR12.Files.FileHeader"> |
| 189 | + <!-- Allow class-based use imports after function-based use imports in the file header. --> |
| 190 | + <exclude name="PSR12.Files.FileHeader.IncorrectOrder"/> |
| 191 | + |
| 192 | + <!-- Do not force to group imports by class and function. --> |
| 193 | + <exclude name="PSR12.Files.FileHeader.IncorrectGrouping"/> |
| 194 | + </rule> |
| 195 | + |
| 196 | + <!-- Allow setting param names as: "$object", "$default", "$abstract". --> |
| 197 | + <rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames"> |
| 198 | + <exclude name="Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound"/> |
| 199 | + <exclude name="Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound"/> |
| 200 | + <exclude name="Universal.NamingConventions.NoReservedKeywordParameterNames.abstractFound"/> |
| 201 | + </rule> |
| 202 | + |
| 203 | + <rule ref="WordPress.NamingConventions.ValidVariableName"> |
| 204 | + <exclude name="WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase"/> |
| 205 | + <exclude name="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase"/> |
| 206 | + <exclude name="WordPress.NamingConventions.ValidVariableName.InterpolatedVariableNotSnakeCase"/> |
| 207 | + </rule> |
| 208 | + |
| 209 | + <!-- |
| 210 | + Allow using "$this" for enum methods. Temp fix until PHPCompatibilityWP |
| 211 | + is updated to support PHPCompatibility v10.x. |
| 212 | + --> |
| 213 | + <rule ref="PHPCompatibility.Variables.ForbiddenThisUseContexts.OutsideObjectContext"> |
| 214 | + <exclude name="PHPCompatibility.Variables.ForbiddenThisUseContexts.OutsideObjectContext"/> |
| 215 | + </rule> |
| 216 | + |
| 217 | + <!-- Maintaining same format as enum's other default methods. --> |
| 218 | + <rule ref="WordPress.NamingConventions.ValidFunctionName"> |
| 219 | + <exclude name="WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid"/> |
| 220 | + <exclude name="WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid"/> |
| 221 | + </rule> |
| 222 | + |
| 223 | + <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"> |
| 224 | + <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed"/> |
| 225 | + </rule> |
| 226 | +</ruleset> |
0 commit comments