@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
|
@@ -2,197 +2,277 @@ import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
|
2
2
|
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
3
3
|
import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
|
|
4
4
|
|
|
5
|
+
const utils_code = `
|
|
6
|
+
#include <stdint.h>
|
|
7
|
+
#include <stdbool.h>
|
|
8
|
+
|
|
9
|
+
void use_uint16(uint16_t param) {
|
|
10
|
+
(void)(param & 0xFF00U);
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
const utils_header = `
|
|
15
|
+
#include <stdint.h>
|
|
16
|
+
#include <stdbool.h>
|
|
17
|
+
|
|
18
|
+
extern void use_uint16(uint16_t param);
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
const misraExample = `
|
|
22
|
+
#include "utils.h"
|
|
23
|
+
|
|
24
|
+
static void unusedtag (void) {
|
|
25
|
+
enum state { // Violation of rule 2.4
|
|
26
|
+
S_init,
|
|
27
|
+
S_run,
|
|
28
|
+
S_sleep
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static void test_2_4_1() {
|
|
33
|
+
typedef struct record_t { // Violation of rule 2.4
|
|
34
|
+
uint16_t key;
|
|
35
|
+
uint16_t val;
|
|
36
|
+
} record1_t;
|
|
37
|
+
|
|
38
|
+
typedef struct {
|
|
39
|
+
uint16_t key;
|
|
40
|
+
uint16_t val;
|
|
41
|
+
} record2_t;
|
|
42
|
+
|
|
43
|
+
record1_t var1;
|
|
44
|
+
record2_t var2;
|
|
45
|
+
use_uint16(var1.key + var1.val + var2.key + var2.val);
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
|
|
5
50
|
const failingCodeEnum1 = `
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
51
|
+
enum MyEnum {
|
|
52
|
+
RED, GREEN, BLUE
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
enum EnumForCast1 {
|
|
56
|
+
RED2, GREEN2, BLUE2
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
enum EnumForCast2 {
|
|
60
|
+
RED3, GREEN3, BLUE3
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
enum MyEnum2 {
|
|
64
|
+
RED4, GREEN4, BLUE4
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
enum EnumForPtr {
|
|
68
|
+
RED5, GREEN5, BLUE5
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
enum EnumForArray {
|
|
72
|
+
RED6, GREEN6, BLUE6
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Non-compliant
|
|
76
|
+
enum UnusedEnum {
|
|
77
|
+
RED7, GREEN7, BLUE7
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
static void enumAsParam(enum MyEnum color) {
|
|
81
|
+
int i;
|
|
82
|
+
if (color == RED) {
|
|
83
|
+
i = 1;
|
|
40
84
|
}
|
|
85
|
+
}
|
|
41
86
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
87
|
+
static enum EnumForCast1 enumAsReturn() {
|
|
88
|
+
return (enum EnumForCast1) RED2;
|
|
89
|
+
};
|
|
45
90
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
91
|
+
static enum EnumForCast2 enumAsReturn2() {
|
|
92
|
+
int id = 2;
|
|
93
|
+
return (enum EnumForCast2) id;
|
|
94
|
+
};
|
|
50
95
|
|
|
96
|
+
static void use_tags_2_4_1() {
|
|
51
97
|
enum MyEnum2 color_enum = RED4;
|
|
52
|
-
|
|
53
98
|
enum EnumForPtr *colorPtr;
|
|
54
|
-
|
|
55
99
|
enum EnumForArray colorArray[3];
|
|
100
|
+
|
|
101
|
+
(void) color_enum;
|
|
102
|
+
(void) colorPtr;
|
|
103
|
+
(void) colorArray;
|
|
104
|
+
}
|
|
56
105
|
`;
|
|
57
106
|
|
|
58
107
|
const failingCodeEnum2 = `
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
108
|
+
typedef enum {
|
|
109
|
+
A1,
|
|
110
|
+
B1,
|
|
111
|
+
C1
|
|
112
|
+
} ColorEnum2;
|
|
113
|
+
|
|
114
|
+
typedef enum MyColors {
|
|
115
|
+
A2,
|
|
116
|
+
B3,
|
|
117
|
+
C4
|
|
118
|
+
} ColorOption;
|
|
119
|
+
|
|
120
|
+
// MyColors2 tag should be removed
|
|
121
|
+
typedef enum MyColors2 {
|
|
122
|
+
A5,
|
|
123
|
+
B6,
|
|
124
|
+
C7
|
|
125
|
+
} ColorOption2;
|
|
126
|
+
|
|
127
|
+
static void use_tags_2_4_2() {
|
|
71
128
|
enum MyColors my_color = A2;
|
|
72
129
|
ColorOption color_option = B3;
|
|
73
|
-
|
|
74
|
-
// MyColors2 tag should be removed
|
|
75
|
-
typedef enum MyColors2 {
|
|
76
|
-
A5,
|
|
77
|
-
B6,
|
|
78
|
-
C7
|
|
79
|
-
} ColorOption2;
|
|
130
|
+
ColorEnum2 colorEnum2 = A1;
|
|
80
131
|
ColorOption2 color2 = B6;
|
|
132
|
+
|
|
133
|
+
(void) my_color;
|
|
134
|
+
(void) color_option;
|
|
135
|
+
(void) colorEnum2;
|
|
136
|
+
(void) color2;
|
|
137
|
+
}
|
|
81
138
|
`;
|
|
82
139
|
|
|
83
140
|
const failingCodeStruct1 = `
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
struct
|
|
125
|
-
struct
|
|
141
|
+
struct MyStruct {
|
|
142
|
+
int x;
|
|
143
|
+
float y;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
struct StructForReturn1 {
|
|
147
|
+
int x;
|
|
148
|
+
float y;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
struct MyStruct2 {
|
|
152
|
+
int x;
|
|
153
|
+
float y;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
struct StructForPtr {
|
|
157
|
+
int x;
|
|
158
|
+
float y;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
struct StructForArray {
|
|
162
|
+
int x;
|
|
163
|
+
float y;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// Non-compliant: should be removed
|
|
167
|
+
struct UnusedStruct {
|
|
168
|
+
int x;
|
|
169
|
+
float y;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
static void structAsParam(struct MyStruct s) {
|
|
173
|
+
int xField = s.x;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static struct StructForReturn1 structAsReturn() {
|
|
177
|
+
return (struct StructForReturn1){1, 1.5f};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
static void use_tags_2_4_3() {
|
|
181
|
+
static struct MyStruct2 myStruct = {10, 20.5f};
|
|
182
|
+
static struct StructForPtr *structPtr;
|
|
183
|
+
static struct StructForArray structArray[3];
|
|
184
|
+
|
|
185
|
+
(void) myStruct;
|
|
186
|
+
(void) structPtr;
|
|
187
|
+
(void) structArray;
|
|
188
|
+
}
|
|
126
189
|
`;
|
|
127
190
|
|
|
128
191
|
const failingCodeStruct2 = `
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
192
|
+
typedef struct {
|
|
193
|
+
int x;
|
|
194
|
+
float y;
|
|
195
|
+
} ColorStruct;
|
|
196
|
+
|
|
197
|
+
typedef struct MyStruct5 {
|
|
198
|
+
int x;
|
|
199
|
+
float y;
|
|
200
|
+
} ColorStruct2;
|
|
201
|
+
|
|
202
|
+
// Violation: MyStruct3 tag will be removed
|
|
203
|
+
typedef struct MyStruct3 {
|
|
204
|
+
int x;
|
|
205
|
+
float y;
|
|
206
|
+
} ColorStruct3;
|
|
207
|
+
|
|
208
|
+
static void use_tags_2_4_4() {
|
|
209
|
+
static ColorStruct colorStruct = {1, 2.5};
|
|
210
|
+
static struct MyStruct5 struct5 = {2, 4.5};
|
|
211
|
+
static ColorStruct2 colorStruct2 = {1, 2.5};
|
|
212
|
+
static ColorStruct3 colorStruct3 = {10, 5.5};
|
|
213
|
+
|
|
214
|
+
(void) colorStruct;
|
|
215
|
+
(void) struct5;
|
|
216
|
+
(void) colorStruct2;
|
|
217
|
+
(void) colorStruct3;
|
|
218
|
+
}
|
|
148
219
|
`;
|
|
149
220
|
|
|
150
221
|
const failingCodeUnion1 = `
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
222
|
+
union MyUnion {
|
|
223
|
+
int x;
|
|
224
|
+
float y;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
union UnionForReturn1 {
|
|
228
|
+
int x;
|
|
229
|
+
float y;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
union MyUnion2 {
|
|
233
|
+
int x;
|
|
234
|
+
float y;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
union UnionForPtr {
|
|
238
|
+
int x;
|
|
239
|
+
float y;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
union UnionForArray {
|
|
243
|
+
int x;
|
|
244
|
+
float y;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// Non-compliant: should be removed
|
|
248
|
+
union UnusedUnion {
|
|
249
|
+
int x;
|
|
250
|
+
float y;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
static void unionAsParam(union MyUnion u) {
|
|
254
|
+
int xField = u.x;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
static union UnionForReturn1 unionAsReturn() {
|
|
258
|
+
return (union UnionForReturn1){.x = 1};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
static void use_tags_2_4_5() {
|
|
190
262
|
union MyUnion2 myUnion = {.y = 20.5f};
|
|
191
263
|
union UnionForPtr *unionPtr;
|
|
192
264
|
union UnionForArray unionArray[3];
|
|
265
|
+
|
|
266
|
+
(void) myUnion;
|
|
267
|
+
(void) unionPtr;
|
|
268
|
+
(void) unionArray;
|
|
269
|
+
}
|
|
193
270
|
`;
|
|
194
271
|
|
|
195
272
|
const files: TestFile[] = [
|
|
273
|
+
{ name: "utils.c", code: utils_code },
|
|
274
|
+
{ name: "utils.h", code: utils_header },
|
|
275
|
+
{ name: "misra_example.c", code: misraExample },
|
|
196
276
|
{ name: "testEnum1.c", code: failingCodeEnum1 },
|
|
197
277
|
{ name: "testEnum2.c", code: failingCodeEnum2 },
|
|
198
278
|
{ name: "testStruct1.c", code: failingCodeStruct1 },
|
|
@@ -204,7 +284,7 @@ describe("Rule 2.4", () => {
|
|
|
204
284
|
registerSourceCode(files);
|
|
205
285
|
|
|
206
286
|
it("should detect errors in bad.c", () => {
|
|
207
|
-
expect(countMISRAErrors()).toBe(
|
|
287
|
+
expect(countMISRAErrors()).toBe(7);
|
|
208
288
|
|
|
209
289
|
expect(countMISRAErrors(Query.search(FileJp, {name: "testEnum1.c"}).first()!)).toBe(1);
|
|
210
290
|
expect(countMISRAErrors(Query.search(FileJp, {name: "testEnum2.c"}).first()!)).toBe(1);
|
|
@@ -3,44 +3,56 @@ import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestF
|
|
|
3
3
|
import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
|
|
4
4
|
|
|
5
5
|
const passingCode = `
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
static int test_2_6_2() {
|
|
7
|
+
int x = 0;
|
|
8
|
+
goto label1;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
label1:
|
|
11
|
+
x++;
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
15
16
|
|
|
16
17
|
const failingCode = `
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
static int test_2_6_1() {
|
|
19
|
+
int x = 0;
|
|
20
|
+
label1: // Violation of rule 2.6
|
|
21
|
+
x = 1;
|
|
22
|
+
label2: // Violation of rule 2.6
|
|
23
|
+
x++;
|
|
24
|
+
|
|
25
|
+
goto label3;
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
label3:
|
|
28
|
+
x += 4;
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
const misraExample = `
|
|
34
|
+
static void unused_label ( void ) {
|
|
35
|
+
int x = 6;
|
|
36
|
+
label1: // Violation of rule 2.6
|
|
37
|
+
x++;
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
30
40
|
|
|
31
41
|
const files: TestFile[] = [
|
|
32
42
|
{ name: "bad.c", code: failingCode },
|
|
33
|
-
{ name: "good.c", code: passingCode }
|
|
43
|
+
{ name: "good.c", code: passingCode },
|
|
44
|
+
{ name: "misra_example.c", code: misraExample }
|
|
34
45
|
];
|
|
35
46
|
|
|
36
47
|
describe("Rule 2.6", () => {
|
|
37
48
|
registerSourceCode(files);
|
|
38
49
|
|
|
39
50
|
it("should detect errors in bad.c", () => {
|
|
40
|
-
expect(countMISRAErrors()).toBe(
|
|
51
|
+
expect(countMISRAErrors()).toBe(3);
|
|
41
52
|
|
|
42
53
|
expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(2);
|
|
43
54
|
expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
|
|
55
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "misra_example.c"}).first()!)).toBe(1);
|
|
44
56
|
});
|
|
45
57
|
|
|
46
58
|
it("should correct errors in bad.c", () => {
|
|
@@ -1,52 +1,58 @@
|
|
|
1
|
-
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
2
1
|
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
3
|
-
import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
|
|
4
2
|
|
|
5
3
|
const failingCode = `
|
|
6
|
-
|
|
4
|
+
int foo(int x, int y, int z);
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
int foo(int x, int y, int z) {
|
|
7
|
+
y++;
|
|
8
|
+
return y;
|
|
9
|
+
}
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
int main() {
|
|
12
|
+
int a = 5, b = 10, c = 15;
|
|
13
|
+
int result1 = foo(a, b, c);
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
int result2 = result1 + foo(a, b, c);
|
|
16
|
+
|
|
17
|
+
return result2;
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
21
20
|
|
|
22
21
|
const passingCode = `
|
|
23
|
-
|
|
22
|
+
extern int foo(int x, int y, int z);
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
static int my_func(int x, int y, int z) {
|
|
25
|
+
return x + y + z;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static int my_func2() {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
static int bar() {
|
|
33
|
+
return my_func(1, 2, 3) + foo(50, 51, 52);
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const misraExample = `
|
|
38
|
+
#include <stdint.h>
|
|
39
|
+
|
|
40
|
+
static void withunusedpara (uint16_t *para1, int16_t unusedpara ) { // Violation of rule 2.7
|
|
41
|
+
*para1 = 42U;
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
36
44
|
|
|
37
45
|
const files: TestFile[] = [
|
|
38
46
|
{ name: "bad.c", code: failingCode },
|
|
39
|
-
{ name: "good.c", code: passingCode }
|
|
47
|
+
{ name: "good.c", code: passingCode },
|
|
48
|
+
{ name: "misra_example.c", code: misraExample }
|
|
40
49
|
];
|
|
41
50
|
|
|
42
51
|
describe("Rule 2.7", () => {
|
|
43
52
|
registerSourceCode(files);
|
|
44
53
|
|
|
45
54
|
it("should detect errors in bad.c", () => {
|
|
46
|
-
expect(countMISRAErrors()).toBe(
|
|
47
|
-
|
|
48
|
-
expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(2);
|
|
49
|
-
expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
|
|
55
|
+
expect(countMISRAErrors()).toBe(3);
|
|
50
56
|
});
|
|
51
57
|
|
|
52
58
|
it("should correct errors in bad.c", () => {
|
|
@@ -2,32 +2,61 @@ import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
|
2
2
|
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
3
3
|
import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
|
|
4
4
|
|
|
5
|
-
const passingCode = `
|
|
5
|
+
const passingCode = `
|
|
6
|
+
int static test_3_1_1() {
|
|
6
7
|
int x, y, z;// good inline comment
|
|
7
8
|
// good */ comment
|
|
9
|
+
// good // comment
|
|
8
10
|
return 0;
|
|
9
|
-
}
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
10
13
|
|
|
11
|
-
const failingCode = `
|
|
12
|
-
|
|
14
|
+
const failingCode = `
|
|
15
|
+
static int test_3_1_2() {
|
|
16
|
+
int x, y, z; // bad inl/*ine comment - Violation of rule 3.1
|
|
17
|
+
|
|
18
|
+
/* bad // comment - violation of rule 3.1 */
|
|
13
19
|
|
|
14
|
-
/* bad /* block comment */
|
|
20
|
+
/* bad /* block comment - Violation of rule 3.1*/
|
|
15
21
|
|
|
16
22
|
return 0;
|
|
17
|
-
}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const misraExample = `
|
|
27
|
+
static int test_3_1_3() {
|
|
28
|
+
/* [Violation of rule 3.1] some comment, end comment marker accidentally omitted
|
|
29
|
+
<<New Page>>
|
|
30
|
+
Perform_Critical_Safety_Function( X );
|
|
31
|
+
/* this comment is non-compliant */
|
|
32
|
+
|
|
33
|
+
int x;
|
|
34
|
+
int y = 6;
|
|
35
|
+
int z = 3;
|
|
36
|
+
|
|
37
|
+
x = y // /* violation of rule 3.1
|
|
38
|
+
+ z
|
|
39
|
+
// */
|
|
40
|
+
;
|
|
41
|
+
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
18
45
|
|
|
19
46
|
const files: TestFile[] = [
|
|
20
47
|
{ name: "bad.c", code: failingCode },
|
|
21
|
-
{ name: "good.c", code: passingCode }
|
|
48
|
+
{ name: "good.c", code: passingCode },
|
|
49
|
+
{ name: "misra_c_example.c", code: misraExample },
|
|
22
50
|
];
|
|
23
51
|
|
|
24
52
|
describe("Rule 3.1", () => {
|
|
25
53
|
registerSourceCode(files);
|
|
26
54
|
|
|
27
55
|
it("should detect errors in bad.c", () => {
|
|
28
|
-
expect(countMISRAErrors()).toBe(
|
|
56
|
+
expect(countMISRAErrors()).toBe(4);
|
|
29
57
|
|
|
30
58
|
expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(2);
|
|
59
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "misra_c_example.c"}).first()!)).toBe(2);
|
|
31
60
|
expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
|
|
32
61
|
});
|
|
33
62
|
|