@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.
- package/.gitignore +8 -0
- package/README.md +53 -19
- package/dist/MISRA.d.ts +28 -10
- package/dist/MISRA.d.ts.map +1 -1
- package/dist/MISRA.js +30 -10
- package/dist/MISRA.js.map +1 -1
- package/dist/MISRAContext.d.ts +65 -11
- package/dist/MISRAContext.d.ts.map +1 -1
- package/dist/MISRAContext.js +131 -35
- package/dist/MISRAContext.js.map +1 -1
- package/dist/MISRARule.d.ts +38 -25
- package/dist/MISRARule.d.ts.map +1 -1
- package/dist/MISRARule.js +40 -18
- package/dist/MISRARule.js.map +1 -1
- package/dist/MISRATool.d.ts +46 -5
- package/dist/MISRATool.d.ts.map +1 -1
- package/dist/MISRATool.js +118 -45
- package/dist/MISRATool.js.map +1 -1
- package/dist/StandardGuideline.d.ts +22 -0
- package/dist/StandardGuideline.d.ts.map +1 -0
- package/dist/StandardGuideline.js +12 -0
- package/dist/StandardGuideline.js.map +1 -0
- package/dist/ast-visitor/Context.d.ts +11 -0
- package/dist/ast-visitor/Context.d.ts.map +1 -0
- package/dist/ast-visitor/Context.js +15 -0
- package/dist/ast-visitor/Context.js.map +1 -0
- package/dist/ast-visitor/Visit.d.ts +23 -0
- package/dist/ast-visitor/Visit.d.ts.map +1 -0
- package/dist/ast-visitor/Visit.js +18 -0
- package/dist/ast-visitor/Visit.js.map +1 -0
- package/dist/ast-visitor/VisitWithContext.d.ts +32 -0
- package/dist/ast-visitor/VisitWithContext.d.ts.map +1 -0
- package/dist/ast-visitor/VisitWithContext.js +26 -0
- package/dist/ast-visitor/VisitWithContext.js.map +1 -0
- package/dist/main.js +1 -2
- package/dist/main.js.map +1 -1
- package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.d.ts +27 -0
- package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.d.ts.map +1 -0
- package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.js +98 -0
- package/dist/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts +45 -6
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js +91 -8
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts +15 -5
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js +20 -6
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts +11 -5
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js +13 -10
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts +11 -6
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js +19 -11
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts +15 -5
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js +24 -10
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts +22 -6
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts.map +1 -1
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js +37 -10
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.d.ts +66 -0
- package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.d.ts.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.js +209 -0
- package/dist/rules/Section17_Functions/Rule_17_3_ImplicitFunction.js.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts +37 -12
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js +112 -39
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts +15 -5
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js +21 -7
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts +11 -6
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts.map +1 -1
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js +17 -8
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js.map +1 -1
- package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.d.ts +105 -0
- package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.js +258 -0
- package/dist/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.d.ts +25 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.js +27 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.d.ts +29 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.js +31 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.d.ts +25 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.js +27 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.d.ts +25 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.js +27 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.d.ts +25 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.js +27 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.d.ts +30 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.js +32 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.js.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.d.ts +25 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.d.ts.map +1 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.js +27 -0
- package/dist/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.js.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts +6 -14
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js +17 -27
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts +13 -7
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js +31 -17
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts +26 -7
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js +32 -14
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts +48 -6
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts.map +1 -1
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js +84 -34
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js.map +1 -1
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts +24 -5
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts.map +1 -1
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js +27 -7
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js.map +1 -1
- package/dist/rules/Section5_Identifiers/IdentifierRenameRule.d.ts +46 -0
- package/dist/rules/Section5_Identifiers/IdentifierRenameRule.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/IdentifierRenameRule.js +40 -0
- package/dist/rules/Section5_Identifiers/IdentifierRenameRule.js.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.d.ts +25 -0
- package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.js +46 -0
- package/dist/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.js.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.d.ts +26 -0
- package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.js +54 -0
- package/dist/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.js.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.d.ts +27 -0
- package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.js +55 -0
- package/dist/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.js.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.d.ts +24 -0
- package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.js +42 -0
- package/dist/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.js.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.d.ts +24 -0
- package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.d.ts.map +1 -0
- package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.js +42 -0
- package/dist/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.js.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.d.ts +35 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.d.ts.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.js +98 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.js.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.d.ts +35 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.d.ts.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.js +76 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.js.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.d.ts +32 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.d.ts.map +1 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.js +57 -0
- package/dist/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.js.map +1 -0
- package/dist/rules/UserConfigurableRule.d.ts +55 -0
- package/dist/rules/UserConfigurableRule.d.ts.map +1 -0
- package/dist/rules/UserConfigurableRule.js +16 -0
- package/dist/rules/UserConfigurableRule.js.map +1 -0
- package/dist/rules/index.d.ts +11 -18
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +47 -7
- package/dist/rules/index.js.map +1 -1
- package/dist/tests/Section17_Functions/misra_config.json +10 -0
- package/dist/tests/Section21-StandardLibraries/misra_config.json +88 -0
- package/dist/tests/Section21-StandardLibraries/problematic_misra_config.json +19 -0
- package/dist/tests/utils.d.ts +6 -3
- package/dist/tests/utils.d.ts.map +1 -1
- package/dist/tests/utils.js +33 -7
- package/dist/tests/utils.js.map +1 -1
- package/dist/utils/CallUtils.d.ts +15 -0
- package/dist/utils/CallUtils.d.ts.map +1 -0
- package/dist/utils/CallUtils.js +34 -0
- package/dist/utils/CallUtils.js.map +1 -0
- package/dist/utils/CommentUtils.d.ts +21 -0
- package/dist/utils/CommentUtils.d.ts.map +1 -0
- package/dist/utils/CommentUtils.js +27 -0
- package/dist/utils/CommentUtils.js.map +1 -0
- package/dist/utils/FileUtils.d.ts +67 -0
- package/dist/utils/FileUtils.d.ts.map +1 -0
- package/dist/utils/FileUtils.js +144 -0
- package/dist/utils/FileUtils.js.map +1 -0
- package/dist/utils/FunctionUtils.d.ts +47 -0
- package/dist/utils/FunctionUtils.d.ts.map +1 -0
- package/dist/utils/FunctionUtils.js +87 -0
- package/dist/utils/FunctionUtils.js.map +1 -0
- package/dist/utils/IdentifierUtils.d.ts +63 -0
- package/dist/utils/IdentifierUtils.d.ts.map +1 -0
- package/dist/utils/IdentifierUtils.js +133 -0
- package/dist/utils/IdentifierUtils.js.map +1 -0
- package/dist/utils/JoinpointUtils.d.ts +36 -0
- package/dist/utils/JoinpointUtils.d.ts.map +1 -0
- package/dist/utils/JoinpointUtils.js +63 -0
- package/dist/utils/JoinpointUtils.js.map +1 -0
- package/dist/utils/ProgramUtils.d.ts +39 -0
- package/dist/utils/ProgramUtils.d.ts.map +1 -0
- package/dist/utils/ProgramUtils.js +97 -0
- package/dist/utils/ProgramUtils.js.map +1 -0
- package/dist/utils/SwitchUtils.d.ts +21 -0
- package/dist/utils/SwitchUtils.d.ts.map +1 -0
- package/dist/utils/SwitchUtils.js +47 -0
- package/dist/utils/SwitchUtils.js.map +1 -0
- package/dist/utils/TypeDeclUtils.d.ts +35 -0
- package/dist/utils/TypeDeclUtils.d.ts.map +1 -0
- package/dist/utils/TypeDeclUtils.js +78 -0
- package/dist/utils/TypeDeclUtils.js.map +1 -0
- package/dist/utils/VarUtils.d.ts +51 -0
- package/dist/utils/VarUtils.d.ts.map +1 -0
- package/dist/utils/VarUtils.js +91 -0
- package/dist/utils/VarUtils.js.map +1 -0
- package/package.json +16 -7
- package/src/MISRA.ts +33 -17
- package/src/MISRAContext.ts +128 -30
- package/src/MISRARule.ts +61 -29
- package/src/MISRATool.ts +126 -42
- package/src/StandardGuideline.ts +23 -0
- package/src/ast-visitor/Context.ts +16 -0
- package/src/ast-visitor/Visit.ts +26 -0
- package/src/ast-visitor/VisitWithContext.ts +42 -0
- package/src/main.ts +1 -4
- package/src/rules/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.ts +114 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.ts +103 -13
- package/src/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.ts +24 -10
- package/src/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.ts +17 -8
- package/src/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.ts +20 -12
- package/src/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.ts +23 -12
- package/src/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.ts +44 -13
- package/src/rules/Section17_Functions/Rule_17_3_ImplicitFunction.ts +153 -104
- package/src/rules/Section17_Functions/Rule_17_4_NonVoidReturn.ts +114 -44
- package/src/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.ts +27 -10
- package/src/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.ts +20 -12
- package/src/rules/Section21-StandardLibraries/DisallowedStdLibFunctionRule.ts +317 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.ts +30 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.ts +35 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.ts +30 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.ts +30 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.ts +29 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.ts +36 -0
- package/src/rules/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.ts +30 -0
- package/src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts +14 -29
- package/src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts +33 -19
- package/src/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.ts +33 -20
- package/src/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.ts +90 -45
- package/src/rules/Section3_Comments/Rule_3_1_CommentSequences.ts +27 -8
- package/src/rules/Section5_Identifiers/IdentifierRenameRule.ts +63 -0
- package/src/rules/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.ts +52 -0
- package/src/rules/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.ts +62 -0
- package/src/rules/Section5_Identifiers/Rule_5_7_UniqueTagNames.ts +61 -0
- package/src/rules/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.ts +47 -0
- package/src/rules/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.ts +47 -0
- package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.ts +118 -0
- package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.ts +89 -0
- package/src/rules/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.ts +65 -0
- package/src/rules/UserConfigurableRule.ts +60 -0
- package/src/rules/index.ts +45 -7
- package/src/tests/Section13_SideEffects/Rule_13_6_SafeSizeOfOperand.test.ts +114 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.test.ts +7 -5
- package/src/tests/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.test.ts +40 -13
- package/src/tests/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.test.ts +10 -12
- package/src/tests/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.test.ts +5 -5
- package/src/tests/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.test.ts +5 -5
- package/src/tests/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.test.ts +5 -5
- package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions.test.ts +68 -40
- package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions_MissingConfig.test.ts +98 -0
- package/src/tests/Section17_Functions/Rule_17_3_ImplicitFunctions_ProblematicConfig.test.ts +71 -0
- package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn.test.ts +103 -49
- package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn_MissingConfig.test.ts +7 -7
- package/src/tests/Section17_Functions/Rule_17_6_StaticArraySizeParam.test.ts +36 -7
- package/src/tests/Section17_Functions/Rule_17_7_UnusedReturnValue.test.ts +25 -21
- package/src/tests/Section17_Functions/misra_config.json +4 -3
- package/src/tests/Section21-StandardLibraries/Rule_21_10_NoTimeDateFunctions.test.ts +62 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_11_NoTgmathFunctions.test.ts +67 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory.test.ts +84 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory_MissingConfig.test.ts +33 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_3_NoDynamicMemory_ProblematicConfig.test.ts +71 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_6_NoStdIOFunctions.test.ts +63 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_7_NoNumericStringConversions.test.ts +91 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_8_NoProcessControlFunctions.test.ts +65 -0
- package/src/tests/Section21-StandardLibraries/Rule_21_9_NoGenericSearchOrSort.test.ts +89 -0
- package/src/tests/Section21-StandardLibraries/misra_config.json +88 -0
- package/src/tests/Section21-StandardLibraries/problematic_misra_config.json +19 -0
- package/src/tests/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.test.ts +148 -113
- package/src/tests/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.test.ts +243 -163
- package/src/tests/Section2_UnusedCode/Rule_2_6_UnusedLabels.test.ts +32 -20
- package/src/tests/Section2_UnusedCode/Rule_2_7_UnusedParameters.test.ts +36 -30
- package/src/tests/Section3_Comments/Rule_3_1_CommentSequences.test.ts +37 -8
- package/src/tests/Section5_Identifiers/Rule_5_1_DistinctExternalIdentifiers.test.ts +78 -0
- package/src/tests/Section5_Identifiers/Rule_5_6_UniqueTypedefNames.test.ts +120 -0
- package/src/tests/Section5_Identifiers/Rule_5_7_UniqueTagNames.test.ts +51 -0
- package/src/tests/Section5_Identifiers/Rule_5_8_UniqueExternalLinkIdentifiers.test.ts +73 -0
- package/src/tests/Section5_Identifiers/Rule_5_9_UniqueInternalLinkIdentifiers.test.ts +97 -0
- package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.test.ts +160 -0
- package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.test.ts +46 -0
- package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_9_BlockScopeDefinition.test.ts +69 -0
- package/src/tests/utils.ts +32 -7
- package/src/utils/CallUtils.ts +37 -0
- package/src/utils/CommentUtils.ts +29 -0
- package/src/utils/FileUtils.ts +169 -0
- package/src/utils/FunctionUtils.ts +97 -0
- package/src/utils/IdentifierUtils.ts +142 -0
- package/src/utils/JoinpointUtils.ts +70 -0
- package/src/utils/ProgramUtils.ts +107 -0
- package/src/utils/SwitchUtils.ts +52 -0
- package/src/utils/TypeDeclUtils.ts +88 -0
- package/src/utils/VarUtils.ts +102 -0
- package/tsconfig.json +2 -1
- package/src/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.ts +0 -120
- package/src/rules/Section3_Comments/Rule_3_2_LineSplicing.ts +0 -36
- 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
|
-
|
|
37
|
+
a_16_3 = 1;
|
|
38
38
|
break;
|
|
39
|
-
case 2:
|
|
40
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
36
|
-
{
|
|
36
|
+
`static void foo16_4_3 (void) {
|
|
37
37
|
int x;
|
|
38
|
-
switch (
|
|
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(
|
|
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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
12
|
-
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
36
|
-
|
|
37
|
-
(
|
|
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
|
|
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:
|
|
51
|
-
|
|
52
|
-
|
|
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.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
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
|
+
});
|