@specs-feup/clava-misra 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/.gitignore +8 -0
  2. package/README.md +53 -19
  3. package/dist/MISRA.d.ts +28 -10
  4. package/dist/MISRA.d.ts.map +1 -1
  5. package/dist/MISRA.js +30 -10
  6. package/dist/MISRA.js.map +1 -1
  7. package/dist/MISRAContext.d.ts +65 -11
  8. package/dist/MISRAContext.d.ts.map +1 -1
  9. package/dist/MISRAContext.js +131 -35
  10. package/dist/MISRAContext.js.map +1 -1
  11. package/dist/MISRARule.d.ts +38 -25
  12. package/dist/MISRARule.d.ts.map +1 -1
  13. package/dist/MISRARule.js +40 -18
  14. package/dist/MISRARule.js.map +1 -1
  15. package/dist/MISRATool.d.ts +46 -5
  16. package/dist/MISRATool.d.ts.map +1 -1
  17. package/dist/MISRATool.js +118 -45
  18. package/dist/MISRATool.js.map +1 -1
  19. package/dist/StandardGuideline.d.ts +22 -0
  20. package/dist/StandardGuideline.d.ts.map +1 -0
  21. package/dist/StandardGuideline.js +12 -0
  22. package/dist/StandardGuideline.js.map +1 -0
  23. package/dist/ast-visitor/Context.d.ts +11 -0
  24. package/dist/ast-visitor/Context.d.ts.map +1 -0
  25. package/dist/ast-visitor/Context.js +15 -0
  26. package/dist/ast-visitor/Context.js.map +1 -0
  27. package/dist/ast-visitor/Visit.d.ts +23 -0
  28. package/dist/ast-visitor/Visit.d.ts.map +1 -0
  29. package/dist/ast-visitor/Visit.js +18 -0
  30. package/dist/ast-visitor/Visit.js.map +1 -0
  31. package/dist/ast-visitor/VisitWithContext.d.ts +32 -0
  32. package/dist/ast-visitor/VisitWithContext.d.ts.map +1 -0
  33. package/dist/ast-visitor/VisitWithContext.js +26 -0
  34. package/dist/ast-visitor/VisitWithContext.js.map +1 -0
  35. package/dist/main.js +1 -2
  36. package/dist/main.js.map +1 -1
  37. package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.d.ts +27 -0
  38. package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.d.ts.map +1 -0
  39. package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.js +98 -0
  40. package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.js.map +1 -0
  41. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts +45 -6
  42. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts.map +1 -1
  43. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js +91 -8
  44. package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js.map +1 -1
  45. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts +15 -5
  46. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts.map +1 -1
  47. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js +20 -6
  48. package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js.map +1 -1
  49. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts +11 -5
  50. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts.map +1 -1
  51. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js +13 -10
  52. package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js.map +1 -1
  53. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts +11 -6
  54. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts.map +1 -1
  55. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js +19 -11
  56. package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js.map +1 -1
  57. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts +15 -5
  58. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts.map +1 -1
  59. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js +24 -10
  60. package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js.map +1 -1
  61. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts +22 -6
  62. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts.map +1 -1
  63. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js +37 -10
  64. package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js.map +1 -1
  65. package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.d.ts +66 -0
  66. package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.d.ts.map +1 -0
  67. package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.js +209 -0
  68. package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.js.map +1 -0
  69. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts +37 -12
  70. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts.map +1 -1
  71. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js +112 -39
  72. package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js.map +1 -1
  73. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts +15 -5
  74. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts.map +1 -1
  75. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js +21 -7
  76. package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js.map +1 -1
  77. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts +11 -6
  78. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts.map +1 -1
  79. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js +17 -8
  80. package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js.map +1 -1
  81. package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.d.ts +105 -0
  82. package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.d.ts.map +1 -0
  83. package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.js +258 -0
  84. package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.js.map +1 -0
  85. package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.d.ts +25 -0
  86. package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.d.ts.map +1 -0
  87. package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.js +27 -0
  88. package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.js.map +1 -0
  89. package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.d.ts +29 -0
  90. package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.d.ts.map +1 -0
  91. package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.js +31 -0
  92. package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.js.map +1 -0
  93. package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.d.ts +25 -0
  94. package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.d.ts.map +1 -0
  95. package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.js +27 -0
  96. package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.js.map +1 -0
  97. package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.d.ts +25 -0
  98. package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.d.ts.map +1 -0
  99. package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.js +27 -0
  100. package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.js.map +1 -0
  101. package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.d.ts +25 -0
  102. package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.d.ts.map +1 -0
  103. package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.js +27 -0
  104. package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.js.map +1 -0
  105. package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.d.ts +30 -0
  106. package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.d.ts.map +1 -0
  107. package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.js +32 -0
  108. package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.js.map +1 -0
  109. package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.d.ts +25 -0
  110. package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.d.ts.map +1 -0
  111. package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.js +27 -0
  112. package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.js.map +1 -0
  113. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts +6 -14
  114. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts.map +1 -1
  115. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js +17 -27
  116. package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js.map +1 -1
  117. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts +13 -7
  118. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts.map +1 -1
  119. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js +31 -17
  120. package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js.map +1 -1
  121. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts +26 -7
  122. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts.map +1 -1
  123. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js +32 -14
  124. package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js.map +1 -1
  125. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts +48 -6
  126. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts.map +1 -1
  127. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js +84 -34
  128. package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js.map +1 -1
  129. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts +24 -5
  130. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts.map +1 -1
  131. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js +27 -7
  132. package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js.map +1 -1
  133. package/dist/rules/Section5_Identifiers/IdentifierRenameRule.d.ts +46 -0
  134. package/dist/rules/Section5_Identifiers/IdentifierRenameRule.d.ts.map +1 -0
  135. package/dist/rules/Section5_Identifiers/IdentifierRenameRule.js +40 -0
  136. package/dist/rules/Section5_Identifiers/IdentifierRenameRule.js.map +1 -0
  137. package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.d.ts +25 -0
  138. package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.d.ts.map +1 -0
  139. package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.js +46 -0
  140. package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.js.map +1 -0
  141. package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.d.ts +26 -0
  142. package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.d.ts.map +1 -0
  143. package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.js +54 -0
  144. package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.js.map +1 -0
  145. package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.d.ts +27 -0
  146. package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.d.ts.map +1 -0
  147. package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.js +55 -0
  148. package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.js.map +1 -0
  149. package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.d.ts +24 -0
  150. package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.d.ts.map +1 -0
  151. package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.js +42 -0
  152. package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.js.map +1 -0
  153. package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.d.ts +24 -0
  154. package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.d.ts.map +1 -0
  155. package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.js +42 -0
  156. package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.js.map +1 -0
  157. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.d.ts +35 -0
  158. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.d.ts.map +1 -0
  159. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.js +98 -0
  160. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.js.map +1 -0
  161. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.d.ts +35 -0
  162. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.d.ts.map +1 -0
  163. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.js +76 -0
  164. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.js.map +1 -0
  165. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.d.ts +32 -0
  166. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.d.ts.map +1 -0
  167. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.js +57 -0
  168. package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.js.map +1 -0
  169. package/dist/rules/UserConfigurableRule.d.ts +55 -0
  170. package/dist/rules/UserConfigurableRule.d.ts.map +1 -0
  171. package/dist/rules/UserConfigurableRule.js +16 -0
  172. package/dist/rules/UserConfigurableRule.js.map +1 -0
  173. package/dist/rules/index.d.ts +11 -18
  174. package/dist/rules/index.d.ts.map +1 -1
  175. package/dist/rules/index.js +47 -7
  176. package/dist/rules/index.js.map +1 -1
  177. package/dist/tests/Section17_Functions/misra_config.json +10 -0
  178. package/dist/tests/Section21-StandardLibraries/misra_config.json +88 -0
  179. package/dist/tests/Section21-StandardLibraries/problematic_misra_config.json +19 -0
  180. package/dist/tests/utils.d.ts +6 -3
  181. package/dist/tests/utils.d.ts.map +1 -1
  182. package/dist/tests/utils.js +33 -7
  183. package/dist/tests/utils.js.map +1 -1
  184. package/dist/utils/CallUtils.d.ts +15 -0
  185. package/dist/utils/CallUtils.d.ts.map +1 -0
  186. package/dist/utils/CallUtils.js +34 -0
  187. package/dist/utils/CallUtils.js.map +1 -0
  188. package/dist/utils/CommentUtils.d.ts +21 -0
  189. package/dist/utils/CommentUtils.d.ts.map +1 -0
  190. package/dist/utils/CommentUtils.js +27 -0
  191. package/dist/utils/CommentUtils.js.map +1 -0
  192. package/dist/utils/FileUtils.d.ts +67 -0
  193. package/dist/utils/FileUtils.d.ts.map +1 -0
  194. package/dist/utils/FileUtils.js +144 -0
  195. package/dist/utils/FileUtils.js.map +1 -0
  196. package/dist/utils/FunctionUtils.d.ts +47 -0
  197. package/dist/utils/FunctionUtils.d.ts.map +1 -0
  198. package/dist/utils/FunctionUtils.js +87 -0
  199. package/dist/utils/FunctionUtils.js.map +1 -0
  200. package/dist/utils/IdentifierUtils.d.ts +63 -0
  201. package/dist/utils/IdentifierUtils.d.ts.map +1 -0
  202. package/dist/utils/IdentifierUtils.js +133 -0
  203. package/dist/utils/IdentifierUtils.js.map +1 -0
  204. package/dist/utils/JoinpointUtils.d.ts +36 -0
  205. package/dist/utils/JoinpointUtils.d.ts.map +1 -0
  206. package/dist/utils/JoinpointUtils.js +63 -0
  207. package/dist/utils/JoinpointUtils.js.map +1 -0
  208. package/dist/utils/ProgramUtils.d.ts +39 -0
  209. package/dist/utils/ProgramUtils.d.ts.map +1 -0
  210. package/dist/utils/ProgramUtils.js +97 -0
  211. package/dist/utils/ProgramUtils.js.map +1 -0
  212. package/dist/utils/SwitchUtils.d.ts +21 -0
  213. package/dist/utils/SwitchUtils.d.ts.map +1 -0
  214. package/dist/utils/SwitchUtils.js +47 -0
  215. package/dist/utils/SwitchUtils.js.map +1 -0
  216. package/dist/utils/TypeDeclUtils.d.ts +35 -0
  217. package/dist/utils/TypeDeclUtils.d.ts.map +1 -0
  218. package/dist/utils/TypeDeclUtils.js +78 -0
  219. package/dist/utils/TypeDeclUtils.js.map +1 -0
  220. package/dist/utils/VarUtils.d.ts +51 -0
  221. package/dist/utils/VarUtils.d.ts.map +1 -0
  222. package/dist/utils/VarUtils.js +91 -0
  223. package/dist/utils/VarUtils.js.map +1 -0
  224. package/package.json +16 -7
  225. package/src/MISRA.ts +33 -17
  226. package/src/MISRAContext.ts +128 -30
  227. package/src/MISRARule.ts +61 -29
  228. package/src/MISRATool.ts +126 -42
  229. package/src/StandardGuideline.ts +23 -0
  230. package/src/ast-visitor/Context.ts +16 -0
  231. package/src/ast-visitor/Visit.ts +26 -0
  232. package/src/ast-visitor/VisitWithContext.ts +42 -0
  233. package/src/main.ts +1 -4
  234. package/src/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.ts +114 -0
  235. package/src/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.ts +103 -13
  236. package/src/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.ts +24 -10
  237. package/src/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.ts +17 -8
  238. package/src/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.ts +20 -12
  239. package/src/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.ts +23 -12
  240. package/src/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.ts +44 -13
  241. package/src/rules/Section17_Functions/Rule_17_3_ImplicitFunction.ts +153 -104
  242. package/src/rules/Section17_Functions/Rule_17_4_NonVoidReturn.ts +114 -44
  243. package/src/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.ts +27 -10
  244. package/src/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.ts +20 -12
  245. package/src/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.ts +317 -0
  246. package/src/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.ts +30 -0
  247. package/src/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.ts +35 -0
  248. package/src/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.ts +30 -0
  249. package/src/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.ts +30 -0
  250. package/src/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.ts +29 -0
  251. package/src/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.ts +36 -0
  252. package/src/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.ts +30 -0
  253. package/src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts +14 -29
  254. package/src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts +33 -19
  255. package/src/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.ts +33 -20
  256. package/src/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.ts +90 -45
  257. package/src/rules/Section3_Comments/Rule_3_1_CommentSequences.ts +27 -8
  258. package/src/rules/Section5_Identifiers/IdentifierRenameRule.ts +63 -0
  259. package/src/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.ts +52 -0
  260. package/src/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.ts +62 -0
  261. package/src/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.ts +61 -0
  262. package/src/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.ts +47 -0
  263. package/src/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.ts +47 -0
  264. package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.ts +118 -0
  265. package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.ts +89 -0
  266. package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.ts +65 -0
  267. package/src/rules/UserConfigurableRule.ts +60 -0
  268. package/src/rules/index.ts +45 -7
  269. package/src/tests/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.test.ts +114 -0
  270. package/src/tests/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.test.ts +7 -5
  271. package/src/tests/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.test.ts +40 -13
  272. package/src/tests/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.test.ts +10 -12
  273. package/src/tests/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.test.ts +5 -5
  274. package/src/tests/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.test.ts +5 -5
  275. package/src/tests/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.test.ts +5 -5
  276. package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions.test.ts +68 -40
  277. package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions_MissingConfig.test.ts +98 -0
  278. package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions_ProblematicConfig.test.ts +71 -0
  279. package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn.test.ts +103 -49
  280. package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn_MissingConfig.test.ts +7 -7
  281. package/src/tests/Section17_Functions/Rule_17_6_StaticArraySizeParam.test.ts +36 -7
  282. package/src/tests/Section17_Functions/Rule_17_7_UnusedReturnValue.test.ts +25 -21
  283. package/src/tests/Section17_Functions/misra_config.json +4 -3
  284. package/src/tests/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.test.ts +62 -0
  285. package/src/tests/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.test.ts +67 -0
  286. package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.test.ts +84 -0
  287. package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory_MissingConfig.test.ts +33 -0
  288. package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory_ProblematicConfig.test.ts +71 -0
  289. package/src/tests/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.test.ts +63 -0
  290. package/src/tests/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.test.ts +91 -0
  291. package/src/tests/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.test.ts +65 -0
  292. package/src/tests/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.test.ts +89 -0
  293. package/src/tests/Section21-StandardLibraries/misra_config.json +88 -0
  294. package/src/tests/Section21-StandardLibraries/problematic_misra_config.json +19 -0
  295. package/src/tests/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.test.ts +148 -113
  296. package/src/tests/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.test.ts +243 -163
  297. package/src/tests/Section2_UnusedCode/Rule_2_6_UnusedLabels.test.ts +32 -20
  298. package/src/tests/Section2_UnusedCode/Rule_2_7_UnusedParameters.test.ts +36 -30
  299. package/src/tests/Section3_Comments/Rule_3_1_CommentSequences.test.ts +37 -8
  300. package/src/tests/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.test.ts +78 -0
  301. package/src/tests/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.test.ts +120 -0
  302. package/src/tests/Section5_Identifiers/Rule_5_7_UniqueTagNames.test.ts +51 -0
  303. package/src/tests/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.test.ts +73 -0
  304. package/src/tests/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.test.ts +97 -0
  305. package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.test.ts +160 -0
  306. package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.test.ts +46 -0
  307. package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.test.ts +69 -0
  308. package/src/tests/utils.ts +32 -7
  309. package/src/utils/CallUtils.ts +37 -0
  310. package/src/utils/CommentUtils.ts +29 -0
  311. package/src/utils/FileUtils.ts +169 -0
  312. package/src/utils/FunctionUtils.ts +97 -0
  313. package/src/utils/IdentifierUtils.ts +142 -0
  314. package/src/utils/JoinpointUtils.ts +70 -0
  315. package/src/utils/ProgramUtils.ts +107 -0
  316. package/src/utils/SwitchUtils.ts +52 -0
  317. package/src/utils/TypeDeclUtils.ts +88 -0
  318. package/src/utils/VarUtils.ts +102 -0
  319. package/tsconfig.json +2 -1
  320. package/src/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.ts +0 -120
  321. package/src/rules/Section3_Comments/Rule_3_2_LineSplicing.ts +0 -36
  322. package/src/utils/utils.ts +0 -280
@@ -2,197 +2,277 @@ import Query from "@specs-feup/lara/api/weaver/Query.js";
2
2
  import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
3
3
  import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
4
4
 
5
+ const utils_code = `
6
+ #include <stdint.h>
7
+ #include <stdbool.h>
8
+
9
+ void use_uint16(uint16_t param) {
10
+ (void)(param & 0xFF00U);
11
+ }
12
+ `;
13
+
14
+ const utils_header = `
15
+ #include <stdint.h>
16
+ #include <stdbool.h>
17
+
18
+ extern void use_uint16(uint16_t param);
19
+ `;
20
+
21
+ const misraExample = `
22
+ #include "utils.h"
23
+
24
+ static void unusedtag (void) {
25
+ enum state { // Violation of rule 2.4
26
+ S_init,
27
+ S_run,
28
+ S_sleep
29
+ };
30
+ }
31
+
32
+ static void test_2_4_1() {
33
+ typedef struct record_t { // Violation of rule 2.4
34
+ uint16_t key;
35
+ uint16_t val;
36
+ } record1_t;
37
+
38
+ typedef struct {
39
+ uint16_t key;
40
+ uint16_t val;
41
+ } record2_t;
42
+
43
+ record1_t var1;
44
+ record2_t var2;
45
+ use_uint16(var1.key + var1.val + var2.key + var2.val);
46
+ }
47
+ `;
48
+
49
+
5
50
  const failingCodeEnum1 = `
6
- enum MyEnum {
7
- RED, GREEN, BLUE
8
- };
9
-
10
- enum EnumForCast1 {
11
- RED2, GREEN2, BLUE2
12
- };
13
-
14
- enum EnumForCast2 {
15
- RED3, GREEN3, BLUE3
16
- };
17
-
18
- enum MyEnum2 {
19
- RED4, GREEN4, BLUE4
20
- };
21
-
22
- enum EnumForPtr {
23
- RED5, GREEN5, BLUE5
24
- };
25
-
26
- enum EnumForArray {
27
- RED6, GREEN6, BLUE6
28
- };
29
-
30
- // Non-compliant
31
- enum UnusedEnum {
32
- RED7, GREEN7, BLUE7
33
- };
34
-
35
- void enumAsParam(enum MyEnum color) {
36
- int i;
37
- if (color == RED) {
38
- i = 1;
39
- }
51
+ enum MyEnum {
52
+ RED, GREEN, BLUE
53
+ };
54
+
55
+ enum EnumForCast1 {
56
+ RED2, GREEN2, BLUE2
57
+ };
58
+
59
+ enum EnumForCast2 {
60
+ RED3, GREEN3, BLUE3
61
+ };
62
+
63
+ enum MyEnum2 {
64
+ RED4, GREEN4, BLUE4
65
+ };
66
+
67
+ enum EnumForPtr {
68
+ RED5, GREEN5, BLUE5
69
+ };
70
+
71
+ enum EnumForArray {
72
+ RED6, GREEN6, BLUE6
73
+ };
74
+
75
+ // Non-compliant
76
+ enum UnusedEnum {
77
+ RED7, GREEN7, BLUE7
78
+ };
79
+
80
+ static void enumAsParam(enum MyEnum color) {
81
+ int i;
82
+ if (color == RED) {
83
+ i = 1;
40
84
  }
85
+ }
41
86
 
42
- enum EnumForCast1 enumAsReturn() {
43
- return (enum EnumForCast1) RED2;
44
- };
87
+ static enum EnumForCast1 enumAsReturn() {
88
+ return (enum EnumForCast1) RED2;
89
+ };
45
90
 
46
- enum EnumForCast2 enumAsReturn2() {
47
- int id = 2;
48
- return (enum EnumForCast2) id;
49
- };
91
+ static enum EnumForCast2 enumAsReturn2() {
92
+ int id = 2;
93
+ return (enum EnumForCast2) id;
94
+ };
50
95
 
96
+ static void use_tags_2_4_1() {
51
97
  enum MyEnum2 color_enum = RED4;
52
-
53
98
  enum EnumForPtr *colorPtr;
54
-
55
99
  enum EnumForArray colorArray[3];
100
+
101
+ (void) color_enum;
102
+ (void) colorPtr;
103
+ (void) colorArray;
104
+ }
56
105
  `;
57
106
 
58
107
  const failingCodeEnum2 = `
59
- typedef enum {
60
- A1,
61
- B1,
62
- C1
63
- } ColorEnum2;
64
- ColorEnum2 colorEnum2 = A1;
65
-
66
- typedef enum MyColors {
67
- A2,
68
- B3,
69
- C4
70
- } ColorOption;
108
+ typedef enum {
109
+ A1,
110
+ B1,
111
+ C1
112
+ } ColorEnum2;
113
+
114
+ typedef enum MyColors {
115
+ A2,
116
+ B3,
117
+ C4
118
+ } ColorOption;
119
+
120
+ // MyColors2 tag should be removed
121
+ typedef enum MyColors2 {
122
+ A5,
123
+ B6,
124
+ C7
125
+ } ColorOption2;
126
+
127
+ static void use_tags_2_4_2() {
71
128
  enum MyColors my_color = A2;
72
129
  ColorOption color_option = B3;
73
-
74
- // MyColors2 tag should be removed
75
- typedef enum MyColors2 {
76
- A5,
77
- B6,
78
- C7
79
- } ColorOption2;
130
+ ColorEnum2 colorEnum2 = A1;
80
131
  ColorOption2 color2 = B6;
132
+
133
+ (void) my_color;
134
+ (void) color_option;
135
+ (void) colorEnum2;
136
+ (void) color2;
137
+ }
81
138
  `;
82
139
 
83
140
  const failingCodeStruct1 = `
84
- struct MyStruct {
85
- int x;
86
- float y;
87
- };
88
-
89
- struct StructForReturn1 {
90
- int x;
91
- float y;
92
- };
93
-
94
- struct MyStruct2 {
95
- int x;
96
- float y;
97
- };
98
-
99
- struct StructForPtr {
100
- int x;
101
- float y;
102
- };
103
-
104
- struct StructForArray {
105
- int x;
106
- float y;
107
- };
108
-
109
- // Non-compliant: should be removed
110
- struct UnusedStruct {
111
- int x;
112
- float y;
113
- };
114
-
115
- void structAsParam(struct MyStruct s) {
116
- int xField = s.x;
117
- }
118
-
119
- struct StructForReturn1 structAsReturn() {
120
- return (struct StructForReturn1){1, 1.5f};
121
- }
122
-
123
- struct MyStruct2 myStruct = {10, 20.5f};
124
- struct StructForPtr *structPtr;
125
- struct StructForArray structArray[3];
141
+ struct MyStruct {
142
+ int x;
143
+ float y;
144
+ };
145
+
146
+ struct StructForReturn1 {
147
+ int x;
148
+ float y;
149
+ };
150
+
151
+ struct MyStruct2 {
152
+ int x;
153
+ float y;
154
+ };
155
+
156
+ struct StructForPtr {
157
+ int x;
158
+ float y;
159
+ };
160
+
161
+ struct StructForArray {
162
+ int x;
163
+ float y;
164
+ };
165
+
166
+ // Non-compliant: should be removed
167
+ struct UnusedStruct {
168
+ int x;
169
+ float y;
170
+ };
171
+
172
+ static void structAsParam(struct MyStruct s) {
173
+ int xField = s.x;
174
+ }
175
+
176
+ static struct StructForReturn1 structAsReturn() {
177
+ return (struct StructForReturn1){1, 1.5f};
178
+ }
179
+
180
+ static void use_tags_2_4_3() {
181
+ static struct MyStruct2 myStruct = {10, 20.5f};
182
+ static struct StructForPtr *structPtr;
183
+ static struct StructForArray structArray[3];
184
+
185
+ (void) myStruct;
186
+ (void) structPtr;
187
+ (void) structArray;
188
+ }
126
189
  `;
127
190
 
128
191
  const failingCodeStruct2 = `
129
- typedef struct {
130
- int x;
131
- float y;
132
- } ColorStruct;
133
- ColorStruct colorStruct = {1, 2.5};
134
-
135
- typedef struct MyStruct5 {
136
- int x;
137
- float y;
138
- } ColorStruct2;
139
- struct MyStruct5 struct5 = {2, 4.5};
140
- ColorStruct2 colorStruct2 = {1, 2.5};
141
-
142
- // Violation: MyStruct3 tag will be removed
143
- typedef struct MyStruct3 {
144
- int x;
145
- float y;
146
- } ColorStruct3;
147
- ColorStruct3 colorStruct3 = {10, 5.5};
192
+ typedef struct {
193
+ int x;
194
+ float y;
195
+ } ColorStruct;
196
+
197
+ typedef struct MyStruct5 {
198
+ int x;
199
+ float y;
200
+ } ColorStruct2;
201
+
202
+ // Violation: MyStruct3 tag will be removed
203
+ typedef struct MyStruct3 {
204
+ int x;
205
+ float y;
206
+ } ColorStruct3;
207
+
208
+ static void use_tags_2_4_4() {
209
+ static ColorStruct colorStruct = {1, 2.5};
210
+ static struct MyStruct5 struct5 = {2, 4.5};
211
+ static ColorStruct2 colorStruct2 = {1, 2.5};
212
+ static ColorStruct3 colorStruct3 = {10, 5.5};
213
+
214
+ (void) colorStruct;
215
+ (void) struct5;
216
+ (void) colorStruct2;
217
+ (void) colorStruct3;
218
+ }
148
219
  `;
149
220
 
150
221
  const failingCodeUnion1 = `
151
- union MyUnion {
152
- int x;
153
- float y;
154
- };
155
-
156
- union UnionForReturn1 {
157
- int x;
158
- float y;
159
- };
160
-
161
- union MyUnion2 {
162
- int x;
163
- float y;
164
- };
165
-
166
- union UnionForPtr {
167
- int x;
168
- float y;
169
- };
170
-
171
- union UnionForArray {
172
- int x;
173
- float y;
174
- };
175
-
176
- // Non-compliant: should be removed
177
- union UnusedUnion {
178
- int x;
179
- float y;
180
- };
181
-
182
- void unionAsParam(union MyUnion u) {
183
- int xField = u.x;
184
- }
185
-
186
- union UnionForReturn1 unionAsReturn() {
187
- return (union UnionForReturn1){.x = 1};
188
- }
189
-
222
+ union MyUnion {
223
+ int x;
224
+ float y;
225
+ };
226
+
227
+ union UnionForReturn1 {
228
+ int x;
229
+ float y;
230
+ };
231
+
232
+ union MyUnion2 {
233
+ int x;
234
+ float y;
235
+ };
236
+
237
+ union UnionForPtr {
238
+ int x;
239
+ float y;
240
+ };
241
+
242
+ union UnionForArray {
243
+ int x;
244
+ float y;
245
+ };
246
+
247
+ // Non-compliant: should be removed
248
+ union UnusedUnion {
249
+ int x;
250
+ float y;
251
+ };
252
+
253
+ static void unionAsParam(union MyUnion u) {
254
+ int xField = u.x;
255
+ }
256
+
257
+ static union UnionForReturn1 unionAsReturn() {
258
+ return (union UnionForReturn1){.x = 1};
259
+ }
260
+
261
+ static void use_tags_2_4_5() {
190
262
  union MyUnion2 myUnion = {.y = 20.5f};
191
263
  union UnionForPtr *unionPtr;
192
264
  union UnionForArray unionArray[3];
265
+
266
+ (void) myUnion;
267
+ (void) unionPtr;
268
+ (void) unionArray;
269
+ }
193
270
  `;
194
271
 
195
272
  const files: TestFile[] = [
273
+ { name: "utils.c", code: utils_code },
274
+ { name: "utils.h", code: utils_header },
275
+ { name: "misra_example.c", code: misraExample },
196
276
  { name: "testEnum1.c", code: failingCodeEnum1 },
197
277
  { name: "testEnum2.c", code: failingCodeEnum2 },
198
278
  { name: "testStruct1.c", code: failingCodeStruct1 },
@@ -204,7 +284,7 @@ describe("Rule 2.4", () => {
204
284
  registerSourceCode(files);
205
285
 
206
286
  it("should detect errors in bad.c", () => {
207
- expect(countMISRAErrors()).toBe(5);
287
+ expect(countMISRAErrors()).toBe(7);
208
288
 
209
289
  expect(countMISRAErrors(Query.search(FileJp, {name: "testEnum1.c"}).first()!)).toBe(1);
210
290
  expect(countMISRAErrors(Query.search(FileJp, {name: "testEnum2.c"}).first()!)).toBe(1);
@@ -3,44 +3,56 @@ import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestF
3
3
  import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
4
4
 
5
5
  const passingCode = `
6
- int test1() {
7
- int x = 0;
8
- goto label1;
6
+ static int test_2_6_2() {
7
+ int x = 0;
8
+ goto label1;
9
9
 
10
- label1:
11
- x++;
10
+ label1:
11
+ x++;
12
12
 
13
- return 0;
14
- }`;
13
+ return 0;
14
+ }
15
+ `;
15
16
 
16
17
  const failingCode = `
17
- int test2() {
18
- int x = 0;
19
- label1:
20
- x = 1;
21
- label2:
22
- x++;
18
+ static int test_2_6_1() {
19
+ int x = 0;
20
+ label1: // Violation of rule 2.6
21
+ x = 1;
22
+ label2: // Violation of rule 2.6
23
+ x++;
24
+
25
+ goto label3;
23
26
 
24
- goto label3;
27
+ label3:
28
+ x += 4;
29
+ return 0;
30
+ }
31
+ `;
25
32
 
26
- label3:
27
- x += 4;
28
- return 0;
29
- }`;
33
+ const misraExample = `
34
+ static void unused_label ( void ) {
35
+ int x = 6;
36
+ label1: // Violation of rule 2.6
37
+ x++;
38
+ }
39
+ `;
30
40
 
31
41
  const files: TestFile[] = [
32
42
  { name: "bad.c", code: failingCode },
33
- { name: "good.c", code: passingCode }
43
+ { name: "good.c", code: passingCode },
44
+ { name: "misra_example.c", code: misraExample }
34
45
  ];
35
46
 
36
47
  describe("Rule 2.6", () => {
37
48
  registerSourceCode(files);
38
49
 
39
50
  it("should detect errors in bad.c", () => {
40
- expect(countMISRAErrors()).toBe(2);
51
+ expect(countMISRAErrors()).toBe(3);
41
52
 
42
53
  expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(2);
43
54
  expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
55
+ expect(countMISRAErrors(Query.search(FileJp, {name: "misra_example.c"}).first()!)).toBe(1);
44
56
  });
45
57
 
46
58
  it("should correct errors in bad.c", () => {
@@ -1,52 +1,58 @@
1
- import Query from "@specs-feup/lara/api/weaver/Query.js";
2
1
  import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
3
- import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
4
2
 
5
3
  const failingCode = `
6
- int foo(int x, int y, int z);
4
+ int foo(int x, int y, int z);
7
5
 
8
- int foo(int x, int y, int z) {
9
- y++;
10
- return y;
11
- }
6
+ int foo(int x, int y, int z) {
7
+ y++;
8
+ return y;
9
+ }
12
10
 
13
- int main() {
14
- int a = 5, b = 10, c = 15;
15
- int result1 = foo(a, b, c);
11
+ int main() {
12
+ int a = 5, b = 10, c = 15;
13
+ int result1 = foo(a, b, c);
16
14
 
17
- int result2 = result1 + foo(a, b, c);
18
-
19
- return result2;
20
- }`;
15
+ int result2 = result1 + foo(a, b, c);
16
+
17
+ return result2;
18
+ }
19
+ `;
21
20
 
22
21
  const passingCode = `
23
- extern int foo(int x, int y, int z);
22
+ extern int foo(int x, int y, int z);
24
23
 
25
- int my_func(int x, int y, int z) {
26
- return x + y + z;
27
- }
28
-
29
- int my_func2() {
30
- return 0;
31
- }
24
+ static int my_func(int x, int y, int z) {
25
+ return x + y + z;
26
+ }
27
+
28
+ static int my_func2() {
29
+ return 0;
30
+ }
32
31
 
33
- int bar() {
34
- return my_func(1, 2, 3) + foo(50, 51, 52);
35
- }`;
32
+ static int bar() {
33
+ return my_func(1, 2, 3) + foo(50, 51, 52);
34
+ }
35
+ `;
36
+
37
+ const misraExample = `
38
+ #include <stdint.h>
39
+
40
+ static void withunusedpara (uint16_t *para1, int16_t unusedpara ) { // Violation of rule 2.7
41
+ *para1 = 42U;
42
+ }
43
+ `;
36
44
 
37
45
  const files: TestFile[] = [
38
46
  { name: "bad.c", code: failingCode },
39
- { name: "good.c", code: passingCode }
47
+ { name: "good.c", code: passingCode },
48
+ { name: "misra_example.c", code: misraExample }
40
49
  ];
41
50
 
42
51
  describe("Rule 2.7", () => {
43
52
  registerSourceCode(files);
44
53
 
45
54
  it("should detect errors in bad.c", () => {
46
- expect(countMISRAErrors()).toBe(2);
47
-
48
- expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(2);
49
- expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
55
+ expect(countMISRAErrors()).toBe(3);
50
56
  });
51
57
 
52
58
  it("should correct errors in bad.c", () => {
@@ -2,32 +2,61 @@ import Query from "@specs-feup/lara/api/weaver/Query.js";
2
2
  import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
3
3
  import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
4
4
 
5
- const passingCode = `int main() {
5
+ const passingCode = `
6
+ int static test_3_1_1() {
6
7
  int x, y, z;// good inline comment
7
8
  // good */ comment
9
+ // good // comment
8
10
  return 0;
9
- }`;
11
+ }
12
+ `;
10
13
 
11
- const failingCode = `int test() {
12
- int x, y, z; // bad inl/*ine comment
14
+ const failingCode = `
15
+ static int test_3_1_2() {
16
+ int x, y, z; // bad inl/*ine comment - Violation of rule 3.1
17
+
18
+ /* bad // comment - violation of rule 3.1 */
13
19
 
14
- /* bad /* block comment */
20
+ /* bad /* block comment - Violation of rule 3.1*/
15
21
 
16
22
  return 0;
17
- }`;
23
+ }
24
+ `;
25
+
26
+ const misraExample = `
27
+ static int test_3_1_3() {
28
+ /* [Violation of rule 3.1] some comment, end comment marker accidentally omitted
29
+ <<New Page>>
30
+ Perform_Critical_Safety_Function( X );
31
+ /* this comment is non-compliant */
32
+
33
+ int x;
34
+ int y = 6;
35
+ int z = 3;
36
+
37
+ x = y // /* violation of rule 3.1
38
+ + z
39
+ // */
40
+ ;
41
+
42
+ return 0;
43
+ }
44
+ `;
18
45
 
19
46
  const files: TestFile[] = [
20
47
  { name: "bad.c", code: failingCode },
21
- { name: "good.c", code: passingCode }
48
+ { name: "good.c", code: passingCode },
49
+ { name: "misra_c_example.c", code: misraExample },
22
50
  ];
23
51
 
24
52
  describe("Rule 3.1", () => {
25
53
  registerSourceCode(files);
26
54
 
27
55
  it("should detect errors in bad.c", () => {
28
- expect(countMISRAErrors()).toBe(2);
56
+ expect(countMISRAErrors()).toBe(4);
29
57
 
30
58
  expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(2);
59
+ expect(countMISRAErrors(Query.search(FileJp, {name: "misra_c_example.c"}).first()!)).toBe(2);
31
60
  expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
32
61
  });
33
62