ruleset.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <?xml version="1.0"?>
  2. <!DOCTYPE ruleset SYSTEM "ruleset.dtd">
  3. <ruleset name="Dolibarr">
  4. <description>Dolibarr coding standard.</description>
  5. <arg name="tab-width" value="4"/>
  6. <arg name="extensions" value="php" />
  7. <!-- info: '*' is replaced with '.*', so better use '+' in some cases -->
  8. <!-- info: 'relative' paths are relative to the examined file, so not ok. -->
  9. <exclude-pattern>/build/(html|aps)/</exclude-pattern>
  10. <exclude-pattern>/dev/tools/test/namespacemig/</exclude-pattern>
  11. <!-- <exclude-pattern>dev/initdata/dbf/includes</exclude-pattern> -->
  12. <exclude-pattern>/documents/</exclude-pattern>
  13. <exclude-pattern>/htdocs/core/class/lessc\.class\.php</exclude-pattern>
  14. <exclude-pattern>/htdocs/(custom|includes)/</exclude-pattern>
  15. <exclude-pattern>/htdocs/install/doctemplates/websites</exclude-pattern>
  16. <exclude-pattern>/htdocs/([^/]+/)?conf\.php</exclude-pattern>
  17. <exclude-pattern>*/nltechno*</exclude-pattern>
  18. <exclude-pattern>/source/</exclude-pattern>
  19. <exclude-pattern>/\.git/</exclude-pattern>
  20. <exclude-pattern>/\.cache/</exclude-pattern>
  21. <!-- List of all tests -->
  22. <!-- Rules from Internal Standard -->
  23. <rule ref="Internal.NoCodeFound" />
  24. <!-- Rules from Generic Standard -->
  25. <!-- We want to allow empty statement: It allows to put some code comments into the else for examples -->
  26. <rule ref="Generic.CodeAnalysis.EmptyStatement">
  27. <exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedIf"/>
  28. <exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedElse"/>
  29. <exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedElseif"/>
  30. <exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/>
  31. <exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedForeach"/>
  32. </rule>
  33. <rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop" />
  34. <rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall" />
  35. <rule ref="Generic.CodeAnalysis.JumbledIncrementer" />
  36. <rule ref="Generic.CodeAnalysis.UnconditionalIfStatement" />
  37. <rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier" />
  38. <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter" />
  39. <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter.Found">
  40. <severity>0</severity>
  41. </rule>
  42. <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed">
  43. <severity>0</severity>
  44. </rule>
  45. <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed">
  46. <severity>0</severity>
  47. </rule>
  48. <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass">
  49. <severity>0</severity>
  50. </rule>
  51. <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed">
  52. <severity>0</severity>
  53. </rule>
  54. <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed">
  55. <severity>0</severity>
  56. </rule>
  57. <!-- Lower severity on warnings we do not want to show in the pre-commit reports -->
  58. <rule ref="Generic.Files.LineLength.TooLong">
  59. <severity>4</severity>
  60. </rule>
  61. <rule ref="Generic.Metrics.CyclomaticComplexity.TooHigh">
  62. <severity>4</severity>
  63. </rule>
  64. <rule ref="Generic.Metrics.NestingLevel.TooHigh">
  65. <severity>4</severity>
  66. </rule>
  67. <!-- Warnings on TODO -->
  68. <!-- Disabled: We want to keep TODO as normal
  69. <rule ref="Generic.Commenting.Todo" />
  70. -->
  71. <!-- PHP code MUST use only UTF-8 without BOM. -->
  72. <rule ref="Generic.Files.ByteOrderMark"/>
  73. <!-- Lines can be 85 chars long, but never show errors -->
  74. <rule ref="Generic.Files.LineLength">
  75. <properties>
  76. <property name="lineLimit" value="500" />
  77. <property name="absoluteLineLimit" value="0" />
  78. </properties>
  79. </rule>
  80. <!-- Use Unix newlines -->
  81. <rule ref="Generic.Files.LineEndings">
  82. <properties>
  83. <property name="eolChar" value="\n" />
  84. </properties>
  85. </rule>
  86. <!-- Disallow several statements on same line -->
  87. <!-- Warning if action on same line than if -->
  88. <!-- Disabled: We want to allow this for better code compactness and readability
  89. <rule ref="Generic.ControlStructures.InlineControlStructure">
  90. <properties>
  91. <property name="error" value="false"/>
  92. </properties>
  93. </rule>
  94. -->
  95. <!-- We want to allow 'if () { ...small code... }' on a single line for better code compactness and readability -->
  96. <!-- <rule ref="Generic.Formatting.DisallowMultipleStatements">
  97. <severity>0</severity>
  98. </rule> -->
  99. <!-- Check that assignments have the = aligned on each line. Have 20 chars padding maximum and always show as errors -->
  100. <!-- Disabled: Report some false warning
  101. <rule ref="Generic.Formatting.MultipleStatementAlignment">
  102. <properties>
  103. <property name="maxPadding" value="20"/>
  104. <property name="ignoreMultiLine" value="true"/>
  105. </properties>
  106. </rule>
  107. -->
  108. <rule ref="Generic.Formatting.SpaceAfterCast" />
  109. <rule ref="Generic.Functions.CallTimePassByReference" />
  110. <rule ref="Generic.Functions.FunctionCallArgumentSpacing" />
  111. <!-- Disallow several spaces after comma -->
  112. <!-- We want to allow this because we want to be able to align params on several similare functions on different lines -->
  113. <rule ref="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma">
  114. <severity>0</severity>
  115. </rule>
  116. <!-- Tweaks to metrics -->
  117. <rule ref="Generic.Metrics.CyclomaticComplexity">
  118. <properties>
  119. <property name="complexity" value="250" />
  120. <property name="absoluteComplexity" value="500" />
  121. </properties>
  122. </rule>
  123. <rule ref="Generic.Metrics.NestingLevel">
  124. <properties>
  125. <property name="nestingLevel" value="12" />
  126. <property name="absoluteNestingLevel" value="50" />
  127. </properties>
  128. </rule>
  129. <rule ref="Generic.NamingConventions.ConstructorName" />
  130. <!-- Check if we use PHP4 constructor instead of __construct() -->
  131. <rule ref="Generic.NamingConventions.ConstructorName.OldStyle" />
  132. <rule ref="Generic.NamingConventions.UpperCaseConstantName" />
  133. <rule ref="Generic.PHP.DeprecatedFunctions" />
  134. <rule ref="Generic.PHP.DeprecatedFunctions.Deprecated">
  135. <severity>0</severity>
  136. </rule>
  137. <rule ref="Generic.PHP.DisallowShortOpenTag" />
  138. <rule ref="Generic.PHP.ForbiddenFunctions" />
  139. <!-- Disable warning when using @ before functions -->
  140. <!-- We want the '@' symbols. Some features need this. -->
  141. <rule ref="Generic.PHP.NoSilencedErrors">
  142. <severity>0</severity>
  143. </rule>
  144. <!-- Say if null, true, false must be uppercase (Rule 2.5 of PSR2 https://www.php-fig.org/psr/psr-2/) -->
  145. <rule ref="Generic.PHP.LowerCaseConstant" />
  146. <rule ref="Generic.Strings.UnnecessaryStringConcat" />
  147. <rule ref="Generic.Strings.UnnecessaryStringConcat.Found">
  148. </rule>
  149. <!-- Disallow usage of space -->
  150. <rule ref="Generic.WhiteSpace.DisallowSpaceIndent" />
  151. <!-- Check indent are done with spaces and with correct number -->
  152. <!-- Disabled as this does not support tab -->
  153. <!-- <rule ref="Generic.WhiteSpace.ScopeIndent" /> -->
  154. <rule ref="Generic.WhiteSpace.ScopeIndent">
  155. <properties>
  156. <property name="indent" value="4"/>
  157. <property name="tabIndent" value="true"/>
  158. </properties>
  159. </rule>
  160. <!-- Check for duplicate class names -->
  161. <!-- Disabled: We need this for dependency injection.
  162. <rule ref="Generic.Classes.DuplicateClassName" />
  163. -->
  164. <!-- Rules from Squiz Standard -->
  165. <rule ref="Squiz.WhiteSpace.ScopeClosingBrace.Indent" />
  166. <!-- There MUST NOT be trailing whitespace at the end of non-blank lines. -->
  167. <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
  168. <properties>
  169. <property name="ignoreBlankLines" value="false"/>
  170. </properties>
  171. </rule>
  172. <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile" />
  173. <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile" />
  174. <!-- Disabled: We want to have 2 empty line as separator sometimes -->
  175. <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines" >
  176. <severity>0</severity>
  177. </rule>
  178. <rule ref="Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen" />
  179. <rule ref="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose" />
  180. <rule ref="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis" />
  181. <rule ref="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace" />
  182. <rule ref="Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword" />
  183. <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen" />
  184. <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose" />
  185. <rule ref="Squiz.Functions.MultiLineFunctionDeclaration" />
  186. <rule ref="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction" />
  187. <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
  188. <properties>
  189. <property name="equalsSpacing" value="1"/>
  190. </properties>
  191. </rule>
  192. <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint">
  193. <severity>0</severity>
  194. </rule>
  195. <rule ref="Squiz.Scope.MethodScope.Missing" />
  196. <!-- Rules from PEAR Standard -->
  197. <rule ref="PEAR.Classes.ClassDeclaration" />
  198. <rule ref="PEAR.Commenting.ClassComment" />
  199. <rule ref="PEAR.Commenting.ClassComment.Missing" />
  200. <rule ref="PEAR.Commenting.ClassComment.MissingTag" />
  201. <rule ref="PEAR.Commenting.ClassComment.MissingAuthorTag">
  202. <severity>0</severity>
  203. </rule>
  204. <rule ref="PEAR.Commenting.ClassComment.MissingCategoryTag">
  205. <severity>0</severity>
  206. </rule>
  207. <rule ref="PEAR.Commenting.ClassComment.MissingLicenseTag">
  208. <severity>0</severity>
  209. </rule>
  210. <rule ref="PEAR.Commenting.ClassComment.MissingLinkTag">
  211. <severity>0</severity>
  212. </rule>
  213. <rule ref="PEAR.Commenting.ClassComment.MissingPackageTag">
  214. <severity>0</severity>
  215. </rule>
  216. <rule ref="PEAR.Commenting.FunctionComment" />
  217. <rule ref="PEAR.Commenting.FunctionComment.Empty" />
  218. <rule ref="PEAR.Commenting.FunctionComment.SpacingAfterParamType" />
  219. <rule ref="PEAR.Commenting.FunctionComment.SpacingAfterParamName">
  220. <severity>0</severity>
  221. </rule>
  222. <rule ref="PEAR.Commenting.FunctionComment.SpacingAfterParamType">
  223. <severity>0</severity>
  224. </rule>
  225. <rule ref="PEAR.Commenting.FunctionComment.ReturnNotRequired" />
  226. <rule ref="PEAR.Commenting.FunctionComment.WrongStyle" />
  227. <rule ref="PEAR.Commenting.FunctionComment.SpacingBeforeParamType">
  228. <severity>0</severity>
  229. </rule>
  230. <rule ref="PEAR.Commenting.FunctionComment.SpacingAfterLongType">
  231. <severity>0</severity>
  232. </rule>
  233. <rule ref="PEAR.Commenting.FunctionComment.SpacingAfterLongName">
  234. <severity>0</severity>
  235. </rule>
  236. <rule ref="PEAR.Commenting.FunctionComment.SpacingAfterParams">
  237. <severity>0</severity>
  238. </rule>
  239. <rule ref="PEAR.Commenting.FunctionComment.ParameterCommentsNotAligned">
  240. <severity>0</severity>
  241. </rule>
  242. <rule ref="PEAR.Commenting.FunctionComment.ParameterNamesNotAligned">
  243. <severity>0</severity>
  244. </rule>
  245. <rule ref="PEAR.Commenting.InlineComment" />
  246. <!-- Check position of { after a control structure like if (), while (), etc... -->
  247. <!--
  248. <rule ref="PEAR.ControlStructures.ControlSignature" />
  249. -->
  250. <!-- <rule ref="PEAR.ControlStructures.MultiLineCondition" /> -->
  251. <!-- Test if () are removed for includes -->
  252. <rule ref="PEAR.Files.IncludingFile" />
  253. <!-- We disable this: We must be able to make require inside if -->
  254. <rule ref="PEAR.Files.IncludingFile.UseInclude">
  255. <severity>0</severity>
  256. </rule>
  257. <!-- We disable this. We must be allowed to use strict require instead of non strict include anywhere -->
  258. <rule ref="PEAR.Files.IncludingFile.UseIncludeOnce">
  259. <severity>0</severity>
  260. </rule>
  261. <rule ref="PEAR.Files.IncludingFile.UseRequire">
  262. <severity>0</severity>
  263. </rule>
  264. <!-- We disable this: We want to allow include_once -->
  265. <rule ref="PEAR.Files.IncludingFile.UseRequireOnce">
  266. <severity>0</severity>
  267. </rule>
  268. <rule ref="PEAR.Formatting.MultiLineAssignment" />
  269. <rule ref="PEAR.Functions.FunctionCallSignature" />
  270. <!-- We disable this: It returns a lot of false positive -->
  271. <rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine">
  272. <severity>0</severity>
  273. </rule>
  274. <!-- We disable this: We want to allow small function on 1 line -->
  275. <rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
  276. <severity>0</severity>
  277. </rule>
  278. <rule ref="PEAR.Functions.FunctionCallSignature.EmptyLine" />
  279. <!-- We disable this: Too many false positive -->
  280. <rule ref="PEAR.Functions.FunctionCallSignature.Indent">
  281. <severity>0</severity>
  282. </rule>
  283. <rule ref="PEAR.Functions.FunctionCallSignature.SpaceBeforeOpenBracket" />
  284. <rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterCloseBracket" />
  285. <rule ref="PEAR.Functions.ValidDefaultValue" />
  286. <rule ref="PEAR.NamingConventions.ValidClassName" />
  287. <rule ref="PEAR.NamingConventions.ValidClassName.Invalid">
  288. <severity>0</severity>
  289. </rule>
  290. <!-- We disable this: there is a lot of existing method not starting with a capital letter (class modXxxx, ...) -->
  291. <rule ref="PEAR.NamingConventions.ValidClassName.StartWithCapital">
  292. <severity>0</severity>
  293. </rule>
  294. <!-- some phpcs have a typo error in rule, so we add it this rule too with term "Captial" instead of "Capital" -->
  295. <rule ref="PEAR.NamingConventions.ValidClassName.StartWithCaptial">
  296. <severity>0</severity>
  297. </rule>
  298. <rule ref="PEAR.NamingConventions.ValidFunctionName" />
  299. <rule ref="PEAR.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore" />
  300. <!-- We disable this: there is a lot of existing function not starting with a capital letter (class modXxxx, ...) -->
  301. <rule ref="PEAR.NamingConventions.ValidFunctionName.FunctionNameInvalid">
  302. <severity>0</severity>
  303. </rule>
  304. <rule ref="PEAR.NamingConventions.ValidFunctionName.FunctionNoCapital">
  305. <severity>0</severity>
  306. </rule>
  307. <!-- some phpcs have a typo error in rule, so we add it this rule too with term "Captial" instead of "Capital" -->
  308. <rule ref="PEAR.NamingConventions.ValidFunctionName.FunctionNoCaptial">
  309. <severity>0</severity>
  310. </rule>
  311. <!--<rule ref="PEAR.NamingConventions.ValidFunctionName.NotCamelCaps">
  312. <severity>0</severity>
  313. </rule>-->
  314. <!--<rule ref="PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps">
  315. <severity>0</severity>
  316. </rule>-->
  317. <!-- We disable this: We don't want to have private methods prefixed with an underscore -->
  318. <rule ref="PEAR.NamingConventions.ValidFunctionName.PrivateNoUnderscore">
  319. <severity>0</severity>
  320. </rule>
  321. <rule ref="PEAR.NamingConventions.ValidVariableName" />
  322. <!-- This is not in PSR2 -->
  323. <!-- We disable this: We don't want to have private methods prefixed with an underscore -->
  324. <rule ref="PEAR.NamingConventions.ValidVariableName.PrivateNoUnderscore">
  325. <severity>0</severity>
  326. </rule>
  327. <rule ref="PEAR.WhiteSpace.ObjectOperatorIndent" />
  328. <!-- Need to be commented to be disabled
  329. <rule ref="PEAR.WhiteSpace.ScopeClosingBrace">
  330. <severity>0</severity>
  331. </rule>
  332. <rule ref="PEAR.WhiteSpace.ScopeClosingBrace.Line">
  333. <severity>0</severity>
  334. </rule>
  335. -->
  336. <!-- Already found as a Generic rule -->
  337. <!-- <rule ref="PEAR.WhiteSpace.ScopeIndent" /> -->
  338. <!-- Rules PSR 2 -->
  339. <rule ref="PSR2.Classes.ClassDeclaration" />
  340. <rule ref="PSR2.Methods.FunctionClosingBrace" />
  341. <rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed" />
  342. <rule ref="PSR2.Classes.ClassDeclaration" />
  343. <rule ref="PSR2.Methods.FunctionClosingBrace" />
  344. <rule ref="PSR2.Files.EndFileNewline.TooMany" />
  345. <rule ref="PSR2.Files.EndFileNewline.NoneFound" />
  346. <rule ref="PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket" />
  347. <rule ref="PSR2.Classes.PropertyDeclaration.VarUsed" />
  348. <!-- The closing ?> tag MUST be omitted from files containing only PHP. -->
  349. <rule ref="PSR2.Files.ClosingTag"/>
  350. </ruleset>