@specs-feup/clava-misra 1.0.0 → 1.0.1
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 +117 -0
- package/README.md +70 -15
- package/dist/MISRA.d.ts +129 -0
- package/dist/MISRA.d.ts.map +1 -0
- package/dist/MISRA.js +245 -0
- package/dist/MISRA.js.map +1 -0
- package/dist/MISRAContext.d.ts +21 -0
- package/dist/MISRAContext.d.ts.map +1 -0
- package/dist/MISRAContext.js +75 -0
- package/dist/MISRAContext.js.map +1 -0
- package/dist/MISRARule.d.ts +56 -0
- package/dist/MISRARule.d.ts.map +1 -0
- package/dist/MISRARule.js +45 -0
- package/dist/MISRARule.js.map +1 -0
- package/dist/MISRATool.d.ts +12 -0
- package/dist/MISRATool.d.ts.map +1 -0
- package/dist/MISRATool.js +84 -0
- package/dist/MISRATool.js.map +1 -0
- package/dist/foo.d.ts +2 -0
- package/dist/foo.d.ts.map +1 -0
- package/{src/foo.ts → dist/foo.js} +3 -2
- package/dist/foo.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +5 -0
- package/dist/main.js.map +1 -0
- package/dist/misra/MISRAAnalyser.d.ts +14 -0
- package/dist/misra/MISRAAnalyser.d.ts.map +1 -0
- package/{src/misra/MISRAAnalyser.ts → dist/misra/MISRAAnalyser.js} +13 -23
- package/dist/misra/MISRAAnalyser.js.map +1 -0
- package/dist/misra/MISRAPass.d.ts +27 -0
- package/dist/misra/MISRAPass.d.ts.map +1 -0
- package/dist/misra/MISRAPass.js +60 -0
- package/dist/misra/MISRAPass.js.map +1 -0
- package/dist/misra/MISRAPassResult.d.ts +13 -0
- package/dist/misra/MISRAPassResult.d.ts.map +1 -0
- package/dist/misra/MISRAPassResult.js +11 -0
- package/dist/misra/MISRAPassResult.js.map +1 -0
- package/dist/misra/MISRAReporter.d.ts +20 -0
- package/dist/misra/MISRAReporter.d.ts.map +1 -0
- package/dist/misra/MISRAReporter.js +43 -0
- package/dist/misra/MISRAReporter.js.map +1 -0
- package/dist/misra/passes/S10_EssentialTypePass.d.ts +42 -0
- package/dist/misra/passes/S10_EssentialTypePass.d.ts.map +1 -0
- package/dist/misra/passes/S10_EssentialTypePass.js +370 -0
- package/dist/misra/passes/S10_EssentialTypePass.js.map +1 -0
- package/dist/misra/passes/S12_ExpressionPass.d.ts +18 -0
- package/dist/misra/passes/S12_ExpressionPass.d.ts.map +1 -0
- package/dist/misra/passes/S12_ExpressionPass.js +72 -0
- package/dist/misra/passes/S12_ExpressionPass.js.map +1 -0
- package/dist/misra/passes/S13_SideEffectPass.d.ts +18 -0
- package/dist/misra/passes/S13_SideEffectPass.d.ts.map +1 -0
- package/dist/misra/passes/S13_SideEffectPass.js +105 -0
- package/dist/misra/passes/S13_SideEffectPass.js.map +1 -0
- package/dist/misra/passes/S15_ControlFlowPass.d.ts +19 -0
- package/dist/misra/passes/S15_ControlFlowPass.d.ts.map +1 -0
- package/dist/misra/passes/S15_ControlFlowPass.js +94 -0
- package/dist/misra/passes/S15_ControlFlowPass.js.map +1 -0
- package/dist/misra/passes/S16_SwitchStatementPass.d.ts +17 -0
- package/dist/misra/passes/S16_SwitchStatementPass.d.ts.map +1 -0
- package/dist/misra/passes/S16_SwitchStatementPass.js +152 -0
- package/dist/misra/passes/S16_SwitchStatementPass.js.map +1 -0
- package/dist/misra/passes/S17_FunctionPass.d.ts +12 -0
- package/dist/misra/passes/S17_FunctionPass.d.ts.map +1 -0
- package/dist/misra/passes/S17_FunctionPass.js +38 -0
- package/dist/misra/passes/S17_FunctionPass.js.map +1 -0
- package/dist/misra/passes/S18_PointersArraysPass.d.ts +17 -0
- package/dist/misra/passes/S18_PointersArraysPass.d.ts.map +1 -0
- package/dist/misra/passes/S18_PointersArraysPass.js +115 -0
- package/dist/misra/passes/S18_PointersArraysPass.js.map +1 -0
- package/dist/misra/passes/S19_OverlappingStoragePass.d.ts +11 -0
- package/dist/misra/passes/S19_OverlappingStoragePass.d.ts.map +1 -0
- package/dist/misra/passes/S19_OverlappingStoragePass.js +20 -0
- package/dist/misra/passes/S19_OverlappingStoragePass.js.map +1 -0
- package/dist/misra/passes/S21_StandardLibPass.d.ts +20 -0
- package/dist/misra/passes/S21_StandardLibPass.d.ts.map +1 -0
- package/dist/misra/passes/S21_StandardLibPass.js +77 -0
- package/dist/misra/passes/S21_StandardLibPass.js.map +1 -0
- package/dist/misra/passes/S3_CommentPass.d.ts +12 -0
- package/dist/misra/passes/S3_CommentPass.d.ts.map +1 -0
- package/dist/misra/passes/S3_CommentPass.js +27 -0
- package/dist/misra/passes/S3_CommentPass.js.map +1 -0
- package/dist/misra/passes/S5_IdentifierPass.d.ts +13 -0
- package/dist/misra/passes/S5_IdentifierPass.d.ts.map +1 -0
- package/dist/misra/passes/S5_IdentifierPass.js +60 -0
- package/dist/misra/passes/S5_IdentifierPass.js.map +1 -0
- package/dist/misra/passes/S6_TypePass.d.ts +11 -0
- package/dist/misra/passes/S6_TypePass.d.ts.map +1 -0
- package/dist/misra/passes/S6_TypePass.js +25 -0
- package/dist/misra/passes/S6_TypePass.js.map +1 -0
- package/dist/misra/passes/S7_LiteralsConstantsPass.d.ts +14 -0
- package/dist/misra/passes/S7_LiteralsConstantsPass.d.ts.map +1 -0
- package/dist/misra/passes/S7_LiteralsConstantsPass.js +71 -0
- package/dist/misra/passes/S7_LiteralsConstantsPass.js.map +1 -0
- package/dist/misra/passes/S8_DeclDefPass.d.ts +18 -0
- package/dist/misra/passes/S8_DeclDefPass.d.ts.map +1 -0
- package/dist/misra/passes/S8_DeclDefPass.js +127 -0
- package/dist/misra/passes/S8_DeclDefPass.js.map +1 -0
- package/dist/misra/sections/Section10_EssentialTypeModel.d.ts +33 -0
- package/dist/misra/sections/Section10_EssentialTypeModel.d.ts.map +1 -0
- package/{src/misra/sections/Section10_EssentialTypeModel.ts → dist/misra/sections/Section10_EssentialTypeModel.js} +58 -73
- package/dist/misra/sections/Section10_EssentialTypeModel.js.map +1 -0
- package/dist/misra/sections/Section11_PointerTypeConversions.d.ts +12 -0
- package/dist/misra/sections/Section11_PointerTypeConversions.d.ts.map +1 -0
- package/{src/misra/sections/Section11_PointerTypeConversions.ts → dist/misra/sections/Section11_PointerTypeConversions.js} +16 -27
- package/dist/misra/sections/Section11_PointerTypeConversions.js.map +1 -0
- package/dist/misra/sections/Section12_Expressions.d.ts +15 -0
- package/dist/misra/sections/Section12_Expressions.d.ts.map +1 -0
- package/dist/misra/sections/Section12_Expressions.js +70 -0
- package/dist/misra/sections/Section12_Expressions.js.map +1 -0
- package/dist/misra/sections/Section13_SideEffects.d.ts +14 -0
- package/dist/misra/sections/Section13_SideEffects.d.ts.map +1 -0
- package/dist/misra/sections/Section13_SideEffects.js +90 -0
- package/dist/misra/sections/Section13_SideEffects.js.map +1 -0
- package/dist/misra/sections/Section14_ControlStmtExprs.d.ts +8 -0
- package/dist/misra/sections/Section14_ControlStmtExprs.d.ts.map +1 -0
- package/{src/misra/sections/Section14_ControlStmtExprs.ts → dist/misra/sections/Section14_ControlStmtExprs.js} +8 -10
- package/dist/misra/sections/Section14_ControlStmtExprs.js.map +1 -0
- package/dist/misra/sections/Section15_ControlFlow.d.ts +14 -0
- package/dist/misra/sections/Section15_ControlFlow.d.ts.map +1 -0
- package/dist/misra/sections/Section15_ControlFlow.js +97 -0
- package/dist/misra/sections/Section15_ControlFlow.js.map +1 -0
- package/dist/misra/sections/Section16_SwitchStatements.d.ts +13 -0
- package/dist/misra/sections/Section16_SwitchStatements.d.ts.map +1 -0
- package/{src/misra/sections/Section16_SwitchStatements.ts → dist/misra/sections/Section16_SwitchStatements.js} +49 -74
- package/dist/misra/sections/Section16_SwitchStatements.js.map +1 -0
- package/dist/misra/sections/Section17_Functions.d.ts +9 -0
- package/dist/misra/sections/Section17_Functions.d.ts.map +1 -0
- package/{src/misra/sections/Section17_Functions.ts → dist/misra/sections/Section17_Functions.js} +10 -13
- package/dist/misra/sections/Section17_Functions.js.map +1 -0
- package/dist/misra/sections/Section18_PointersAndArrays.d.ts +13 -0
- package/dist/misra/sections/Section18_PointersAndArrays.d.ts.map +1 -0
- package/{src/misra/sections/Section18_PointersAndArrays.ts → dist/misra/sections/Section18_PointersAndArrays.js} +36 -40
- package/dist/misra/sections/Section18_PointersAndArrays.js.map +1 -0
- package/dist/misra/sections/Section19_OverlappingStorage.d.ts +8 -0
- package/dist/misra/sections/Section19_OverlappingStorage.d.ts.map +1 -0
- package/dist/misra/sections/Section19_OverlappingStorage.js +16 -0
- package/dist/misra/sections/Section19_OverlappingStorage.js.map +1 -0
- package/dist/misra/sections/Section20_PreprocessingDirectives.d.ts +8 -0
- package/dist/misra/sections/Section20_PreprocessingDirectives.d.ts.map +1 -0
- package/{src/misra/sections/Section20_PreprocessingDirectives.ts → dist/misra/sections/Section20_PreprocessingDirectives.js} +7 -9
- package/dist/misra/sections/Section20_PreprocessingDirectives.js.map +1 -0
- package/dist/misra/sections/Section21_StandardLibraries.d.ts +17 -0
- package/dist/misra/sections/Section21_StandardLibraries.d.ts.map +1 -0
- package/dist/misra/sections/Section21_StandardLibraries.js +54 -0
- package/dist/misra/sections/Section21_StandardLibraries.js.map +1 -0
- package/dist/misra/sections/Section2_UnusedCode.d.ts +9 -0
- package/dist/misra/sections/Section2_UnusedCode.d.ts.map +1 -0
- package/{src/misra/sections/Section2_UnusedCode.ts → dist/misra/sections/Section2_UnusedCode.js} +11 -16
- package/dist/misra/sections/Section2_UnusedCode.js.map +1 -0
- package/dist/misra/sections/Section3_Comments.d.ts +9 -0
- package/dist/misra/sections/Section3_Comments.d.ts.map +1 -0
- package/{src/misra/sections/Section3_Comments.ts → dist/misra/sections/Section3_Comments.js} +7 -10
- package/dist/misra/sections/Section3_Comments.js.map +1 -0
- package/dist/misra/sections/Section5_Identifiers.d.ts +12 -0
- package/dist/misra/sections/Section5_Identifiers.d.ts.map +1 -0
- package/dist/misra/sections/Section5_Identifiers.js +139 -0
- package/dist/misra/sections/Section5_Identifiers.js.map +1 -0
- package/dist/misra/sections/Section6_Types.d.ts +8 -0
- package/dist/misra/sections/Section6_Types.d.ts.map +1 -0
- package/dist/misra/sections/Section6_Types.js +23 -0
- package/dist/misra/sections/Section6_Types.js.map +1 -0
- package/dist/misra/sections/Section7_LiteralsConstants.d.ts +11 -0
- package/dist/misra/sections/Section7_LiteralsConstants.d.ts.map +1 -0
- package/{src/misra/sections/Section7_LiteralsConstants.ts → dist/misra/sections/Section7_LiteralsConstants.js} +18 -25
- package/dist/misra/sections/Section7_LiteralsConstants.js.map +1 -0
- package/dist/misra/sections/Section8_DeclarationsDefinitions.d.ts +15 -0
- package/dist/misra/sections/Section8_DeclarationsDefinitions.d.ts.map +1 -0
- package/{src/misra/sections/Section8_DeclarationsDefinitions.ts → dist/misra/sections/Section8_DeclarationsDefinitions.js} +18 -33
- package/dist/misra/sections/Section8_DeclarationsDefinitions.js.map +1 -0
- package/dist/misra/tests/utils.d.ts +10 -0
- package/dist/misra/tests/utils.d.ts.map +1 -0
- package/dist/misra/tests/utils.js +33 -0
- package/dist/misra/tests/utils.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts +15 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js +33 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts +16 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js +60 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts +19 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js +42 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts +43 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js +103 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts +26 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js +49 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.js.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts +26 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.d.ts.map +1 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js +49 -0
- package/dist/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.js.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts +31 -0
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.d.ts.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js +71 -0
- package/dist/rules/Section17_Functions/Rule_17_4_NonVoidReturn.js.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts +27 -0
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.d.ts.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js +58 -0
- package/dist/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.js.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts +28 -0
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.d.ts.map +1 -0
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js +44 -0
- package/dist/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.js.map +1 -0
- package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.d.ts +55 -0
- package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.d.ts.map +1 -0
- package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.js +108 -0
- package/dist/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.js.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts +43 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.d.ts.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js +68 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.js.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts +29 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.d.ts.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js +53 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.js.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts +15 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.d.ts.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js +35 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.js.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts +13 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.d.ts.map +1 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js +53 -0
- package/dist/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.js.map +1 -0
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts +13 -0
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.d.ts.map +1 -0
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js +32 -0
- package/dist/rules/Section3_Comments/Rule_3_1_CommentSequences.js.map +1 -0
- package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.d.ts +10 -0
- package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.d.ts.map +1 -0
- package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.js +26 -0
- package/dist/rules/Section3_Comments/Rule_3_2_LineSplicing.js.map +1 -0
- package/dist/rules/index.d.ts +20 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +38 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/tests/Section17_Functions/misra_config.json +10 -0
- package/dist/tests/utils.d.ts +10 -0
- package/dist/tests/utils.d.ts.map +1 -0
- package/dist/tests/utils.js +29 -0
- package/dist/tests/utils.js.map +1 -0
- package/dist/utils/utils.d.ts +102 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +202 -0
- package/dist/utils/utils.js.map +1 -0
- package/jest.config.js +6 -6
- package/package.json +40 -8
- package/src/MISRA.ts +266 -0
- package/src/MISRAContext.ts +91 -0
- package/src/MISRARule.ts +77 -0
- package/src/MISRATool.ts +96 -0
- package/src/main.ts +4 -33
- package/src/misra-old/MISRAAnalyser.ts +60 -0
- package/src/misra-old/MISRAAnalyserResult.ts +16 -0
- package/src/misra-old/sections/Section10_EssentialTypeModel.ts +377 -0
- package/src/misra-old/sections/Section11_PointerTypeConversions.ts +104 -0
- package/src/{misra → misra-old}/sections/Section12_Expressions.ts +7 -7
- package/src/{misra → misra-old}/sections/Section13_SideEffects.ts +15 -15
- package/src/misra-old/sections/Section14_ControlStmtExprs.ts +27 -0
- package/src/{misra → misra-old}/sections/Section15_ControlFlow.ts +10 -10
- package/src/misra-old/sections/Section18_PointersAndArrays.ts +108 -0
- package/src/{misra → misra-old}/sections/Section19_OverlappingStorage.ts +4 -4
- package/src/misra-old/sections/Section20_PreprocessingDirectives.ts +22 -0
- package/src/misra-old/sections/Section21_StandardLibraries.ts +99 -0
- package/src/{misra → misra-old}/sections/Section5_Identifiers.ts +16 -15
- package/src/{misra → misra-old}/sections/Section6_Types.ts +4 -4
- package/src/misra-old/sections/Section7_LiteralsConstants.ts +76 -0
- package/src/misra-old/sections/Section8_DeclarationsDefinitions.ts +133 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.ts +40 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.ts +69 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.ts +46 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.ts +113 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.ts +57 -0
- package/src/rules/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.ts +56 -0
- package/src/rules/Section17_Functions/Rule_17_4_NonVoidReturn.ts +78 -0
- package/src/rules/Section17_Functions/Rule_17_6_StaticArraySizeParam.ts +68 -0
- package/src/rules/Section17_Functions/Rule_17_7_UnusedReturnValue.ts +47 -0
- package/src/rules/Section20-PreprocessingDirectives/Rule_20_2_InvalidHeaderFileName.ts +120 -0
- package/src/rules/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.ts +75 -0
- package/src/rules/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.ts +60 -0
- package/src/rules/Section2_UnusedCode/Rule_2_6_UnusedLabels.ts +46 -0
- package/src/rules/Section2_UnusedCode/Rule_2_7_UnusedParameters.ts +65 -0
- package/src/rules/Section3_Comments/Rule_3_1_CommentSequences.ts +41 -0
- package/src/rules/Section3_Comments/Rule_3_2_LineSplicing.ts +36 -0
- package/src/rules/index.ts +40 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_2_TopLevelSwitch.test.ts +55 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_3_UnconditionalBreak.test.ts +70 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_4_SwitchHasDefault.test.ts +128 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_5_DefaultFirstOrLast.test.ts +132 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_6_SwitchMinTwoClauses.test.ts +146 -0
- package/src/tests/Section16_SwitchStatements/Rule_16_7_NonBooleanSwitchCondition.test.ts +102 -0
- package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn.test.ts +85 -0
- package/src/tests/Section17_Functions/Rule_17_4_NonVoidReturn_MissingConfig.test.ts +77 -0
- package/src/tests/Section17_Functions/Rule_17_6_StaticArraySizeParam.test.ts +36 -0
- package/src/tests/Section17_Functions/Rule_17_7_UnusedReturnValue.test.ts +44 -0
- package/src/tests/Section17_Functions/misra_config.json +10 -0
- package/src/tests/Section2_UnusedCode/Rule_2_3_UnusedTypeDecl.test.ts +175 -0
- package/src/tests/Section2_UnusedCode/Rule_2_4_UnusedTagDecl.test.ts +219 -0
- package/src/tests/Section2_UnusedCode/Rule_2_6_UnusedLabels.test.ts +49 -0
- package/src/tests/Section2_UnusedCode/Rule_2_7_UnusedParameters.test.ts +55 -0
- package/src/tests/Section3_Comments/Rule_3_1_CommentSequences.test.ts +37 -0
- package/src/tests/utils.ts +39 -0
- package/src/utils/utils.ts +221 -0
- package/tsconfig.json +4 -3
- package/typedoc.config.js +1 -1
- package/CxxSources/lib.cpp +0 -3
- package/CxxSources/lib.h +0 -8
- package/CxxSources/main.cpp +0 -40
- package/TODO.md +0 -1
- package/consumer_order.txt +0 -2
- package/enum_integer_type.txt +0 -0
- package/is_temporary.txt +0 -0
- package/omp.txt +0 -0
- package/src/misra/passes/S16_SwitchStatementPass.ts +0 -168
- package/src/misra/passes/S3_CommentPass.ts +0 -40
- package/src/misra/sections/Section21_StandardLibraries.ts +0 -65
- package/src/misra/tests/S10_EssentialTypes.test.ts +0 -253
- package/src/misra/tests/S12_Expressions.test.ts +0 -43
- package/src/misra/tests/S13_SideEffects.test.ts +0 -77
- package/src/misra/tests/S15_ControlFlow.test.ts +0 -144
- package/src/misra/tests/S16_SwitchStatements.test.ts +0 -164
- package/src/misra/tests/S17_Functions.test.ts +0 -46
- package/src/misra/tests/S18_PointersArrays.test.ts +0 -167
- package/src/misra/tests/S19_OverlappingStorage.test.ts +0 -38
- package/src/misra/tests/S3_Comments.test.ts +0 -36
- package/src/misra/tests/S6_Types.test.ts +0 -36
- package/src/misra/tests/S7_LiteralsConstants.test.ts +0 -48
- package/src/misra/tests/utils.ts +0 -47
- package/types_with_templates.txt +0 -0
- /package/src/{misra → misra-old}/MISRAPass.ts +0 -0
- /package/src/{misra → misra-old}/MISRAPassResult.ts +0 -0
- /package/src/{misra → misra-old}/MISRAReporter.ts +0 -0
- /package/src/{misra → misra-old}/passes/S10_EssentialTypePass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S12_ExpressionPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S13_SideEffectPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S15_ControlFlowPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S17_FunctionPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S18_PointersArraysPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S19_OverlappingStoragePass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S21_StandardLibPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S5_IdentifierPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S6_TypePass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S7_LiteralsConstantsPass.ts +0 -0
- /package/src/{misra → misra-old}/passes/S8_DeclDefPass.ts +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
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 programCode = `
|
|
6
|
+
void my_void_func() {
|
|
7
|
+
// Void function
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
unsigned int foo() {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
unsigned int bar(unsigned int n) {
|
|
15
|
+
return n*n;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
int main() {
|
|
19
|
+
my_void_func(); // Compliant - call to void function
|
|
20
|
+
|
|
21
|
+
unsigned int result = foo();
|
|
22
|
+
(void) bar(foo());
|
|
23
|
+
|
|
24
|
+
foo(); // Non-compliant
|
|
25
|
+
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
const files: TestFile[] = [
|
|
31
|
+
{ name: "program.c", code: programCode }
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
describe("Rule 17.7", () => {
|
|
35
|
+
registerSourceCode(files);
|
|
36
|
+
|
|
37
|
+
it("should detect errors", () => {
|
|
38
|
+
expect(countMISRAErrors()).toBe(1);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should correct errors", () => {
|
|
42
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
2
|
+
import { countErrorsAfterCorrection, countMISRAErrors, registerSourceCode, TestFile } from "../utils.js";
|
|
3
|
+
import { EnumDecl, FileJp, RecordJp, TypedefDecl } from "@specs-feup/clava/api/Joinpoints.js";
|
|
4
|
+
|
|
5
|
+
const passingCode = `
|
|
6
|
+
typedef int MyInt;
|
|
7
|
+
typedef MyInt AliasInt;
|
|
8
|
+
|
|
9
|
+
typedef int BasicInt;
|
|
10
|
+
typedef BasicInt* PtrToBasicInt;
|
|
11
|
+
|
|
12
|
+
typedef int MyInt2;
|
|
13
|
+
typedef int MyInt3;
|
|
14
|
+
typedef int MyInt4;
|
|
15
|
+
|
|
16
|
+
typedef struct {
|
|
17
|
+
int x;
|
|
18
|
+
int y;
|
|
19
|
+
MyInt2 i2;
|
|
20
|
+
MyInt3 i3[4];
|
|
21
|
+
MyInt4 *i4;
|
|
22
|
+
} MyStruct;
|
|
23
|
+
|
|
24
|
+
typedef int MyInt5;
|
|
25
|
+
typedef union {
|
|
26
|
+
int x;
|
|
27
|
+
int y;
|
|
28
|
+
MyInt5 i5;
|
|
29
|
+
} MyUnion;
|
|
30
|
+
|
|
31
|
+
typedef int BasicInt2;
|
|
32
|
+
void foo(BasicInt2 x) {
|
|
33
|
+
int a = x + 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
typedef int BasicInt3;
|
|
37
|
+
BasicInt3 bar() {
|
|
38
|
+
return (BasicInt3)10;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
int main() {
|
|
42
|
+
AliasInt a = 1;
|
|
43
|
+
BasicInt x = 10;
|
|
44
|
+
MyInt4 y = 11;
|
|
45
|
+
|
|
46
|
+
MyStruct myStructInstance = {1, 2, 3, {4, 5, 6, 7}, &y};
|
|
47
|
+
|
|
48
|
+
MyUnion myUnionInstance;
|
|
49
|
+
myUnionInstance.x = 100;
|
|
50
|
+
|
|
51
|
+
PtrToBasicInt ptr = &x;
|
|
52
|
+
|
|
53
|
+
return 0;
|
|
54
|
+
}`;
|
|
55
|
+
|
|
56
|
+
// 3 errors
|
|
57
|
+
const failingCode1 = `
|
|
58
|
+
typedef int OtherInt;
|
|
59
|
+
|
|
60
|
+
// Unused type defs
|
|
61
|
+
typedef OtherInt** OtherPointer;
|
|
62
|
+
typedef int MyUnusedType;
|
|
63
|
+
typedef int** MyUnusedPointer;
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
// 4 errors, where 1 is the unused tag decl
|
|
67
|
+
const failingCode2 = `
|
|
68
|
+
// Should be removed
|
|
69
|
+
typedef struct {
|
|
70
|
+
int x;
|
|
71
|
+
int y;
|
|
72
|
+
} MyUnusedStruct;
|
|
73
|
+
|
|
74
|
+
// Should be removed
|
|
75
|
+
typedef struct NumberEnum {
|
|
76
|
+
int x;
|
|
77
|
+
int y;
|
|
78
|
+
} MyUnusedStruct2;
|
|
79
|
+
|
|
80
|
+
// Should be replaced by the struct
|
|
81
|
+
typedef struct PersonStruct {
|
|
82
|
+
int id;
|
|
83
|
+
char name[10];
|
|
84
|
+
} Person;
|
|
85
|
+
struct PersonStruct personInstance = {1, "Alice"};
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
// 4 errors, one is from the other class
|
|
89
|
+
const failingCode3 = `
|
|
90
|
+
// Should be removed
|
|
91
|
+
typedef union {
|
|
92
|
+
int x;
|
|
93
|
+
int y;
|
|
94
|
+
} MyUnusedUnion1;
|
|
95
|
+
|
|
96
|
+
// Should be removed
|
|
97
|
+
typedef union NumberUnion1 {
|
|
98
|
+
int x;
|
|
99
|
+
int y;
|
|
100
|
+
} MyUnusedUnion2;
|
|
101
|
+
|
|
102
|
+
// Should be replaced by the union
|
|
103
|
+
typedef union NumberUnion {
|
|
104
|
+
int intValue;
|
|
105
|
+
float floatValue;
|
|
106
|
+
} Number;
|
|
107
|
+
|
|
108
|
+
union NumberUnion unionInst = {.intValue = 10};
|
|
109
|
+
`;
|
|
110
|
+
|
|
111
|
+
// 4 errors, one is from the other class
|
|
112
|
+
const failingCode4 = `
|
|
113
|
+
// Should be removed
|
|
114
|
+
typedef enum {
|
|
115
|
+
A1,
|
|
116
|
+
B1,
|
|
117
|
+
C1
|
|
118
|
+
} MyUnusedEnum;
|
|
119
|
+
|
|
120
|
+
// Should be removed
|
|
121
|
+
typedef enum ColorEnum2 {
|
|
122
|
+
YELLOW,
|
|
123
|
+
BROWN,
|
|
124
|
+
WHITE
|
|
125
|
+
} Color2;
|
|
126
|
+
|
|
127
|
+
// Should be replaced by the enum
|
|
128
|
+
typedef enum ColorEnum {
|
|
129
|
+
RED,
|
|
130
|
+
GREEN,
|
|
131
|
+
BLUE
|
|
132
|
+
} Color;
|
|
133
|
+
enum ColorEnum colorInstance = GREEN;
|
|
134
|
+
`;
|
|
135
|
+
|
|
136
|
+
const files: TestFile[] = [
|
|
137
|
+
{ name: "bad1.c", code: failingCode1 },
|
|
138
|
+
{ name: "bad2.c", code: failingCode2 },
|
|
139
|
+
{ name: "bad3.c", code: failingCode3 },
|
|
140
|
+
{ name: "bad4.c", code: failingCode4 },
|
|
141
|
+
{ name: "good.c", code: passingCode }
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
describe("Rule 2.3", () => {
|
|
145
|
+
registerSourceCode(files);
|
|
146
|
+
|
|
147
|
+
it("should detect errors in bad.c", () => {
|
|
148
|
+
expect(countMISRAErrors()).toBe(15);
|
|
149
|
+
|
|
150
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "bad1.c"}).first()!)).toBe(3);
|
|
151
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "bad2.c"}).first()!)).toBe(4);
|
|
152
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "bad3.c"}).first()!)).toBe(4);
|
|
153
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "bad4.c"}).first()!)).toBe(4);
|
|
154
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("should correct errors in bad.c", () => {
|
|
158
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
159
|
+
|
|
160
|
+
const badFile1 = Query.search(FileJp, {name: "bad1.c"}).first()!;
|
|
161
|
+
expect(Query.searchFrom(badFile1, TypedefDecl).get().length).toBe(0);
|
|
162
|
+
|
|
163
|
+
const badFile2 = Query.search(FileJp, {name: "bad2.c"}).first()!;
|
|
164
|
+
expect(Query.searchFrom(badFile2, TypedefDecl).get().length).toBe(0);
|
|
165
|
+
expect(Query.searchFrom(badFile2, RecordJp).get().length).toBe(1);
|
|
166
|
+
|
|
167
|
+
const badFile3 = Query.search(FileJp, {name: "bad3.c"}).first()!;
|
|
168
|
+
expect(Query.searchFrom(badFile3, TypedefDecl).get().length).toBe(0);
|
|
169
|
+
expect(Query.searchFrom(badFile3, RecordJp).get().length).toBe(1);
|
|
170
|
+
|
|
171
|
+
const badFile4 = Query.search(FileJp, {name: "bad4.c"}).first()!;
|
|
172
|
+
expect(Query.searchFrom(badFile4, TypedefDecl).get().length).toBe(0);
|
|
173
|
+
expect(Query.searchFrom(badFile4, EnumDecl).get().length).toBe(1);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
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 failingCodeEnum1 = `
|
|
6
|
+
enum MyEnum {
|
|
7
|
+
RED, GREEN, BLUE
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
enum EnumForCast1 {
|
|
11
|
+
RED2, GREEN2, BLUE2
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
enum EnumForCast2 {
|
|
15
|
+
RED3, GREEN3, BLUE3
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
enum MyEnum2 {
|
|
19
|
+
RED4, GREEN4, BLUE4
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
enum EnumForPtr {
|
|
23
|
+
RED5, GREEN5, BLUE5
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
enum EnumForArray {
|
|
27
|
+
RED6, GREEN6, BLUE6
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Non-compliant
|
|
31
|
+
enum UnusedEnum {
|
|
32
|
+
RED7, GREEN7, BLUE7
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
void enumAsParam(enum MyEnum color) {
|
|
36
|
+
int i;
|
|
37
|
+
if (color == RED) {
|
|
38
|
+
i = 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
enum EnumForCast1 enumAsReturn() {
|
|
43
|
+
return (enum EnumForCast1) RED2;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
enum EnumForCast2 enumAsReturn2() {
|
|
47
|
+
int id = 2;
|
|
48
|
+
return (enum EnumForCast2) id;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
enum MyEnum2 color_enum = RED4;
|
|
52
|
+
|
|
53
|
+
enum EnumForPtr *colorPtr;
|
|
54
|
+
|
|
55
|
+
enum EnumForArray colorArray[3];
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
const failingCodeEnum2 = `
|
|
59
|
+
typedef enum {
|
|
60
|
+
A1,
|
|
61
|
+
B1,
|
|
62
|
+
C1
|
|
63
|
+
} ColorEnum2;
|
|
64
|
+
ColorEnum2 colorEnum2 = A1;
|
|
65
|
+
|
|
66
|
+
typedef enum MyColors {
|
|
67
|
+
A2,
|
|
68
|
+
B3,
|
|
69
|
+
C4
|
|
70
|
+
} ColorOption;
|
|
71
|
+
enum MyColors my_color = A2;
|
|
72
|
+
ColorOption color_option = B3;
|
|
73
|
+
|
|
74
|
+
// MyColors2 tag should be removed
|
|
75
|
+
typedef enum MyColors2 {
|
|
76
|
+
A5,
|
|
77
|
+
B6,
|
|
78
|
+
C7
|
|
79
|
+
} ColorOption2;
|
|
80
|
+
ColorOption2 color2 = B6;
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
const failingCodeStruct1 = `
|
|
84
|
+
struct MyStruct {
|
|
85
|
+
int x;
|
|
86
|
+
float y;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
struct StructForReturn1 {
|
|
90
|
+
int x;
|
|
91
|
+
float y;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
struct MyStruct2 {
|
|
95
|
+
int x;
|
|
96
|
+
float y;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
struct StructForPtr {
|
|
100
|
+
int x;
|
|
101
|
+
float y;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
struct StructForArray {
|
|
105
|
+
int x;
|
|
106
|
+
float y;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Non-compliant: should be removed
|
|
110
|
+
struct UnusedStruct {
|
|
111
|
+
int x;
|
|
112
|
+
float y;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
void structAsParam(struct MyStruct s) {
|
|
116
|
+
int xField = s.x;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
struct StructForReturn1 structAsReturn() {
|
|
120
|
+
return (struct StructForReturn1){1, 1.5f};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
struct MyStruct2 myStruct = {10, 20.5f};
|
|
124
|
+
struct StructForPtr *structPtr;
|
|
125
|
+
struct StructForArray structArray[3];
|
|
126
|
+
`;
|
|
127
|
+
|
|
128
|
+
const failingCodeStruct2 = `
|
|
129
|
+
typedef struct {
|
|
130
|
+
int x;
|
|
131
|
+
float y;
|
|
132
|
+
} ColorStruct;
|
|
133
|
+
ColorStruct colorStruct = {1, 2.5};
|
|
134
|
+
|
|
135
|
+
typedef struct MyStruct5 {
|
|
136
|
+
int x;
|
|
137
|
+
float y;
|
|
138
|
+
} ColorStruct2;
|
|
139
|
+
struct MyStruct5 struct5 = {2, 4.5};
|
|
140
|
+
ColorStruct2 colorStruct2 = {1, 2.5};
|
|
141
|
+
|
|
142
|
+
// Violation: MyStruct3 tag will be removed
|
|
143
|
+
typedef struct MyStruct3 {
|
|
144
|
+
int x;
|
|
145
|
+
float y;
|
|
146
|
+
} ColorStruct3;
|
|
147
|
+
ColorStruct3 colorStruct3 = {10, 5.5};
|
|
148
|
+
`;
|
|
149
|
+
|
|
150
|
+
const failingCodeUnion1 = `
|
|
151
|
+
union MyUnion {
|
|
152
|
+
int x;
|
|
153
|
+
float y;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
union UnionForReturn1 {
|
|
157
|
+
int x;
|
|
158
|
+
float y;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
union MyUnion2 {
|
|
162
|
+
int x;
|
|
163
|
+
float y;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
union UnionForPtr {
|
|
167
|
+
int x;
|
|
168
|
+
float y;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
union UnionForArray {
|
|
172
|
+
int x;
|
|
173
|
+
float y;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// Non-compliant: should be removed
|
|
177
|
+
union UnusedUnion {
|
|
178
|
+
int x;
|
|
179
|
+
float y;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
void unionAsParam(union MyUnion u) {
|
|
183
|
+
int xField = u.x;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
union UnionForReturn1 unionAsReturn() {
|
|
187
|
+
return (union UnionForReturn1){.x = 1};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
union MyUnion2 myUnion = {.y = 20.5f};
|
|
191
|
+
union UnionForPtr *unionPtr;
|
|
192
|
+
union UnionForArray unionArray[3];
|
|
193
|
+
`;
|
|
194
|
+
|
|
195
|
+
const files: TestFile[] = [
|
|
196
|
+
{ name: "testEnum1.c", code: failingCodeEnum1 },
|
|
197
|
+
{ name: "testEnum2.c", code: failingCodeEnum2 },
|
|
198
|
+
{ name: "testStruct1.c", code: failingCodeStruct1 },
|
|
199
|
+
{ name: "testStruct2.c", code: failingCodeStruct2 },
|
|
200
|
+
{ name: "testUnion1.c", code: failingCodeUnion1 },
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
describe("Rule 2.4", () => {
|
|
204
|
+
registerSourceCode(files);
|
|
205
|
+
|
|
206
|
+
it("should detect errors in bad.c", () => {
|
|
207
|
+
expect(countMISRAErrors()).toBe(5);
|
|
208
|
+
|
|
209
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "testEnum1.c"}).first()!)).toBe(1);
|
|
210
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "testEnum2.c"}).first()!)).toBe(1);
|
|
211
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "testStruct1.c"}).first()!)).toBe(1);
|
|
212
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "testStruct2.c"}).first()!)).toBe(1);
|
|
213
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "testUnion1.c"}).first()!)).toBe(1);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("should correct errors in bad.c", () => {
|
|
217
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
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 test1() {
|
|
7
|
+
int x = 0;
|
|
8
|
+
goto label1;
|
|
9
|
+
|
|
10
|
+
label1:
|
|
11
|
+
x++;
|
|
12
|
+
|
|
13
|
+
return 0;
|
|
14
|
+
}`;
|
|
15
|
+
|
|
16
|
+
const failingCode = `
|
|
17
|
+
int test2() {
|
|
18
|
+
int x = 0;
|
|
19
|
+
label1:
|
|
20
|
+
x = 1;
|
|
21
|
+
label2:
|
|
22
|
+
x++;
|
|
23
|
+
|
|
24
|
+
goto label3;
|
|
25
|
+
|
|
26
|
+
label3:
|
|
27
|
+
x += 4;
|
|
28
|
+
return 0;
|
|
29
|
+
}`;
|
|
30
|
+
|
|
31
|
+
const files: TestFile[] = [
|
|
32
|
+
{ name: "bad.c", code: failingCode },
|
|
33
|
+
{ name: "good.c", code: passingCode }
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
describe("Rule 2.6", () => {
|
|
37
|
+
registerSourceCode(files);
|
|
38
|
+
|
|
39
|
+
it("should detect errors in bad.c", () => {
|
|
40
|
+
expect(countMISRAErrors()).toBe(2);
|
|
41
|
+
|
|
42
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(2);
|
|
43
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should correct errors in bad.c", () => {
|
|
47
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
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 failingCode = `
|
|
6
|
+
int foo(int x, int y, int z);
|
|
7
|
+
|
|
8
|
+
int foo(int x, int y, int z) {
|
|
9
|
+
y++;
|
|
10
|
+
return y;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
int main() {
|
|
14
|
+
int a = 5, b = 10, c = 15;
|
|
15
|
+
int result1 = foo(a, b, c);
|
|
16
|
+
|
|
17
|
+
int result2 = result1 + foo(a, b, c);
|
|
18
|
+
|
|
19
|
+
return result2;
|
|
20
|
+
}`;
|
|
21
|
+
|
|
22
|
+
const passingCode = `
|
|
23
|
+
extern int foo(int x, int y, int z);
|
|
24
|
+
|
|
25
|
+
int my_func(int x, int y, int z) {
|
|
26
|
+
return x + y + z;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
int my_func2() {
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
int bar() {
|
|
34
|
+
return my_func(1, 2, 3) + foo(50, 51, 52);
|
|
35
|
+
}`;
|
|
36
|
+
|
|
37
|
+
const files: TestFile[] = [
|
|
38
|
+
{ name: "bad.c", code: failingCode },
|
|
39
|
+
{ name: "good.c", code: passingCode }
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
describe("Rule 2.7", () => {
|
|
43
|
+
registerSourceCode(files);
|
|
44
|
+
|
|
45
|
+
it("should detect errors in bad.c", () => {
|
|
46
|
+
expect(countMISRAErrors()).toBe(2);
|
|
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);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should correct errors in bad.c", () => {
|
|
53
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
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 = `int main() {
|
|
6
|
+
int x, y, z;// good inline comment
|
|
7
|
+
// good */ comment
|
|
8
|
+
return 0;
|
|
9
|
+
}`;
|
|
10
|
+
|
|
11
|
+
const failingCode = `int test() {
|
|
12
|
+
int x, y, z; // bad inl/*ine comment
|
|
13
|
+
|
|
14
|
+
/* bad /* block comment */
|
|
15
|
+
|
|
16
|
+
return 0;
|
|
17
|
+
}`;
|
|
18
|
+
|
|
19
|
+
const files: TestFile[] = [
|
|
20
|
+
{ name: "bad.c", code: failingCode },
|
|
21
|
+
{ name: "good.c", code: passingCode }
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
describe("Rule 3.1", () => {
|
|
25
|
+
registerSourceCode(files);
|
|
26
|
+
|
|
27
|
+
it("should detect errors in bad.c", () => {
|
|
28
|
+
expect(countMISRAErrors()).toBe(2);
|
|
29
|
+
|
|
30
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "bad.c"}).first()!)).toBe(2);
|
|
31
|
+
expect(countMISRAErrors(Query.search(FileJp, {name: "good.c"}).first()!)).toBe(0);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should correct errors in bad.c", () => {
|
|
35
|
+
expect(countErrorsAfterCorrection()).toBe(0);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import MISRATool from "../MISRATool.js";
|
|
2
|
+
import Clava from "@specs-feup/clava/api/clava/Clava.js";
|
|
3
|
+
import ClavaJoinPoints from "@specs-feup/clava/api/clava/ClavaJoinPoints.js";
|
|
4
|
+
import { FileJp, Program } from "@specs-feup/clava/api/Joinpoints.js";
|
|
5
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
6
|
+
|
|
7
|
+
export function countMISRAErrors(startingPoint: FileJp | Program = Query.root() as Program): number {
|
|
8
|
+
MISRATool.checkCompliance(startingPoint);
|
|
9
|
+
return MISRATool.getMISRAErrors().length;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function countErrorsAfterCorrection(configPath?: string): number {
|
|
13
|
+
MISRATool.applyCorrections(configPath);
|
|
14
|
+
return MISRATool.getMISRAErrors().length;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TestFile {
|
|
18
|
+
name: string,
|
|
19
|
+
code: string
|
|
20
|
+
path?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function registerSourceCode(files: TestFile[]): void {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
Clava.getData().setStandard(process.env.STD_VERSION!);
|
|
26
|
+
Clava.getProgram().push();
|
|
27
|
+
const program = Clava.getProgram();
|
|
28
|
+
files.forEach(file => {
|
|
29
|
+
const sourceFile = ClavaJoinPoints.fileWithSource(file.name, file.code, file.path);
|
|
30
|
+
program.addFile(sourceFile);
|
|
31
|
+
});
|
|
32
|
+
program.rebuild();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
Clava.getProgram().rebuild();
|
|
37
|
+
Clava.getProgram().pop();
|
|
38
|
+
});
|
|
39
|
+
}
|