@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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
2
|
+
|
|
3
|
+
const failingCode = `
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
/* 1234567890123456789012345678901********* Characters */
|
|
7
|
+
int32_t engine_exhaust_gas_temperature_raw;
|
|
8
|
+
int32_t engine_exhaust_gas_temperature_scaled; /* Non-compliant */
|
|
9
|
+
|
|
10
|
+
/* 1234567890123456789012345678901********* Characters */
|
|
11
|
+
int32_t engine_exhaust_gas_temp_raw;
|
|
12
|
+
int32_t engine_exhaust_gas_temp_scaled; /* Compliant */
|
|
13
|
+
|
|
14
|
+
/* 1234567890123456789012345678901********* Characters */
|
|
15
|
+
void motor_controller_status_update_v1(void) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* 1234567890123456789012345678901********* Characters */
|
|
20
|
+
void motor_controller_status_update_v2(void) { /* Non-compliant */
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* 1234567890123456789012345678901********* Characters */
|
|
25
|
+
int32_t data_collection_handler_buffer_var;
|
|
26
|
+
|
|
27
|
+
/* 1234567890123456789012345678901********* Characters */
|
|
28
|
+
void data_collection_handler_buffer_function(void) { /* Non-compliant */
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
const systemFile = `
|
|
34
|
+
#include <stdint.h>
|
|
35
|
+
|
|
36
|
+
extern int32_t engine_exhaust_gas_temperature_raw;
|
|
37
|
+
extern int32_t engine_exhaust_gas_temperature_scaled;
|
|
38
|
+
|
|
39
|
+
extern int32_t engine_exhaust_gas_temp_raw;
|
|
40
|
+
extern int32_t engine_exhaust_gas_temp_scaled;
|
|
41
|
+
|
|
42
|
+
extern void motor_controller_status_update_v1(void);
|
|
43
|
+
extern void motor_controller_status_update_v2(void);
|
|
44
|
+
|
|
45
|
+
extern int32_t data_collection_handler_buffer_var;
|
|
46
|
+
extern void data_collection_handler_buffer_function(void);
|
|
47
|
+
|
|
48
|
+
static void use_externs_5_1() {
|
|
49
|
+
(void) (engine_exhaust_gas_temperature_raw);
|
|
50
|
+
(void) (engine_exhaust_gas_temperature_scaled);
|
|
51
|
+
(void) (engine_exhaust_gas_temp_raw);
|
|
52
|
+
(void) (engine_exhaust_gas_temp_scaled);
|
|
53
|
+
motor_controller_status_update_v1();
|
|
54
|
+
motor_controller_status_update_v2();
|
|
55
|
+
|
|
56
|
+
(void) (data_collection_handler_buffer_var);
|
|
57
|
+
|
|
58
|
+
data_collection_handler_buffer_function();
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
const files: TestFile[] = [
|
|
63
|
+
{ name: "bad.c", code: failingCode },
|
|
64
|
+
{ name: "system.c", code: systemFile }
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
describe("Rule 5.1", () => {
|
|
68
|
+
registerSourceCode(files);
|
|
69
|
+
|
|
70
|
+
it("should detect violations of Rule 5.1", () => {
|
|
71
|
+
expect(countMISRAErrors()).toBe(3);
|
|
72
|
+
expect(countMISRAErrors("5.1")).toBe(3);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should correct all violations of Rule 5.1", () => {
|
|
76
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
2
|
+
|
|
3
|
+
const failingCode1 = `
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
typedef float float32_t;
|
|
7
|
+
|
|
8
|
+
static void test_5_6_1 ( void ) {
|
|
9
|
+
{
|
|
10
|
+
typedef unsigned char u8_t;
|
|
11
|
+
u8_t var_1 = 288;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
{
|
|
15
|
+
typedef unsigned char u8_t; // Violation of rule 5.6
|
|
16
|
+
u8_t var_2 = 288;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
typedef float mass;
|
|
21
|
+
|
|
22
|
+
static void test_5_6_2 ( void ) {
|
|
23
|
+
float32_t mass = 0.0f; // Violation of rule 5.6
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
typedef struct list {
|
|
27
|
+
struct list *next;
|
|
28
|
+
uint16_t element;
|
|
29
|
+
} list; /* Compliant - exception */
|
|
30
|
+
|
|
31
|
+
typedef struct { // Violation of rule 5.7
|
|
32
|
+
struct chain // Violation of rule 5.6
|
|
33
|
+
{
|
|
34
|
+
struct chain *list;
|
|
35
|
+
uint16_t element;
|
|
36
|
+
} s1;
|
|
37
|
+
|
|
38
|
+
uint16_t length;
|
|
39
|
+
} chain; /* Non-compliant - tag "chain" not
|
|
40
|
+
* associated with typedef */
|
|
41
|
+
|
|
42
|
+
static void test_5_6_7() {
|
|
43
|
+
mass var_3 = 0.0f;
|
|
44
|
+
list list_var = { .next = NULL, .element = 0 };
|
|
45
|
+
chain chain_var = { .s1 = { .list = NULL, .element = 0 }, .length = 0 };
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
const failingCode2 = `
|
|
50
|
+
typedef unsigned int my_int; // Violation of rule 5.7
|
|
51
|
+
|
|
52
|
+
struct my_int { // Violation of rule 5.6
|
|
53
|
+
float x;
|
|
54
|
+
float y;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
static unsigned int test_5_6() {
|
|
58
|
+
my_int value = 42;
|
|
59
|
+
struct my_int point = { 1.5f, 2.5f };
|
|
60
|
+
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
const failingCode3 = `
|
|
66
|
+
#include <stdint.h>
|
|
67
|
+
#include <stddef.h>
|
|
68
|
+
|
|
69
|
+
typedef float float_type;
|
|
70
|
+
|
|
71
|
+
static void compute_5_6(void) {
|
|
72
|
+
{
|
|
73
|
+
typedef int8_t byte_t;
|
|
74
|
+
byte_t x = 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
{
|
|
78
|
+
typedef int8_t byte_t; // Violation of rule 5.6
|
|
79
|
+
byte_t y = 2;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
typedef float velocity;
|
|
84
|
+
|
|
85
|
+
static void simulate(void) {
|
|
86
|
+
velocity vel = 90;
|
|
87
|
+
float_type velocity = 99.5; // Violation of rule 5.6
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
typedef struct node {
|
|
92
|
+
struct node *next;
|
|
93
|
+
uint16_t id;
|
|
94
|
+
} node; /* Compliant - exception */
|
|
95
|
+
|
|
96
|
+
static void traverse(node *head) {
|
|
97
|
+
while (head != NULL) {
|
|
98
|
+
head = head->next;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
const files: TestFile[] = [
|
|
104
|
+
{ name: "bad1.c", code: failingCode1 },
|
|
105
|
+
{ name: "bad2.c", code: failingCode2 },
|
|
106
|
+
{ name: "bad3.c", code: failingCode3 },
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
describe("Rule 5.6", () => {
|
|
110
|
+
registerSourceCode(files);
|
|
111
|
+
|
|
112
|
+
it("should detect errors in bad.c", () => {
|
|
113
|
+
expect(countMISRAErrors()).toBe(8);
|
|
114
|
+
expect(countMISRAErrors("5.6")).toBe(6);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should correct errors in bad.c", () => {
|
|
118
|
+
expect(countErrorsAfterCorrection("5.6")).toBe(0);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
2
|
+
|
|
3
|
+
const failingCode1 = `
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
struct deer {
|
|
7
|
+
uint16_t a;
|
|
8
|
+
uint16_t b;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
static void foo ( void ) {
|
|
12
|
+
struct deer { // Violation of rule 5.7
|
|
13
|
+
uint16_t a;
|
|
14
|
+
};
|
|
15
|
+
struct deer deer1 = { 5 };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
typedef struct coord {
|
|
19
|
+
uint16_t x;
|
|
20
|
+
uint16_t y;
|
|
21
|
+
} coord; /* Compliant by Exception */
|
|
22
|
+
|
|
23
|
+
struct elk {
|
|
24
|
+
uint16_t x;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
static void test_5_7_1() {
|
|
28
|
+
struct deer deer_var = {100, 200};
|
|
29
|
+
coord coord_var = {50, 60};
|
|
30
|
+
struct coord coord_struct;
|
|
31
|
+
struct elk elk_var = {100};
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
const files: TestFile[] = [
|
|
37
|
+
{ name: "bad1.c", code: failingCode1 }
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
describe("Rule 5.7", () => {
|
|
41
|
+
registerSourceCode(files);
|
|
42
|
+
|
|
43
|
+
it("should detect errors in bad.c", () => {
|
|
44
|
+
expect(countMISRAErrors()).toBe(1);
|
|
45
|
+
expect(countMISRAErrors("5.7")).toBe(1);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should correct errors in bad.c", () => {
|
|
49
|
+
expect(countErrorsAfterCorrection("5.7")).toBe(0);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
2
|
+
|
|
3
|
+
const file1 = `
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
int32_t count_5_8;
|
|
7
|
+
|
|
8
|
+
void foo_5_8 ( void ) { // Violation of rule 5.9
|
|
9
|
+
int16_t index_5_8;
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
const file2 = `
|
|
14
|
+
#include <stdint.h>
|
|
15
|
+
|
|
16
|
+
static void foo_5_8 ( void ) { // Violation of rule 5.8
|
|
17
|
+
int16_t count_5_8; // Violation of rule 5.8
|
|
18
|
+
int32_t index_5_8;
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
const file3 = `
|
|
23
|
+
#include <stdint.h>
|
|
24
|
+
|
|
25
|
+
static void test_5_8_1 ( void ) {
|
|
26
|
+
int32_t index_5_8 = 0;
|
|
27
|
+
|
|
28
|
+
count_5_8: // Violation of rule 5.8
|
|
29
|
+
index_5_8++;
|
|
30
|
+
if (index_5_8 < 5) {
|
|
31
|
+
goto count_5_8;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static void test_5_8_2(void) {
|
|
36
|
+
int32_t foo_5_8 = 0; // Violation of rules 5.8 and 5.9
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const systemFile = `
|
|
41
|
+
#include <stdint.h>
|
|
42
|
+
extern int32_t count_5_8;
|
|
43
|
+
extern void foo_5_8 (void);
|
|
44
|
+
|
|
45
|
+
static void use_externs_5_8() {
|
|
46
|
+
(void) (count_5_8);
|
|
47
|
+
foo_5_8();
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const files: TestFile[] = [
|
|
52
|
+
{ name: "file1.c", code: file1 },
|
|
53
|
+
{ name: "file2.c", code: file2 },
|
|
54
|
+
{ name: "file3.c", code: file3 },
|
|
55
|
+
{ name: "rule_5_8_system.c", code: systemFile}
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
describe("Rule 5.8", () => {
|
|
59
|
+
registerSourceCode(files);
|
|
60
|
+
|
|
61
|
+
it("should detect errors in bad.c", () => {
|
|
62
|
+
expect(countMISRAErrors()).toBe(6);
|
|
63
|
+
expect(countMISRAErrors("5.8")).toBe(4);
|
|
64
|
+
|
|
65
|
+
//expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!, "5.8")).toBe(0);
|
|
66
|
+
//expect(countMISRAErrors(Query.search(FileJp, {name: "bad1.c"}).first()!, "5.8")).toBe(2);
|
|
67
|
+
//expect(countMISRAErrors(Query.search(FileJp, {name: "bad2.c"}).first()!, "5.8")).toBe(3);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should correct errors in bad.c", () => {
|
|
71
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
2
|
+
|
|
3
|
+
const failingCode1 = `
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
static int32_t count_5_9; /* "count" has internal linkage */
|
|
7
|
+
|
|
8
|
+
static void foo_5_9 (void) {
|
|
9
|
+
int16_t count_5_9; // Violation of rule 5.9
|
|
10
|
+
int16_t index_5_9;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
void bar1 (void) {
|
|
14
|
+
static int16_t count_5_9; // Violation of rule 5.9
|
|
15
|
+
foo_5_9();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
void static use_static_count() {
|
|
19
|
+
(void) count_5_9;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void static use_static_count_2() {
|
|
23
|
+
(void) count_5_9;
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
const failingCode2 = `
|
|
28
|
+
#include <stdint.h>
|
|
29
|
+
|
|
30
|
+
static int8_t count_5_9; // Violation of rule 5.9
|
|
31
|
+
|
|
32
|
+
static void foo_5_9 ( void ) { // Violation of rule 5.9
|
|
33
|
+
int32_t index_5_9;
|
|
34
|
+
int16_t nbytes;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Missing "static" keyword
|
|
38
|
+
void bar2 ( void ){
|
|
39
|
+
static uint8_t nbytes;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void static use_static_count_3() {
|
|
43
|
+
(void) count_5_9;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void static use_static_count_4() {
|
|
47
|
+
(void) count_5_9;
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const failingCode3 = `
|
|
52
|
+
#include <stdint.h>
|
|
53
|
+
|
|
54
|
+
static void test_5_9_1 ( void ) {
|
|
55
|
+
int32_t index_5_9 = 0;
|
|
56
|
+
|
|
57
|
+
count_5_9: // Violation of rule 5.9
|
|
58
|
+
index_5_9++;
|
|
59
|
+
if (index_5_9 < 5) {
|
|
60
|
+
goto count_5_9;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
const systemFile = `
|
|
66
|
+
extern void bar1 (void);
|
|
67
|
+
extern void bar2 (void);
|
|
68
|
+
|
|
69
|
+
static void use_externs_5_9() {
|
|
70
|
+
bar1();
|
|
71
|
+
bar2();
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
const files: TestFile[] = [
|
|
76
|
+
{ name: "bad1.c", code: failingCode1 },
|
|
77
|
+
{ name: "bad2.c", code: failingCode2 },
|
|
78
|
+
{ name: "bad3.c", code: failingCode3 },
|
|
79
|
+
{ name: "rule_5_9_system.c", code: systemFile}
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
describe("Rule 5.9", () => {
|
|
83
|
+
registerSourceCode(files);
|
|
84
|
+
|
|
85
|
+
it("should detect errors in bad.c", () => {
|
|
86
|
+
expect(countMISRAErrors()).toBe(5);
|
|
87
|
+
expect(countMISRAErrors("5.9")).toBe(5);
|
|
88
|
+
|
|
89
|
+
//expect(countMISRAErrors(Query.search(FileJp, {name: "bad1.c"}).first()!)).toBe(5);
|
|
90
|
+
//expect(countMISRAErrors(Query.search(FileJp, {name: "bad2.c"}).first()!)).toBe(3);
|
|
91
|
+
//expect(countMISRAErrors(Query.search(FileJp, {name: "bad3.c"}).first()!)).toBe(1);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should correct errors in bad.c", () => {
|
|
95
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
96
|
+
});
|
|
97
|
+
});
|
package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_6_SingleExternalDefinition.test.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
2
|
+
|
|
3
|
+
const passingCode1 = `
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
/* Compliant - First definition but has another initialization in other file
|
|
7
|
+
* Will not be fixed, as there are multiple initializations
|
|
8
|
+
*/
|
|
9
|
+
int16_t i = 10;
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
const failingCode1 = `
|
|
13
|
+
#include <stdint.h>
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* Non-compliant - Second definition
|
|
17
|
+
* Will not be fixed, as there are multiple initializations
|
|
18
|
+
*/
|
|
19
|
+
int16_t i = 20;
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
const passingCode2 = `
|
|
23
|
+
#include <stdint.h>
|
|
24
|
+
|
|
25
|
+
int16_t j; /* Tentative definition */
|
|
26
|
+
int16_t j = 1; /* Compliant - external definition */
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
const passingCode3 = `
|
|
30
|
+
#include <stdint.h>
|
|
31
|
+
|
|
32
|
+
/* Compliant - First defintion but has initialization in other file
|
|
33
|
+
* After transformation it will have 'extern' storage class
|
|
34
|
+
*/
|
|
35
|
+
int16_t k; /* Tentative definition - becomes external */
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
const failingCode3 = `
|
|
39
|
+
#include <stdint.h>
|
|
40
|
+
|
|
41
|
+
int16_t k = 0; /* Non-compliant- Second external definition (unique initialization)*/
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
const failingCode4 = `
|
|
45
|
+
#include <stdint.h>
|
|
46
|
+
|
|
47
|
+
/* Compliant - First defintion but has initialization in other file
|
|
48
|
+
* After transformation it will have 'extern' storage class
|
|
49
|
+
*/
|
|
50
|
+
int16_t a;
|
|
51
|
+
|
|
52
|
+
/* Compliant - First definition but has another initialization in other file
|
|
53
|
+
* Will not be fixed, as there are multiple initializations
|
|
54
|
+
*/
|
|
55
|
+
int16_t b = 40;
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
int16_t c; /* Compliant- First definition */
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
const failingCode5 = `
|
|
62
|
+
#include <stdint.h>
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
* Non-compliant - Second definition
|
|
66
|
+
* This is the unique initialization
|
|
67
|
+
*/
|
|
68
|
+
int16_t a = 10;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* Non-compliant - Second definition
|
|
73
|
+
* Will not be fixed, as there are multiple initializations
|
|
74
|
+
*/
|
|
75
|
+
int16_t b = 20;
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
* Non-compliant - Second declaration
|
|
80
|
+
* Will be changed to 'extern'
|
|
81
|
+
*/
|
|
82
|
+
int16_t c;
|
|
83
|
+
`;
|
|
84
|
+
|
|
85
|
+
const failingCode6 = `
|
|
86
|
+
#include <stdint.h>
|
|
87
|
+
|
|
88
|
+
/*
|
|
89
|
+
* Non-compliant - Third declaration
|
|
90
|
+
* Will be changed to 'extern'
|
|
91
|
+
*/
|
|
92
|
+
int16_t a;
|
|
93
|
+
|
|
94
|
+
/*
|
|
95
|
+
* Non-compliant - Second defintion
|
|
96
|
+
* Will not be fixed, as there are multiple initializations
|
|
97
|
+
*/
|
|
98
|
+
int16_t b;
|
|
99
|
+
`;
|
|
100
|
+
|
|
101
|
+
const passingCode4 = `
|
|
102
|
+
#include <stdint.h>
|
|
103
|
+
|
|
104
|
+
int16_t d;
|
|
105
|
+
int16_t e = 15;
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
const passingCode5 = `
|
|
109
|
+
#include <stdint.h>
|
|
110
|
+
|
|
111
|
+
extern int16_t d;
|
|
112
|
+
extern int16_t e;
|
|
113
|
+
|
|
114
|
+
extern int16_t i;
|
|
115
|
+
extern int16_t j;
|
|
116
|
+
extern int16_t k;
|
|
117
|
+
|
|
118
|
+
extern int16_t a;
|
|
119
|
+
extern int16_t b;
|
|
120
|
+
extern int16_t c;
|
|
121
|
+
|
|
122
|
+
static int16_t findGreatestValue(void) {
|
|
123
|
+
int16_t values[] = { d, e, i, j, k, a, b, c };
|
|
124
|
+
int16_t max = values[0];
|
|
125
|
+
|
|
126
|
+
for (int idx = 1; idx < sizeof(values)/sizeof(values[0]); ++idx) {
|
|
127
|
+
if (values[idx] > max) {
|
|
128
|
+
max = values[idx];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return max;
|
|
132
|
+
}
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
const files: TestFile[] = [
|
|
136
|
+
{ name: "good1.c", code: passingCode1 },
|
|
137
|
+
{ name: "bad1.c", code: failingCode1 },
|
|
138
|
+
{ name: "good2.c", code: passingCode2 },
|
|
139
|
+
{ name: "good3.c", code: passingCode3 },
|
|
140
|
+
{ name: "bad3.c", code: failingCode3 },
|
|
141
|
+
{ name: "bad4.c", code: failingCode4 },
|
|
142
|
+
{ name: "bad5.c", code: failingCode5 },
|
|
143
|
+
{ name: "bad6.c", code: failingCode6 },
|
|
144
|
+
{ name: "good4.c", code: passingCode4 },
|
|
145
|
+
{ name: "good5.c", code: passingCode5 },
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
describe("Rule 8.6", () => {
|
|
149
|
+
registerSourceCode(files);
|
|
150
|
+
|
|
151
|
+
it("should detect errors in bad.c", () => {
|
|
152
|
+
expect(countMISRAErrors()).toBe(7);
|
|
153
|
+
expect(countMISRAErrors("8.6")).toBe(7);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("should correct errors in bad.c", () => {
|
|
157
|
+
expect(countErrorsAfterCorrection()).toBe(3);
|
|
158
|
+
expect(countErrorsAfterCorrection("8.6")).toBe(3);
|
|
159
|
+
});
|
|
160
|
+
});
|
package/src/tests/Section8_DeclarationsAndDefinitions/Rule_8_7_RestrictExternalLinkage.test.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
2
|
+
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
3
|
+
import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
|
|
4
|
+
|
|
5
|
+
const passingCode = `
|
|
6
|
+
int good_extern_obj = 0;
|
|
7
|
+
|
|
8
|
+
int good_extern_function() {
|
|
9
|
+
return ++good_extern_obj;
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
const failingCode = `
|
|
14
|
+
extern int good_extern_obj;
|
|
15
|
+
extern int good_extern_function();
|
|
16
|
+
|
|
17
|
+
int bad_extern_obj = 0;
|
|
18
|
+
|
|
19
|
+
int bad_extern_function() {
|
|
20
|
+
return bad_extern_obj + good_extern_obj + good_extern_function();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static int test_8_7_1() {
|
|
24
|
+
return bad_extern_obj;
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
const files: TestFile[] = [
|
|
29
|
+
{ name: "bad.c", code: failingCode },
|
|
30
|
+
{ name: "good.c", code: passingCode }
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
describe("Rule 8.7", () => {
|
|
34
|
+
registerSourceCode(files);
|
|
35
|
+
|
|
36
|
+
it("should detect errors in bad.c", () => {
|
|
37
|
+
expect(countMISRAErrors()).toBe(2);
|
|
38
|
+
|
|
39
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(2);
|
|
40
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should correct errors in bad.c", () => {
|
|
44
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
2
|
+
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
3
|
+
import { FileJp } from "@specs-feup/clava/api/Joinpoints.js";
|
|
4
|
+
|
|
5
|
+
const passingCode = `
|
|
6
|
+
#include <stdint.h>
|
|
7
|
+
|
|
8
|
+
static uint32_t good_counter = 0;
|
|
9
|
+
|
|
10
|
+
static void test_8_9_1 ( void ) {
|
|
11
|
+
int32_t i;
|
|
12
|
+
for (i = 0; i < 10; ++i) {
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
++good_counter;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static uint32_t test_8_9_2 ( void ) {
|
|
19
|
+
static uint32_t call_count = 0;
|
|
20
|
+
|
|
21
|
+
++call_count;
|
|
22
|
+
++good_counter;
|
|
23
|
+
|
|
24
|
+
return call_count;
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
const failingCode = `
|
|
29
|
+
#include <stdint.h>
|
|
30
|
+
|
|
31
|
+
static uint32_t bad_counter = 0; // Violation of rule 8.9
|
|
32
|
+
|
|
33
|
+
static int test_8_9_3 (void) {
|
|
34
|
+
++bad_counter;
|
|
35
|
+
return bad_counter;
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
const misraExample = `
|
|
40
|
+
#include <stdint.h>
|
|
41
|
+
|
|
42
|
+
static uint32_t test_8_9_4 ( void ) {
|
|
43
|
+
static uint32_t call_count = 0;
|
|
44
|
+
++call_count;
|
|
45
|
+
return call_count;
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
const files: TestFile[] = [
|
|
50
|
+
{ name: "bad.c", code: failingCode },
|
|
51
|
+
{ name: "good.c", code: passingCode },
|
|
52
|
+
{ name: "misraExample.c", code: misraExample }
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
describe("Rule 8.9", () => {
|
|
56
|
+
registerSourceCode(files);
|
|
57
|
+
|
|
58
|
+
it("should detect errors in bad.c", () => {
|
|
59
|
+
expect(countMISRAErrors()).toBe(1);
|
|
60
|
+
|
|
61
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(1);
|
|
62
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
|
|
63
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "misraExample.c"}).first()!)).toBe(0);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should correct errors in bad.c", () => {
|
|
67
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
68
|
+
});
|
|
69
|
+
});
|