@specs-feup/clava-misra 1.0.2 → 1.0.3

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 +39 -5
  16. package/dist/MISRATool.d.ts.map +1 -1
  17. package/dist/MISRATool.js +102 -46
  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 -1
  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 +51 -0
  193. package/dist/utils/FileUtils.d.ts.map +1 -0
  194. package/dist/utils/FileUtils.js +121 -0
  195. package/dist/utils/FileUtils.js.map +1 -0
  196. package/dist/utils/FunctionUtils.d.ts +25 -0
  197. package/dist/utils/FunctionUtils.d.ts.map +1 -0
  198. package/dist/utils/FunctionUtils.js +65 -0
  199. package/dist/utils/FunctionUtils.js.map +1 -0
  200. package/dist/utils/IdentifierUtils.d.ts +14 -0
  201. package/dist/utils/IdentifierUtils.d.ts.map +1 -0
  202. package/dist/utils/IdentifierUtils.js +87 -0
  203. package/dist/utils/IdentifierUtils.js.map +1 -0
  204. package/dist/utils/JoinpointUtils.d.ts +19 -0
  205. package/dist/utils/JoinpointUtils.d.ts.map +1 -0
  206. package/dist/utils/JoinpointUtils.js +46 -0
  207. package/dist/utils/JoinpointUtils.js.map +1 -0
  208. package/dist/utils/ProgramUtils.d.ts +14 -0
  209. package/dist/utils/ProgramUtils.d.ts.map +1 -0
  210. package/dist/utils/ProgramUtils.js +72 -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 +19 -0
  221. package/dist/utils/VarUtils.d.ts.map +1 -0
  222. package/dist/utils/VarUtils.js +59 -0
  223. package/dist/utils/VarUtils.js.map +1 -0
  224. package/package.json +16 -6
  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 +108 -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 -1
  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 +40 -0
  310. package/src/utils/CommentUtils.ts +29 -0
  311. package/src/utils/FileUtils.ts +141 -0
  312. package/src/utils/FunctionUtils.ts +75 -0
  313. package/src/utils/IdentifierUtils.ts +94 -0
  314. package/src/utils/JoinpointUtils.ts +53 -0
  315. package/src/utils/ProgramUtils.ts +83 -0
  316. package/src/utils/SwitchUtils.ts +52 -0
  317. package/src/utils/TypeDeclUtils.ts +89 -0
  318. package/src/utils/VarUtils.ts +70 -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
@@ -0,0 +1,27 @@
1
+ import { AnalysisType } from "../../MISRA.js";
2
+ import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
3
+ /**
4
+ * MISRA-C Rule 21.3: The memory allocation and deallocation functions of <stdlib.h> shall not be used
5
+ */
6
+ export default class Rule_21_3_NoDynamicMemory extends DisallowedStdLibFunctionRule {
7
+ /**
8
+ * The name of the standard library
9
+ */
10
+ standardLibrary = "stdlib.h";
11
+ /**
12
+ * Names of functions from {@link standardLibrary} that are forbidden.
13
+ * If the set is empty, all functions from {@link standardLibrary} are forbidden.
14
+ */
15
+ invalidFunctions = new Set(["calloc", "malloc", "aligned_alloc", "realloc", "free"]);
16
+ /**
17
+ * Scope of analysis
18
+ */
19
+ analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
20
+ /**
21
+ * @returns Rule identifier according to MISRA-C:2012
22
+ */
23
+ get name() {
24
+ return "21.3";
25
+ }
26
+ }
27
+ //# sourceMappingURL=Rule_21_3_NoDynamicMemory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_21_3_NoDynamicMemory.js","sourceRoot":"","sources":["../../../src/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,4BAA4B;IAC/E;;OAEG;IACO,eAAe,GAAG,UAAU,CAAC;IAEvC;;;OAGG;IACO,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;IAE/F;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,uBAAuB,CAAC;IAE7D;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
@@ -0,0 +1,25 @@
1
+ import { AnalysisType } from "../../MISRA.js";
2
+ import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
3
+ /**
4
+ * MISRA-C Rule 21.6: The Standard Library input/output functions shall not be used
5
+ */
6
+ export default class Rule_21_6_NoStdIOFunctions extends DisallowedStdLibFunctionRule {
7
+ /**
8
+ * The name of the standard library
9
+ */
10
+ protected standardLibrary: string;
11
+ /**
12
+ * Names of functions from {@link standardLibrary} that are forbidden.
13
+ * If the set is empty, all functions from {@link standardLibrary} are forbidden.
14
+ */
15
+ protected invalidFunctions: Set<string>;
16
+ /**
17
+ * Scope of analysis
18
+ */
19
+ readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
20
+ /**
21
+ * @returns Rule identifier according to MISRA-C:2012
22
+ */
23
+ get name(): string;
24
+ }
25
+ //# sourceMappingURL=Rule_21_6_NoStdIOFunctions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_21_6_NoStdIOFunctions.d.ts","sourceRoot":"","sources":["../../../src/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,4BAA4B;IAChF;;OAEG;IACH,SAAS,CAAC,eAAe,SAAa;IAEtC;;;OAGG;IACH,SAAS,CAAC,gBAAgB,cAAqB;IAE/C;;OAEG;IACH,QAAQ,CAAC,YAAY,wCAAwC;IAE7D;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;CACJ"}
@@ -0,0 +1,27 @@
1
+ import { AnalysisType } from "../../MISRA.js";
2
+ import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
3
+ /**
4
+ * MISRA-C Rule 21.6: The Standard Library input/output functions shall not be used
5
+ */
6
+ export default class Rule_21_6_NoStdIOFunctions extends DisallowedStdLibFunctionRule {
7
+ /**
8
+ * The name of the standard library
9
+ */
10
+ standardLibrary = "stdio.h";
11
+ /**
12
+ * Names of functions from {@link standardLibrary} that are forbidden.
13
+ * If the set is empty, all functions from {@link standardLibrary} are forbidden.
14
+ */
15
+ invalidFunctions = new Set();
16
+ /**
17
+ * Scope of analysis
18
+ */
19
+ analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
20
+ /**
21
+ * @returns Rule identifier according to MISRA-C:2012
22
+ */
23
+ get name() {
24
+ return "21.6";
25
+ }
26
+ }
27
+ //# sourceMappingURL=Rule_21_6_NoStdIOFunctions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_21_6_NoStdIOFunctions.js","sourceRoot":"","sources":["../../../src/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,4BAA4B;IAChF;;OAEG;IACO,eAAe,GAAG,SAAS,CAAC;IAEtC;;;OAGG;IACO,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/C;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,uBAAuB,CAAC;IAE7D;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
@@ -0,0 +1,25 @@
1
+ import { AnalysisType } from "../../MISRA.js";
2
+ import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
3
+ /**
4
+ * MISRA-C Rule 21.7: The atof, atoi, atol and atoll functions of <stdlib.h> shall not be used.
5
+ */
6
+ export default class Rule_21_7_NoNumericStringConversions extends DisallowedStdLibFunctionRule {
7
+ /**
8
+ * The name of the standard library
9
+ */
10
+ protected standardLibrary: string;
11
+ /**
12
+ * Names of functions from {@link standardLibrary} that are forbidden.
13
+ * If the set is empty, all functions from {@link standardLibrary} are forbidden.
14
+ */
15
+ protected invalidFunctions: Set<string>;
16
+ /**
17
+ * Scope of analysis
18
+ */
19
+ readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
20
+ /**
21
+ * @returns Rule identifier according to MISRA-C:2012
22
+ */
23
+ get name(): string;
24
+ }
25
+ //# sourceMappingURL=Rule_21_7_NoNumericStringConversions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_21_7_NoNumericStringConversions.d.ts","sourceRoot":"","sources":["../../../src/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,oCAAqC,SAAQ,4BAA4B;IAC1F;;OAEG;IACH,SAAS,CAAC,eAAe,SAAc;IAEvC;;;OAGG;IACH,SAAS,CAAC,gBAAgB,cAA8C;IACxE;;OAEG;IACH,QAAQ,CAAC,YAAY,wCAAwC;IAE7D;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;CACJ"}
@@ -0,0 +1,27 @@
1
+ import { AnalysisType } from "../../MISRA.js";
2
+ import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
3
+ /**
4
+ * MISRA-C Rule 21.7: The atof, atoi, atol and atoll functions of <stdlib.h> shall not be used.
5
+ */
6
+ export default class Rule_21_7_NoNumericStringConversions extends DisallowedStdLibFunctionRule {
7
+ /**
8
+ * The name of the standard library
9
+ */
10
+ standardLibrary = "stdlib.h";
11
+ /**
12
+ * Names of functions from {@link standardLibrary} that are forbidden.
13
+ * If the set is empty, all functions from {@link standardLibrary} are forbidden.
14
+ */
15
+ invalidFunctions = new Set(["atof", "atoi", "atol", "atoll"]);
16
+ /**
17
+ * Scope of analysis
18
+ */
19
+ analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
20
+ /**
21
+ * @returns Rule identifier according to MISRA-C:2012
22
+ */
23
+ get name() {
24
+ return "21.7";
25
+ }
26
+ }
27
+ //# sourceMappingURL=Rule_21_7_NoNumericStringConversions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_21_7_NoNumericStringConversions.js","sourceRoot":"","sources":["../../../src/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,oCAAqC,SAAQ,4BAA4B;IAC1F;;OAEG;IACO,eAAe,GAAG,UAAU,CAAC;IAEvC;;;OAGG;IACO,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACxE;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,uBAAuB,CAAC;IAE7D;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
@@ -0,0 +1,30 @@
1
+ import { AnalysisType } from "../../MISRA.js";
2
+ import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
3
+ /**
4
+ * MISRA-C Rule 21.8: The library functions abort, exit, getenv and system of <stdlib.h>
5
+ * shall not be used
6
+ */
7
+ export default class Rule_21_8_NoProcessControlFunctions extends DisallowedStdLibFunctionRule {
8
+ /**
9
+ * Standards to which this rule applies to
10
+ */
11
+ protected readonly appliesTo: Set<string>;
12
+ /**
13
+ * The name of the standard library
14
+ */
15
+ protected standardLibrary: string;
16
+ /**
17
+ * Names of functions from {@link standardLibrary} that are forbidden.
18
+ * If the set is empty, all functions from {@link standardLibrary} are forbidden.
19
+ */
20
+ protected invalidFunctions: Set<string>;
21
+ /**
22
+ * Scope of analysis
23
+ */
24
+ readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
25
+ /**
26
+ * @returns Rule identifier according to MISRA-C:2012
27
+ */
28
+ get name(): string;
29
+ }
30
+ //# sourceMappingURL=Rule_21_8_NoProcessControlFunctions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_21_8_NoProcessControlFunctions.d.ts","sourceRoot":"","sources":["../../../src/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAE7E;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,mCAAoC,SAAQ,4BAA4B;IACzF;;OAEG;IACH,mBAA4B,SAAS,cAA2B;IAEhE;;OAEG;IACH,SAAS,CAAC,eAAe,SAAc;IAEvC;;;OAGG;IACH,SAAS,CAAC,gBAAgB,cAAkD;IAE5E;;OAEG;IACH,QAAQ,CAAC,YAAY,wCAAwC;IAE7D;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;CACJ"}
@@ -0,0 +1,32 @@
1
+ import { AnalysisType } from "../../MISRA.js";
2
+ import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
3
+ /**
4
+ * MISRA-C Rule 21.8: The library functions abort, exit, getenv and system of <stdlib.h>
5
+ * shall not be used
6
+ */
7
+ export default class Rule_21_8_NoProcessControlFunctions extends DisallowedStdLibFunctionRule {
8
+ /**
9
+ * Standards to which this rule applies to
10
+ */
11
+ appliesTo = new Set(["c90", "c99"]);
12
+ /**
13
+ * The name of the standard library
14
+ */
15
+ standardLibrary = "stdlib.h";
16
+ /**
17
+ * Names of functions from {@link standardLibrary} that are forbidden.
18
+ * If the set is empty, all functions from {@link standardLibrary} are forbidden.
19
+ */
20
+ invalidFunctions = new Set(["abort", "exit", "getenv", "system"]);
21
+ /**
22
+ * Scope of analysis
23
+ */
24
+ analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
25
+ /**
26
+ * @returns Rule identifier according to MISRA-C:2012
27
+ */
28
+ get name() {
29
+ return "21.8";
30
+ }
31
+ }
32
+ //# sourceMappingURL=Rule_21_8_NoProcessControlFunctions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_21_8_NoProcessControlFunctions.js","sourceRoot":"","sources":["../../../src/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAE7E;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,mCAAoC,SAAQ,4BAA4B;IACzF;;OAEG;IACyB,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEhE;;OAEG;IACO,eAAe,GAAG,UAAU,CAAC;IAEvC;;;OAGG;IACO,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5E;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,uBAAuB,CAAC;IAE7D;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
@@ -0,0 +1,25 @@
1
+ import { AnalysisType } from "../../MISRA.js";
2
+ import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
3
+ /**
4
+ * MISRA-C Rule 21.9: The library functions bsearch and qsort of <stdlib.h> shall not be used.
5
+ */
6
+ export default class Rule_21_9_NoGenericSearchOrSort extends DisallowedStdLibFunctionRule {
7
+ /**
8
+ * The name of the standard library
9
+ */
10
+ protected standardLibrary: string;
11
+ /**
12
+ * Names of functions from {@link standardLibrary} that are forbidden.
13
+ * If the set is empty, all functions from {@link standardLibrary} are forbidden.
14
+ */
15
+ protected invalidFunctions: Set<string>;
16
+ /**
17
+ * Scope of analysis
18
+ */
19
+ readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
20
+ /**
21
+ * @returns Rule identifier according to MISRA-C:2012
22
+ */
23
+ get name(): string;
24
+ }
25
+ //# sourceMappingURL=Rule_21_9_NoGenericSearchOrSort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_21_9_NoGenericSearchOrSort.d.ts","sourceRoot":"","sources":["../../../src/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,+BAAgC,SAAQ,4BAA4B;IACrF;;OAEG;IACH,SAAS,CAAC,eAAe,SAAc;IAEvC;;;OAGG;IACH,SAAS,CAAC,gBAAgB,cAAiC;IAE3D;;OAEG;IACH,QAAQ,CAAC,YAAY,wCAAwC;IAE7D;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;CACJ"}
@@ -0,0 +1,27 @@
1
+ import { AnalysisType } from "../../MISRA.js";
2
+ import DisallowedStdLibFunctionRule from "./DisallowedStdLibFunctionRule.js";
3
+ /**
4
+ * MISRA-C Rule 21.9: The library functions bsearch and qsort of <stdlib.h> shall not be used.
5
+ */
6
+ export default class Rule_21_9_NoGenericSearchOrSort extends DisallowedStdLibFunctionRule {
7
+ /**
8
+ * The name of the standard library
9
+ */
10
+ standardLibrary = "stdlib.h";
11
+ /**
12
+ * Names of functions from {@link standardLibrary} that are forbidden.
13
+ * If the set is empty, all functions from {@link standardLibrary} are forbidden.
14
+ */
15
+ invalidFunctions = new Set(["bsearch", "qsort"]);
16
+ /**
17
+ * Scope of analysis
18
+ */
19
+ analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
20
+ /**
21
+ * @returns Rule identifier according to MISRA-C:2012
22
+ */
23
+ get name() {
24
+ return "21.9";
25
+ }
26
+ }
27
+ //# sourceMappingURL=Rule_21_9_NoGenericSearchOrSort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule_21_9_NoGenericSearchOrSort.js","sourceRoot":"","sources":["../../../src/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,4BAA4B,MAAM,mCAAmC,CAAC;AAE7E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,+BAAgC,SAAQ,4BAA4B;IACrF;;OAEG;IACO,eAAe,GAAG,UAAU,CAAC;IAEvC;;;OAGG;IACO,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;IAE3D;;OAEG;IACM,YAAY,GAAG,YAAY,CAAC,uBAAuB,CAAC;IAE7D;;OAEG;IACH,IAAa,IAAI;QACb,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
@@ -1,26 +1,18 @@
1
1
  import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
2
  import MISRARule from "../../MISRARule.js";
3
- import MISRAContext from "../../MISRAContext.js";
4
- import { MISRATransformationReport } from "../../MISRA.js";
3
+ import { AnalysisType, MISRATransformationReport } from "../../MISRA.js";
5
4
  /**
6
5
  * MISRA-C Rule 2.3: A project should not contain unused type declarations.
7
6
  */
8
7
  export default class Rule_2_3_UnusedTypeDecl extends MISRARule {
9
- constructor(context: MISRAContext);
10
8
  /**
11
- * Checks if a given joinpoint uses the specified typedef declaration.
12
- * @param jp - The joinpoint to check
13
- * @param typeDecl - The typedef declaration to check against
14
- * @returns Returns true if the joinpoint uses the given typedef declaration, false otherwise
9
+ * Scope of analysis
15
10
  */
16
- private isTypedefUsed;
11
+ readonly analysisType = AnalysisType.SYSTEM;
17
12
  /**
18
- * Retrieves all joinpoints that use the specified typedef declaration
19
- *
20
- * @param typeDecl - The typedef declaration to search for in the joinpoints
21
- * @returns Array of joinpoints that use the given typedef declaration
13
+ * @returns Rule identifier according to MISRA-C:2012
22
14
  */
23
- private getTypeDefUses;
15
+ get name(): string;
24
16
  /**
25
17
  * Checks if the given joinpoint represents an unused type declaration
26
18
  * @param $jp - Joinpoint to analyze
@@ -38,6 +30,6 @@ export default class Rule_2_3_UnusedTypeDecl extends MISRARule {
38
30
  * @param $jp - Joinpoint to transform
39
31
  * @returns Report detailing the transformation result
40
32
  */
41
- transform($jp: Joinpoint): MISRATransformationReport;
33
+ apply($jp: Joinpoint): MISRATransformationReport;
42
34
  }
43
35
  //# sourceMappingURL=Rule_2_3_UnusedTypeDecl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Rule_2_3_UnusedTypeDecl.d.ts","sourceRoot":"","sources":["../../../src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAoC,MAAM,qCAAqC,CAAC;AAC5G,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAGpF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,SAAS;gBAE9C,OAAO,EAAE,YAAY;IAIjC;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAKrB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAItB;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAW1D;;;;;;;;;OASG;IACH,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAWvD"}
1
+ {"version":3,"file":"Rule_2_3_UnusedTypeDecl.d.ts","sourceRoot":"","sources":["../../../src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAIlG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,SAAS;IAC1D;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAW1D;;;;;;;;;OASG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAanD"}
@@ -1,32 +1,20 @@
1
- import { EnumDecl, RecordJp, TypedefType } from "@specs-feup/clava/api/Joinpoints.js";
2
1
  import MISRARule from "../../MISRARule.js";
3
- import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
4
- import { getBaseType, getTagUses, getTypeDecl, getTypedJps } from "../../utils/utils.js";
2
+ import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
3
+ import { getTypeDefDecl, isTypeDeclUsed } from "../../utils/TypeDeclUtils.js";
4
+ import { isTagDecl } from "../../utils/JoinpointUtils.js";
5
5
  /**
6
6
  * MISRA-C Rule 2.3: A project should not contain unused type declarations.
7
7
  */
8
8
  export default class Rule_2_3_UnusedTypeDecl extends MISRARule {
9
- constructor(context) {
10
- super("2.3", context);
11
- }
12
9
  /**
13
- * Checks if a given joinpoint uses the specified typedef declaration.
14
- * @param jp - The joinpoint to check
15
- * @param typeDecl - The typedef declaration to check against
16
- * @returns Returns true if the joinpoint uses the given typedef declaration, false otherwise
10
+ * Scope of analysis
17
11
  */
18
- isTypedefUsed(jp, typeDecl) {
19
- const jpType = getBaseType(jp);
20
- return !jpType?.isBuiltin && jpType instanceof TypedefType && jpType.decl.astId === typeDecl.astId;
21
- }
12
+ analysisType = AnalysisType.SYSTEM;
22
13
  /**
23
- * Retrieves all joinpoints that use the specified typedef declaration
24
- *
25
- * @param typeDecl - The typedef declaration to search for in the joinpoints
26
- * @returns Array of joinpoints that use the given typedef declaration
14
+ * @returns Rule identifier according to MISRA-C:2012
27
15
  */
28
- getTypeDefUses(typeDecl) {
29
- return getTypedJps().filter(jp => this.isTypedefUsed(jp, typeDecl));
16
+ get name() {
17
+ return "2.3";
30
18
  }
31
19
  /**
32
20
  * Checks if the given joinpoint represents an unused type declaration
@@ -35,12 +23,12 @@ export default class Rule_2_3_UnusedTypeDecl extends MISRARule {
35
23
  * @returns Returns true if the joinpoint violates the rule, false otherwise
36
24
  */
37
25
  match($jp, logErrors = false) {
38
- const typeDecl = getTypeDecl($jp);
26
+ const typeDecl = getTypeDefDecl($jp);
39
27
  if (typeDecl === undefined)
40
28
  return false;
41
- const isUnused = this.getTypeDefUses(typeDecl).length === 0;
29
+ const isUnused = !isTypeDeclUsed(typeDecl);
42
30
  if (logErrors && isUnused) {
43
- this.logMISRAError($jp, `Type declaration ${typeDecl.name} is declared but not used.`);
31
+ this.logMISRAError($jp, `Type declaration '${typeDecl.name}' is declared but not used.`);
44
32
  }
45
33
  return isUnused;
46
34
  }
@@ -54,15 +42,17 @@ export default class Rule_2_3_UnusedTypeDecl extends MISRARule {
54
42
  * @param $jp - Joinpoint to transform
55
43
  * @returns Report detailing the transformation result
56
44
  */
57
- transform($jp) {
45
+ apply($jp) {
58
46
  if (!this.match($jp))
59
47
  return new MISRATransformationReport(MISRATransformationType.NoChange);
60
- if (($jp instanceof RecordJp || $jp instanceof EnumDecl) && $jp.name && getTagUses($jp)) {
48
+ if (isTagDecl($jp) && $jp.name && isTypeDeclUsed($jp)) {
61
49
  $jp.lastChild.detach();
62
50
  return new MISRATransformationReport(MISRATransformationType.DescendantChange);
63
51
  }
64
- $jp.detach();
65
- return new MISRATransformationReport(MISRATransformationType.Removal);
52
+ else {
53
+ $jp.detach();
54
+ return new MISRATransformationReport(MISRATransformationType.Removal);
55
+ }
66
56
  }
67
57
  }
68
58
  //# sourceMappingURL=Rule_2_3_UnusedTypeDecl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Rule_2_3_UnusedTypeDecl.js","sourceRoot":"","sources":["../../../src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAY,QAAQ,EAAc,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAC5G,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEzF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,SAAS;IAE1D,YAAY,OAAqB;QAC7B,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACK,aAAa,CAAC,EAAa,EAAE,QAAqB;QACtD,MAAM,MAAM,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;QAC/B,OAAO,CAAC,MAAM,EAAE,SAAS,IAAI,MAAM,YAAY,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,CAAC;IACvG,CAAC;IAED;;;;;OAKG;IACK,cAAc,CAAC,QAAqB;QACxC,O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;QACnF,CAAC;aAAM,CAAC;YACJ,GAAG,CAAC,MAAM,EAAE,CAAC;YACb,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;QAC1E,CAAC;IAEL,CAAC;CACJ"}
@@ -1,15 +1,21 @@
1
1
  import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
2
  import MISRARule from "../../MISRARule.js";
3
- import MISRAContext from "../../MISRAContext.js";
4
- import { MISRATransformationReport } from "../../MISRA.js";
3
+ import { AnalysisType, MISRATransformationReport } from "../../MISRA.js";
5
4
  /**
6
5
  * MISRA-C Rule 2.4: A project should not contain unused tag declarations.
7
6
  */
8
7
  export default class Rule_2_4_UnusedTagDecl extends MISRARule {
9
- constructor(context: MISRAContext);
8
+ /**
9
+ * Scope of analysis
10
+ */
11
+ readonly analysisType = AnalysisType.SYSTEM;
12
+ /**
13
+ * @returns Rule identifier according to MISRA-C:2012
14
+ */
15
+ get name(): string;
10
16
  /**
11
17
  * Checks if the given joinpoint is an unused tag declaration
12
- * A tag is considered to be unused if it has no references in the code or is only used within a typedef
18
+ * A tag is considered unused if it has no references in the code or if it's only used within a typedef
13
19
  *
14
20
  * @param $jp - Joinpoint to analyze
15
21
  * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
@@ -18,12 +24,12 @@ export default class Rule_2_4_UnusedTagDecl extends MISRARule {
18
24
  match($jp: Joinpoint, logErrors?: boolean): boolean;
19
25
  /**
20
26
  * Transforms the joinpoint if it is an unused tag declaration
21
- * - If the Joinpoint is a tag declared in a typedef, it removes the name.
22
- * - Otherwise, the Joinpoint is detached.
27
+ * - If the joinpoint is a tag declared in a typedef, it removes the name.
28
+ * - Otherwise, the joinpoint is detached.
23
29
  *
24
30
  * @param $jp - Joinpoint to transform
25
31
  * @returns Report detailing the transformation result
26
32
  */
27
- transform($jp: Joinpoint): MISRATransformationReport;
33
+ apply($jp: Joinpoint): MISRATransformationReport;
28
34
  }
29
35
  //# sourceMappingURL=Rule_2_4_UnusedTagDecl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Rule_2_4_UnusedTagDecl.d.ts","sourceRoot":"","sources":["../../../src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA+C,MAAM,qCAAqC,CAAC;AAC7G,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAGpF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,SAAS;gBAE7C,OAAO,EAAE,YAAY;IAIjC;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAiB1D;;;;;;;OAOG;IACH,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAWvD"}
1
+ {"version":3,"file":"Rule_2_4_UnusedTagDecl.d.ts","sourceRoot":"","sources":["../../../src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAY,MAAM,qCAAqC,CAAC;AAC1E,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAIlG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,SAAS;IACzD;;OAEG;IACH,QAAQ,CAAC,YAAY,uBAAuB;IAE5C;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAwB1D;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAYnD"}
@@ -1,49 +1,63 @@
1
- import { RecordJp, EnumDecl } from "@specs-feup/clava/api/Joinpoints.js";
1
+ import { DeclStmt } from "@specs-feup/clava/api/Joinpoints.js";
2
2
  import MISRARule from "../../MISRARule.js";
3
- import { MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
4
- import { getTagUses, hasTypeDecl } from "../../utils/utils.js";
3
+ import { AnalysisType, MISRATransformationReport, MISRATransformationType } from "../../MISRA.js";
4
+ import { hasTypeDefDecl, isTypeDeclUsed } from "../../utils/TypeDeclUtils.js";
5
+ import { isTagDecl } from "../../utils/JoinpointUtils.js";
5
6
  /**
6
7
  * MISRA-C Rule 2.4: A project should not contain unused tag declarations.
7
8
  */
8
9
  export default class Rule_2_4_UnusedTagDecl extends MISRARule {
9
- constructor(context) {
10
- super("2.4", context);
10
+ /**
11
+ * Scope of analysis
12
+ */
13
+ analysisType = AnalysisType.SYSTEM;
14
+ /**
15
+ * @returns Rule identifier according to MISRA-C:2012
16
+ */
17
+ get name() {
18
+ return "2.4";
11
19
  }
12
20
  /**
13
21
  * Checks if the given joinpoint is an unused tag declaration
14
- * A tag is considered to be unused if it has no references in the code or is only used within a typedef
22
+ * A tag is considered unused if it has no references in the code or if it's only used within a typedef
15
23
  *
16
24
  * @param $jp - Joinpoint to analyze
17
25
  * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
18
26
  * @returns Returns true if the joinpoint violates the rule, false otherwise
19
27
  */
20
28
  match($jp, logErrors = false) {
21
- if (!($jp instanceof RecordJp || $jp instanceof EnumDecl))
29
+ if (!(isTagDecl($jp) || ($jp instanceof DeclStmt && $jp.decls.length === 1))) {
22
30
  return false;
23
- const containsTypeDecl = hasTypeDecl($jp);
24
- const jpName = $jp.name;
25
- if (containsTypeDecl && jpName === undefined || jpName === null || jpName.trim().length === 0) {
31
+ }
32
+ if ($jp instanceof DeclStmt && !isTagDecl($jp.decls[0])) {
33
+ return false;
34
+ }
35
+ const tagJp = $jp instanceof DeclStmt ? $jp.decls[0] : $jp;
36
+ const containsTypeDecl = hasTypeDefDecl(tagJp);
37
+ const jpName = tagJp.name;
38
+ if (containsTypeDecl && (jpName === undefined || jpName === null || jpName.trim().length === 0)) {
26
39
  return false;
27
40
  }
28
- const isUnused = getTagUses($jp).length === 0;
41
+ const isUnused = !isTypeDeclUsed(tagJp);
29
42
  if (isUnused && logErrors) {
30
- this.logMISRAError($jp, containsTypeDecl ? `The tag '${$jp.name}' is declared but only used in a typedef.` : `The tag '${$jp.name}' is declared but not used.`);
43
+ this.logMISRAError(tagJp, containsTypeDecl ? `The tag '${tagJp.name}' is declared but only used in a typedef.` : `The tag '${tagJp.name}' is declared but not used.`);
31
44
  }
32
45
  return isUnused;
33
46
  }
34
47
  /**
35
48
  * Transforms the joinpoint if it is an unused tag declaration
36
- * - If the Joinpoint is a tag declared in a typedef, it removes the name.
37
- * - Otherwise, the Joinpoint is detached.
49
+ * - If the joinpoint is a tag declared in a typedef, it removes the name.
50
+ * - Otherwise, the joinpoint is detached.
38
51
  *
39
52
  * @param $jp - Joinpoint to transform
40
53
  * @returns Report detailing the transformation result
41
54
  */
42
- transform($jp) {
55
+ apply($jp) {
43
56
  if (!this.match($jp))
44
57
  return new MISRATransformationReport(MISRATransformationType.NoChange);
45
- if (hasTypeDecl($jp)) {
46
- $jp.setName('');
58
+ const tagJp = $jp instanceof DeclStmt ? $jp.decls[0] : $jp;
59
+ if (hasTypeDefDecl(tagJp)) {
60
+ (tagJp).setName('');
47
61
  return new MISRATransformationReport(MISRATransformationType.DescendantChange);
48
62
  }
49
63
  $jp.detach();
@@ -1 +1 @@
1
- {"version":3,"file":"Rule_2_4_UnusedTagDecl.js","sourceRoot":"","sources":["../../../src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,QAAQ,EAAE,QAAQ,EAA2B,MAAM,qCAAqC,CAAC;AAC7G,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,yBAAy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G,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,IAAI,yBAAyB,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAC1E,CAAC;CACJ"}
@@ -1,15 +1,34 @@
1
1
  import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
2
2
  import MISRARule from "../../MISRARule.js";
3
- import MISRAContext from "../../MISRAContext.js";
4
- import { MISRATransformationReport } from "../../MISRA.js";
3
+ import { AnalysisType, MISRATransformationReport } from "../../MISRA.js";
5
4
  /**
6
- * Rule 2.6: Unused Labels.
7
- * Checks for labels within a function that are not used.
5
+ * MISRA-C Rule 2.6: A function should not contain unused label declarations.
6
+ *
8
7
  */
9
8
  export default class Rule_2_6_UnusedLabels extends MISRARule {
10
- constructor(context: MISRAContext);
11
- private getUnusedLabels;
9
+ /**
10
+ * Scope of analysis
11
+ */
12
+ readonly analysisType = AnalysisType.SINGLE_TRANSLATION_UNIT;
13
+ /**
14
+ * @returns Rule identifier according to MISRA-C:2012
15
+ */
16
+ get name(): string;
17
+ /**
18
+ * Checks if the given joinpoint represents a function with unused labels.
19
+ * A tag is considered unused if it is declared but not referenced by any goto statement.
20
+ *
21
+ * @param $jp - Joinpoint to analyze
22
+ * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected
23
+ * @returns Returns true if the joinpoint violates the rule, false otherwise
24
+ */
12
25
  match($jp: Joinpoint, logErrors?: boolean): boolean;
13
- transform($jp: Joinpoint): MISRATransformationReport;
26
+ /**
27
+ * Removes all unused labels if the provided joinpoint represents a function
28
+ *
29
+ * @param $jp - Joinpoint to transform
30
+ * @returns Report detailing the transformation result
31
+ */
32
+ apply($jp: Joinpoint): MISRATransformationReport;
14
33
  }
15
34
  //# sourceMappingURL=Rule_2_6_UnusedLabels.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Rule_2_6_UnusedLabels.d.ts","sourceRoot":"","sources":["../../../src/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,SAAS,EAAa,MAAM,qCAAqC,CAAC;AACjG,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAEpF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,SAAS;gBAE5C,OAAO,EAAE,YAAY;IAIjC,OAAO,CAAC,eAAe;IAMvB,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAa1D,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAUvD"}
1
+ {"version":3,"file":"Rule_2_6_UnusedLabels.d.ts","sourceRoot":"","sources":["../../../src/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAA2B,MAAM,gBAAgB,CAAC;AAGlG;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,SAAS;IACxD;;OAEG;IACH,QAAQ,CAAC,YAAY,wCAAwC;IAE7D;;OAEG;IACH,IAAa,IAAI,IAAI,MAAM,CAE1B;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO;IAa1D;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,yBAAyB;CAUnD"}