|
| 1 | +<?xml version="1.0"?> |
| 2 | +<!-- |
| 3 | +/** |
| 4 | + * Copyright Youwe. All rights reserved. |
| 5 | + * https://www.youweagency.com |
| 6 | + * |
| 7 | + * TODO:: Create a separate ruleset for phtml files, since a lot of exceptions need to be made just for adding phtml to code sniffer. |
| 8 | + */ |
| 9 | +--> |
| 10 | +<ruleset name="YouweMagento2"> |
| 11 | + <description>Youwe coding standards for Magento2 websites and modules</description> |
| 12 | + <!-- TODO:: Check if these values are correct. Did not see anything about how to configure this in documentation --> |
| 13 | + <arg name="extensions" value="php/PHP,phtml/PHP,js/JS,css/CSS,xml/XML,less/CSS" /> |
| 14 | + |
| 15 | + <!-- Base rules on Youwe --> |
| 16 | + <rule ref="Youwe"> |
| 17 | + <!-- Magento 2 does not use return types everywhere in the code base yet. So we cannot make this mandatory. --> |
| 18 | + <exclude name="GlobalCommon.Php7.ReturnType" /> |
| 19 | + <!-- Magento 2 still uses $_ to tell if it's protected, so we cannot mandate this. --> |
| 20 | + <exclude name="GlobalCommon.NamingConventions.ValidVariableName" /> |
| 21 | + <!-- TODO:: Check if this rule still needs to be excluded. Seems logical that all classes should start with camelcase --> |
| 22 | + <exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" /> |
| 23 | + <!--TODO:: Check if this should not be excluded. Seems logical to add throws in function comment. --> |
| 24 | + <exclude name="Squiz.Commenting.FunctionComment.EmptyThrows" /> |
| 25 | + <!-- Magento 2 still does not strict type arguments of functions. This is why this rule is excluded. --> |
| 26 | + <exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing" /> |
| 27 | + <!-- Magento 2 still does not strict type arguments of functions. This is why this rule is excluded. --> |
| 28 | + <exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing" /> |
| 29 | + </rule> |
| 30 | + |
| 31 | + <!-- Import most rules from official Magento2 coding standard --> |
| 32 | + <rule ref="Magento2"> |
| 33 | + <!-- Excluded because short descriptions are not mandatory in Youwe for a method. --> |
| 34 | + <exclude name="Magento2.Annotation" /> |
| 35 | + <!-- |
| 36 | + Excluded because in PHP 8.1 it's already possible to declare what type it is. |
| 37 | + Also most class properties are self-explanatory. |
| 38 | + --> |
| 39 | + <exclude name="Magento2.Commenting.ClassPropertyPHPDocFormatting" /> |
| 40 | + </rule> |
| 41 | + |
| 42 | + <!-- Detects function that use a for-loops call in their function. --> |
| 43 | + <rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed"> |
| 44 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 45 | + </rule> |
| 46 | + |
| 47 | + <rule ref="Generic.Commenting.DocComment"> |
| 48 | + <!-- default Magento 2 templates also not cohere to this. --> |
| 49 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 50 | + </rule> |
| 51 | + |
| 52 | + <rule ref="Generic.ControlStructures.InlineControlStructure.NotAllowed"> |
| 53 | + <!-- Magento 2 templates do not cohere to this rule. --> |
| 54 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 55 | + </rule> |
| 56 | + |
| 57 | + <rule ref="Generic.Files.LineLength.TooLong"> |
| 58 | + <!-- Magento 2 phtml & xml both have long lines think of checkout_index_index.xml --> |
| 59 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 60 | + <exclude-pattern>*.xml</exclude-pattern> |
| 61 | + </rule> |
| 62 | + |
| 63 | + <rule ref="PEAR.Functions.FunctionCallSignature"> |
| 64 | + <!-- default Magento 2 templates also not cohere to this. --> |
| 65 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 66 | + </rule> |
| 67 | + |
| 68 | + <rule ref="PSR2.Classes.PropertyDeclaration.Underscore"> |
| 69 | + <!-- In some cases Magento 2 still uses underscores for their properties. --> |
| 70 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 71 | + </rule> |
| 72 | + |
| 73 | + <rule ref="PSR2.ControlStructures.ControlStructureSpacing"> |
| 74 | + <!-- default Magento 2 templates also not cohere to this. --> |
| 75 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 76 | + </rule> |
| 77 | + |
| 78 | + <rule ref="PSR12.ControlStructures.ControlStructureSpacing"> |
| 79 | + <!-- default Magento 2 templates also not cohere to this. --> |
| 80 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 81 | + </rule> |
| 82 | + |
| 83 | + <rule ref="PSR12.Files.FileHeader.SpacingAfterBlock"> |
| 84 | + <!-- default Magento 2 templates also not cohere to this. --> |
| 85 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 86 | + </rule> |
| 87 | + |
| 88 | + <rule ref="PSR12.Operators.OperatorSpacing"> |
| 89 | + <!-- default Magento 2 templates also not cohere to this. --> |
| 90 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 91 | + </rule> |
| 92 | + |
| 93 | + <rule ref="Squiz.ControlStructures.ControlSignature"> |
| 94 | + <!-- Magento 2 uses a different notation for patterns like do { / if { for phtml that's why this was excluded. --> |
| 95 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 96 | + </rule> |
| 97 | + |
| 98 | + <rule ref="Squiz.WhiteSpace.ControlStructureSpacing"> |
| 99 | + <!-- default Magento 2 templates also not cohere to this. --> |
| 100 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 101 | + </rule> |
| 102 | + |
| 103 | + <rule ref="Squiz.WhiteSpace.MemberVarSpacing" > |
| 104 | + <properties> |
| 105 | + <property name="spacingBeforeFirst" value="0"/> |
| 106 | + </properties> |
| 107 | + </rule> |
| 108 | + |
| 109 | + <rule ref="Squiz.WhiteSpace.ScopeClosingBrace"> |
| 110 | + <!-- Magento 2 phptml files end differently and use endif; for example. --> |
| 111 | + <exclude-pattern>*.phtml</exclude-pattern> |
| 112 | + </rule> |
| 113 | +</ruleset> |
0 commit comments