@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
@@ -3,7 +3,7 @@ import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestF
3
3
  import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
4
4
 
5
5
  const passingCode =
6
- `void foo16_3_1( void )
6
+ `static void foo16_3_1( void )
7
7
  {
8
8
  int x, a, b;
9
9
  switch ( x )
@@ -26,41 +26,68 @@ const passingCode =
26
26
  default:
27
27
  break;
28
28
  }
29
- }`;
29
+ }
30
+ `;
30
31
 
31
32
  const failingCode =
32
- `void foo16_3_2( void )
33
- {
34
- int x = 4, a, b, c;
33
+ `static void foo16_3_2( void ) {
34
+ int x = 4, a_16_3, b_16_3, c_16_3;
35
35
  switch (x) {
36
36
  case 1:
37
- a = 1;
37
+ a_16_3 = 1;
38
38
  break;
39
- case 2: // Missing break
40
- b = 10;
39
+ case 2:
40
+ b_16_3 = 10; // Missing break - violation of rule 16.3
41
41
  case 6:
42
42
  case 3:
43
43
  x++;
44
44
  // comment1
45
45
  x--;
46
- // comment2
46
+ // comment2 Missing break - violation of rule 16.3
47
47
  default:
48
- c = 30;
48
+ c_16_3 = 30; // Missing break - violation of rule 16.3
49
+ }
50
+ }
51
+ `;
52
+
53
+ const misraExample = `
54
+ static void foo16_3_3( void ) {
55
+ int x = 4, a_16_3, b_16_3, c_16_3;
56
+ switch ( x )
57
+ {
58
+ case 0:
59
+ break; /* Compliant - unconditional break */
60
+ case 1: /* Compliant - empty fall through allows a group */
61
+ case 2:
62
+ break;
63
+ /* Compliant*/
64
+ case 4:
65
+ a_16_3 = b_16_3; /* Non-compliant - break omitted (violation of rule 16.3) */
66
+ case 5:
67
+ if (a_16_3 == b_16_3) {
68
+ ++a_16_3;
69
+ break; /* Non-compliant - conditional break (violation of rule 16.3) */
70
+ }
71
+ default:
72
+ ; /* Non-compliant - default must also have a break (violation of rule 16.3) */
49
73
  }
50
- }`;
74
+ }
75
+ `;
51
76
 
52
77
  const files: TestFile[] = [
53
78
  { name: "bad.c", code: failingCode },
54
- { name: "good.c", code: passingCode }
79
+ { name: "good.c", code: passingCode },
80
+ { name: "misra_example.c", code: misraExample }
55
81
  ];
56
82
 
57
83
  describe("Rule 16.3", () => {
58
84
  registerSourceCode(files);
59
85
 
60
86
  it("should detect errors in bad.c", () => {
61
- expect(countMISRAErrors()).toBe(3);
87
+ expect(countMISRAErrors()).toBe(6);
62
88
 
63
89
  expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(3);
90
+ expect(countMISRAErrors(Query.search(FileJp, {name: "misra_example.c"}).first()!)).toBe(3);
64
91
  expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
65
92
  });
66
93
 
@@ -3,7 +3,7 @@ import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestF
3
3
  import Query from "@specs-feup/lara/api/weaver/Query.js";
4
4
 
5
5
  const passingCode =
6
- `void foo16_4_1( void )
6
+ `static void foo16_4_1( void )
7
7
  {
8
8
  int x;
9
9
  switch ( x )
@@ -29,14 +29,13 @@ const passingCode =
29
29
  case 2:
30
30
  break;
31
31
  }
32
- }`;
32
+ }
33
+ `;
33
34
 
34
35
  const failingCode1 =
35
- `void foo16_4_3( void )
36
- {
36
+ `static void foo16_4_3 (void) {
37
37
  int x;
38
- switch ( x )
39
- {
38
+ switch (x) { // violation of rule 16.4
40
39
  case 0:
41
40
  ++x;
42
41
  break;
@@ -45,15 +44,14 @@ const failingCode1 =
45
44
  x--;
46
45
  break;
47
46
  }
48
- }`;
47
+ }
48
+ `;
49
49
 
50
50
  // 4 erros: two of them are related to having boolean switch condition
51
51
  const failingCode2 =
52
- `void foo16_4_4( void )
53
- {
52
+ `static void foo16_4_4 (void) {
54
53
  int x, a = 14;
55
- switch ( x == 4) /* Default will not be introduced, as it will be converted by the other rule */
56
- {
54
+ switch ( x == 4) { /* Default will not be introduced, as it will be converted by the other rule */
57
55
  case 1:
58
56
  ++x;
59
57
  break;
@@ -77,7 +75,7 @@ const failingCode2 =
77
75
 
78
76
  // 4 errors: two of them are related to having less than two clauses
79
77
  const failingCode3 =
80
- `void foo16_4_5( void )
78
+ `static void foo16_4_5( void )
81
79
  {
82
80
  int x, a = 14;
83
81
  switch (x) { /* Default will not be introduced, as it will be converted by the other rule*/
@@ -3,7 +3,7 @@ import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestF
3
3
  import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
4
4
 
5
5
  const passingCode1 =
6
- `void foo16_5_1( void )
6
+ `static void foo16_5_1( void )
7
7
  {
8
8
  int x;
9
9
  switch ( x ) {
@@ -30,7 +30,7 @@ const passingCode1 =
30
30
  }`;
31
31
 
32
32
  const failingCode1 =
33
- `void foo16_5_3( void )
33
+ `static void foo16_5_3( void )
34
34
  {
35
35
  int x;
36
36
  switch ( x ) {
@@ -46,7 +46,7 @@ const failingCode1 =
46
46
  }`;
47
47
 
48
48
  const failingCode2 =
49
- `void foo16_5_4( void )
49
+ `static void foo16_5_4( void )
50
50
  {
51
51
  int x;
52
52
  switch ( x ) {
@@ -66,7 +66,7 @@ const failingCode2 =
66
66
  }`;
67
67
 
68
68
  const failingCode3 =
69
- `void foo16_5_5( void )
69
+ `static void foo16_5_5( void )
70
70
  {
71
71
  int x;
72
72
  switch ( x ) {
@@ -88,7 +88,7 @@ const failingCode3 =
88
88
  }`;
89
89
 
90
90
  const failingCode4 =
91
- `void foo16_5_6( void )
91
+ `static void foo16_5_6( void )
92
92
  {
93
93
  int x;
94
94
  switch ( x ) {
@@ -3,7 +3,7 @@ import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestF
3
3
  import { FileJp, FunctionJp, If, Switch } from "@specs-feup/clava/api/Joinpoints.js";
4
4
 
5
5
  const passingCode =
6
- `void foo16_6_1( void )
6
+ `static void foo16_6_1( void )
7
7
  {
8
8
  int x, a, b;
9
9
 
@@ -28,7 +28,7 @@ const passingCode =
28
28
  }`;
29
29
 
30
30
  const failingCode1 =
31
- `int foo16_6_2( void )
31
+ `static int foo16_6_2( void )
32
32
  {
33
33
  int x = 1;
34
34
  switch ( x )
@@ -47,7 +47,7 @@ const failingCode1 =
47
47
  }`;
48
48
 
49
49
  const failingCode2 =
50
- `int foo16_6_3( void )
50
+ `static int foo16_6_3( void )
51
51
  {
52
52
  int x = 10, a, b;
53
53
 
@@ -65,7 +65,7 @@ const failingCode2 =
65
65
 
66
66
  // 2 erros: one is related to not having a default case
67
67
  const failingCode3 =
68
- `int foo16_6_4( void )
68
+ `static int foo16_6_4( void )
69
69
  {
70
70
  int x = 10, a, b;
71
71
 
@@ -81,7 +81,7 @@ const failingCode3 =
81
81
  }`;
82
82
 
83
83
  const failingCode4 =
84
- `int foo16_6_5( void )
84
+ `static int foo16_6_5( void )
85
85
  {
86
86
  int x = 10, a, b;
87
87
 
@@ -3,7 +3,7 @@ import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestF
3
3
  import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
4
4
 
5
5
  const passingCode =
6
- `void foo16_7_1( int num )
6
+ `static void foo16_7_1( int num )
7
7
  {
8
8
  switch (num) {
9
9
  case 0:
@@ -22,10 +22,10 @@ const failingCode1 =
22
22
  `
23
23
  #include <stdbool.h>
24
24
 
25
- void foo16_6_2( int num )
25
+ static void foo16_6_2( int num )
26
26
  {
27
27
  int a = 7;
28
- switch (num % 3) {
28
+ switch ((num % 3) == 0) {
29
29
  case 0:
30
30
  a *= 2;
31
31
  break;
@@ -38,7 +38,7 @@ void foo16_6_2( int num )
38
38
  }
39
39
  }
40
40
 
41
- void foo16_6_3( bool flag )
41
+ static void foo16_6_3( bool flag )
42
42
  {
43
43
  int a = 7;
44
44
  switch (flag) {
@@ -59,7 +59,7 @@ const failingCode2 =
59
59
  `
60
60
  #include <stdbool.h>
61
61
 
62
- void foo16_6_4( bool flag )
62
+ static void foo16_6_4( bool flag )
63
63
  {
64
64
  int a = 7, b = 10;
65
65
  switch (flag) {
@@ -1,79 +1,107 @@
1
+ import Clava from "@specs-feup/clava/api/clava/Clava.js";
1
2
  import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
2
3
  import path from "path";
3
4
  import { fileURLToPath } from "url";
4
5
 
5
6
  const passingCode = `
6
- #include <stdio.h>
7
- int func() {
7
+
8
+ extern double test_17_3_4();
9
+
10
+ // Missing "static" keyword; Will have external decl after correction
11
+ unsigned int foo_17_3() {
8
12
  return 0;
9
13
  }
10
14
 
11
- void test_17_3_1() {
12
- printf("Result: %.2f ", func());
13
- }`;
15
+ // Missing "static" keyword; Will have external decl after correction
16
+ double test_17_3_1() {
17
+ return foo_17_3() + test_17_3_4();
18
+ }
19
+ `;
20
+
21
+ const passingCode2 = `
22
+ extern int foo_17_3();
23
+ extern double test_17_3_1();
24
+
25
+ double test_17_3_4() {
26
+ return foo_17_3() + test_17_3_1();
27
+ }
28
+ `;
14
29
 
15
30
  const failingCode = `
16
- void test_17_3_2() {
31
+ static void test_17_3_2() {
17
32
  double a = 2.0, b = 3.0;
18
33
 
19
- // Implicit call to pow(): math.h is missing
20
- double res1 = pow(a, b);
21
- double res2 = pow(b, a);
34
+ // Implicit call to pow(): <math.h> is missing
35
+ double res1 = pow(a, b); // Violation of rule 17.3
36
+ double res2 = pow(b, a); // Violation of rule 17.3
22
37
 
23
- // Implicit call to printf(): studio.h is missing
24
- // Return value is not being used
25
- printf("Results: %.2f %.2f ", res1, res2);
38
+ // Implicit call to toupper: <ctype.h> is missing
39
+ char lower1 = 'a';
40
+ char upper1 = toupper(lower1); // Violation of rule 17.3
26
41
 
27
- // Implicit call to sin(): math.h is missing
42
+ // Implicit call to sin(): <math.h> is missing
28
43
  double angle = 3.14159265;
29
- double sin_val = sin(angle);
30
-
31
- // Implicit call to printf(): studio.h is missing
32
- // Return value is not being used
33
- printf("Sin: %.2f ", sin_val);
44
+ double sin_val = sin(angle); // Violation of rule 17.3
34
45
 
35
- // Implicit call to print(): studio.h will not solve this issue
36
- // Return value is not being used
37
- (void) print("End of program");
38
-
39
- }`;
46
+ // Implicit call to strlen(): <ctype.h> is missing
47
+ char lower2 = 'b';
48
+ char upper2 = toupper(lower2); // Violation of rule 17.3
49
+ }
50
+ `;
40
51
 
41
52
  const failingCode2 = `
42
53
  #include <math.h>
43
54
 
44
- int func() {
55
+ static unsigned int bar_17_3() {
45
56
  double a = 2.0, b = 3.0;
46
57
 
47
58
  double pow_result = pow(a, b);
48
- double sum = half(b) + pow_result; // Implicit call: provided math.h does not solve
49
59
 
50
- // Implicit call: provided stdio.h does not solve the issue
51
- // Return value is not being used
52
- println("Result: ", sum);
60
+ // Implicit call: <string.h> is missing
61
+ char lower1 = 'a';
62
+ char upper1 = toupper(lower1); // Violation of rule 17.3
53
63
 
54
64
  return 0;
55
- }`;
65
+ }
66
+ `;
67
+
68
+ // Missing externs
69
+ const failingCode3 = `
70
+ static unsigned int test_17_3_3() {
71
+ int x = foo_17_3(); // Implicit call to foo_17_3() in good.c - violation of rule 17.3
72
+
73
+ (void) test_17_3_1(); // Implicit call with wrong params - violation of rule 17.3
74
+ return 0;
75
+ }
76
+ `;
56
77
 
57
78
  const files: TestFile[] = [
58
79
  { name: "bad1.c", code: failingCode },
59
80
  { name: "bad2.c", code: failingCode2 },
81
+ { name: "bad3.c", code: failingCode3 },
60
82
  { name: "good.c", code: passingCode },
83
+ { name: "good2.c", code:passingCode2 }
61
84
  ];
62
85
 
63
- describe("Rule 17.4", () => {
64
- registerSourceCode(files);
65
-
66
- it("should detect errors", () => {
67
- expect(countMISRAErrors()).toBe(12);
68
- });
69
-
70
- it("should correct errors", () => {
86
+ describe("Rule 17.3", () => {
87
+ if (Clava.getStandard() !== "c90") {
88
+ it("should skip tests for c99 and c11", () => {});
89
+ } else {
71
90
  const __filename = fileURLToPath(import.meta.url);
72
91
  const __dirname = path.dirname(__filename);
73
92
 
74
93
  const configFilename = "misra_config.json";
75
94
  const configFilePath = path.join(__dirname, configFilename);
76
95
 
77
- expect(countErrorsAfterCorrection(configFilePath)).toBe(3);
78
- });
79
- });
96
+ registerSourceCode(files, configFilePath);
97
+
98
+ it("should detect errors", () => {
99
+ expect(countMISRAErrors()).toBe(8);
100
+ expect(countMISRAErrors("17.3")).toBe(8);
101
+ });
102
+
103
+ it("should correct errors", () => {
104
+ expect(countErrorsAfterCorrection()).toBe(0);
105
+ });
106
+ }
107
+ });
@@ -0,0 +1,98 @@
1
+ import Clava from "@specs-feup/clava/api/clava/Clava.js";
2
+ import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
3
+ import path from "path";
4
+ import { fileURLToPath } from "url";
5
+
6
+ const passingCode = `
7
+ #include <math.h>
8
+
9
+ static unsigned int func() {
10
+ return 0;
11
+ }
12
+
13
+ static void test_17_3_1() {
14
+ double result = sqrt(func());
15
+ }
16
+ `;
17
+
18
+
19
+ const failingCode = `
20
+ static void test_17_3_2() {
21
+ double a = 2.0, b = 3.0;
22
+
23
+ // Implicit call to pow(): <math.h> is missing
24
+ double res1 = pow(a, b);
25
+ double res2 = pow(b, a);
26
+
27
+ // Implicit call to strlen: <ctype.h> is missing
28
+ char lower1 = 'a';
29
+ char upper1 = toupper(lower1);
30
+
31
+ // Implicit call to sin(): <math.h> is missing
32
+ double angle = 3.14159265;
33
+ double sin_val = sin(angle);
34
+
35
+ // Implicit call to strlen(): <ctype.h> is missing
36
+ char lower2 = 'b';
37
+ char upper2 = toupper(lower2);
38
+
39
+ // Implicit call to toupper_transformation(): <ctype.h> is missing
40
+ char lower3 = 'c';
41
+ char upper3 = toupper_transformation(lower3);
42
+
43
+ }`;
44
+
45
+ const failingCode2 = `
46
+ #include <math.h>
47
+
48
+ static unsigned int func2() {
49
+ double a = 2.0, b = 3.0;
50
+
51
+ double pow_result = pow(a, b);
52
+ double sum = half(b) + pow_result; // Implicit call to 'half': provided math.h does not solve
53
+
54
+ // Implicit call: <ctype.h> is missing
55
+ char lower1 = 'a';
56
+ char upper1 = toupper_transformation(lower1);
57
+
58
+ return 0;
59
+ }`;
60
+
61
+ // Missing externs
62
+ const failingCode3 = `
63
+ static unsigned int test_17_3_3() {
64
+ int x = func(); // Implicit call to func() in good.c
65
+
66
+ // Implicit call to func2() in bad2.c; Provided file in config does not include definition
67
+ int y = func2();
68
+
69
+ // Implicit call with wrong params
70
+ (void) test_17_3_1(1, 4);
71
+ return 0;
72
+ }
73
+ `;
74
+
75
+ const files: TestFile[] = [
76
+ { name: "bad1.c", code: failingCode },
77
+ { name: "bad2.c", code: failingCode2 },
78
+ { name: "bad3.c", code: failingCode3 },
79
+ { name: "good.c", code: passingCode },
80
+ ];
81
+
82
+ describe("Rule 17.3 (without config)", () => {
83
+ if (Clava.getStandard() !== "c90") {
84
+ it("should skip tests for c99 and c11", () => {});
85
+ } else {
86
+ registerSourceCode(files);
87
+
88
+ it("should detect errors", () => {
89
+ expect(countMISRAErrors()).toBe(11);
90
+ expect(countMISRAErrors("17.3")).toBe(11);
91
+
92
+ });
93
+
94
+ it("should correct errors", () => {
95
+ expect(countErrorsAfterCorrection()).toBe(11);
96
+ });
97
+ }
98
+ });
@@ -0,0 +1,71 @@
1
+ import Clava from "@specs-feup/clava/api/clava/Clava.js";
2
+ import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
3
+ import path from "path";
4
+ import { fileURLToPath } from "url";
5
+
6
+ const passingCode = `
7
+ #include <math.h>
8
+
9
+ static unsigned int func() {
10
+ return 0;
11
+ }
12
+
13
+ void test_17_3_1() {
14
+ double result = sqrt(func());
15
+ }
16
+ `;
17
+
18
+ const failingCode2 = `
19
+ #include <math.h>
20
+
21
+ static unsigned int func2() {
22
+ double a = 2.0, b = 3.0;
23
+
24
+ double pow_result = pow(a, b);
25
+ double sum = half(b) + pow_result; // Implicit call to 'half': provided math.h does not solve
26
+
27
+ // Implicit call: provided <ctype.h> does not solve
28
+ char lower1 = 'a';
29
+ char upper1 = toupper_transformation(lower1);
30
+
31
+ return 0;
32
+ }
33
+ `;
34
+
35
+ // Missing externs
36
+ const failingCode3 = `
37
+ static unsigned int test_17_3_3() {
38
+ int x = func(); // Implicit call to func() in good.c but does not have external linkage
39
+
40
+ // Implicit call to func2() in bad2.c; Provided file in config does not include definition
41
+ int y = func2();
42
+
43
+ // Implicit call with wrong params
44
+ (void) test_17_3_1(1, 4);
45
+ return 0;
46
+ }
47
+ `;
48
+
49
+ const files: TestFile[] = [
50
+ { name: "bad2.c", code: failingCode2 },
51
+ { name: "bad3.c", code: failingCode3 },
52
+ { name: "good.c", code: passingCode },
53
+ ];
54
+
55
+ describe("Rule 17.3 (without config)", () => {
56
+ if (Clava.getStandard() !== "c90") {
57
+ it("should skip tests for c99 and c11", () => {});
58
+ } else {
59
+ registerSourceCode(files);
60
+
61
+ it("should detect errors", () => {
62
+ expect(countMISRAErrors()).toBe(6);
63
+ expect(countMISRAErrors("17.3")).toBe(5);
64
+
65
+ });
66
+
67
+ it("should correct errors", () => {
68
+ expect(countErrorsAfterCorrection()).toBe(5);
69
+ });
70
+ }
71
+ });