@specs-feup/clava-misra 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +39 -5
- package/dist/MISRATool.d.ts.map +1 -1
- package/dist/MISRATool.js +102 -46
- 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 -1
- 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 +51 -0
- package/dist/utils/FileUtils.d.ts.map +1 -0
- package/dist/utils/FileUtils.js +121 -0
- package/dist/utils/FileUtils.js.map +1 -0
- package/dist/utils/FunctionUtils.d.ts +25 -0
- package/dist/utils/FunctionUtils.d.ts.map +1 -0
- package/dist/utils/FunctionUtils.js +65 -0
- package/dist/utils/FunctionUtils.js.map +1 -0
- package/dist/utils/IdentifierUtils.d.ts +14 -0
- package/dist/utils/IdentifierUtils.d.ts.map +1 -0
- package/dist/utils/IdentifierUtils.js +87 -0
- package/dist/utils/IdentifierUtils.js.map +1 -0
- package/dist/utils/JoinpointUtils.d.ts +19 -0
- package/dist/utils/JoinpointUtils.d.ts.map +1 -0
- package/dist/utils/JoinpointUtils.js +46 -0
- package/dist/utils/JoinpointUtils.js.map +1 -0
- package/dist/utils/ProgramUtils.d.ts +14 -0
- package/dist/utils/ProgramUtils.d.ts.map +1 -0
- package/dist/utils/ProgramUtils.js +72 -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 +19 -0
- package/dist/utils/VarUtils.d.ts.map +1 -0
- package/dist/utils/VarUtils.js +59 -0
- package/dist/utils/VarUtils.js.map +1 -0
- package/package.json +16 -6
- package/src/MISRA.ts +33 -17
- package/src/MISRAContext.ts +128 -30
- package/src/MISRARule.ts +61 -29
- package/src/MISRATool.ts +108 -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 -1
- 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 +40 -0
- package/src/utils/CommentUtils.ts +29 -0
- package/src/utils/FileUtils.ts +141 -0
- package/src/utils/FunctionUtils.ts +75 -0
- package/src/utils/IdentifierUtils.ts +94 -0
- package/src/utils/JoinpointUtils.ts +53 -0
- package/src/utils/ProgramUtils.ts +83 -0
- package/src/utils/SwitchUtils.ts +52 -0
- package/src/utils/TypeDeclUtils.ts +89 -0
- package/src/utils/VarUtils.ts +70 -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
package/.gitignore
CHANGED
|
@@ -6,6 +6,11 @@ package-lock.json
|
|
|
6
6
|
CxxSources
|
|
7
7
|
/misra_config.json
|
|
8
8
|
/src/main.ts
|
|
9
|
+
c-common-standards
|
|
10
|
+
/c90
|
|
11
|
+
/c99
|
|
12
|
+
/example-suite
|
|
13
|
+
/experiment-3
|
|
9
14
|
|
|
10
15
|
# Extensions
|
|
11
16
|
ltex.dictionary.*
|
|
@@ -19,6 +24,9 @@ yarn-debug.log*
|
|
|
19
24
|
yarn-error.log*
|
|
20
25
|
lerna-debug.log*
|
|
21
26
|
|
|
27
|
+
# Files generated during tests
|
|
28
|
+
__clava_woven_for_file_rebuild/
|
|
29
|
+
|
|
22
30
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
23
31
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
24
32
|
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Clava
|
|
1
|
+
# Clava-MISRA Tool
|
|
2
2
|
|
|
3
3
|
A Clava-based library to automatically detect and correct parts of C code that violate MISRA-C:2012 coding standard.
|
|
4
4
|
|
|
@@ -15,10 +15,10 @@ npm install @specs-feup/clava-misra
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
17
|
### 1. Analysis
|
|
18
|
-
You can use the tool to
|
|
18
|
+
You can use the tool to detect violations by executing the following statements in your script:
|
|
19
19
|
|
|
20
20
|
```ts
|
|
21
|
-
import MISRATool from "@specs-feup/clava-misra/
|
|
21
|
+
import MISRATool from "@specs-feup/clava-misra/MISRATool";
|
|
22
22
|
|
|
23
23
|
MISRATool.checkCompliance();
|
|
24
24
|
```
|
|
@@ -28,17 +28,17 @@ After analysis, each identified violation will be displayed, including its locat
|
|
|
28
28
|
Besides analysis, the tool can also correct the provided source code to comply with the coding guidelines, using the following statements:
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
|
-
import MISRATool from "@specs-feup/clava-misra/
|
|
31
|
+
import MISRATool from "@specs-feup/clava-misra/MISRATool";
|
|
32
32
|
|
|
33
|
-
MISRATool.
|
|
33
|
+
MISRATool.correctViolations();
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
After the transformation, any violations that could not be fixed will be displayed along with their justification. The corrected files will be saved in the `woven_code` folder.
|
|
37
37
|
|
|
38
38
|
You can provide an **optional** JSON config file to assist in correcting specific rules, such as implicit function calls, disallowed functions, and missing return statements. For instance, you can:
|
|
39
39
|
- Define default values for certain types to address functions with missing return statements.
|
|
40
|
-
- Provide custom implementations for disallowed functions.
|
|
41
40
|
- Specify the path or library for implicit function calls.
|
|
41
|
+
- Provide custom implementations for disallowed functions.
|
|
42
42
|
|
|
43
43
|
The config file should follow this structure:
|
|
44
44
|
```json
|
|
@@ -49,39 +49,73 @@ The config file should follow this structure:
|
|
|
49
49
|
"enum Status": "SUCCESS",
|
|
50
50
|
"Color": "RED",
|
|
51
51
|
"my_int_type": "0"
|
|
52
|
+
},
|
|
53
|
+
"implicitCalls": {
|
|
54
|
+
"printf": "stdio.h",
|
|
55
|
+
"foo": "CxxSources/utils/functions.c"
|
|
56
|
+
},
|
|
57
|
+
"disallowedFunctions": {
|
|
58
|
+
"stdlib.h": {
|
|
59
|
+
"malloc": {
|
|
60
|
+
"replacement": "custom_malloc",
|
|
61
|
+
"location": "utils/custom_stdlib.c"
|
|
62
|
+
},
|
|
63
|
+
"exit": {
|
|
64
|
+
"replacement": "custom_exit",
|
|
65
|
+
"location": "utils/custom_stdlib.c"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
52
68
|
}
|
|
53
69
|
}
|
|
54
70
|
```
|
|
55
|
-
**Note:** Not all fields are
|
|
71
|
+
**Note:** Not all fields (`defaultValues`, `implicitCalls`, `disallowedFunctions`) are mandatory. If the config file is not provided or lacks the necessary information to fix a violation, the violation will remain and be displayed as unresolved.
|
|
56
72
|
|
|
57
|
-
After preparing the config file, provide its full path to `applyCorrections` method call:
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
import MISRATool from "@specs-feup/clava-misra/dist/MISRATool.js";
|
|
61
|
-
|
|
62
|
-
MISRATool.applyCorrections("/full/path/to/json/config/file");
|
|
63
|
-
```
|
|
64
73
|
|
|
65
74
|
## Execution
|
|
66
75
|
|
|
67
|
-
To execute a project that uses this tool,
|
|
76
|
+
To execute a project that uses this tool, provide the following information:
|
|
68
77
|
|
|
69
78
|
- The path to your **script file**.
|
|
70
79
|
- The **C standard** to use (`c90`, `c99`, or `c11`).
|
|
71
80
|
- The path to the **source code** to process.
|
|
81
|
+
- *(Optional)* The full path to a **config file**.
|
|
82
|
+
- *(Optional)* The **analysis type**:
|
|
83
|
+
- `system`: For rules whose violation detection requires analyzing multiple files together
|
|
84
|
+
- `single`: For rules whose violation detection is identified within individual translation units independently
|
|
85
|
+
- `all`: For both system and single translation rules (default)
|
|
72
86
|
|
|
73
87
|
```bash
|
|
74
|
-
npx clava classic
|
|
88
|
+
npx clava classic <scriptFile.js> -pi -std <c90 | c99 | c11> -p <path/to/source/code> [-av "<options>"]
|
|
75
89
|
```
|
|
76
90
|
|
|
77
|
-
**
|
|
91
|
+
**Note:** Some guidelines are tied to a specific C language standard (e.g., c90, c99, c11). Therefore, they will not be detected when running under other standards. For instance, the rule 17.3 (*"A function shall not be declared implicitly"*) only applies to c90 and is not reported when analyzing c99.
|
|
92
|
+
|
|
93
|
+
### Examples:
|
|
94
|
+
|
|
95
|
+
Default use (no config file or analysis type):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npx clava classic dist/main.js -pi -std c99 -p CxxSources/
|
|
99
|
+
```
|
|
100
|
+
In this case, analysis type is `all` by default.
|
|
101
|
+
|
|
102
|
+
With analysis type specified:
|
|
103
|
+
```bash
|
|
104
|
+
npx clava classic dist/main.js -pi -std c99 -p CxxSources/ -av "type=system"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Using a config file:
|
|
108
|
+
```bash
|
|
109
|
+
npx clava classic dist/main.js -pi -std c99 -p CxxSources/ -av "config=misra_config.json"
|
|
110
|
+
```
|
|
78
111
|
|
|
112
|
+
With both analysis and config file specified:
|
|
79
113
|
```bash
|
|
80
|
-
npx clava classic main.js -pi -std c99 -p CxxSources/
|
|
114
|
+
npx clava classic dist/main.js -pi -std c99 -p CxxSources/ -av "type=system config=misra_config.json"
|
|
81
115
|
```
|
|
82
116
|
|
|
83
117
|
To view other available options, run:
|
|
84
118
|
|
|
85
119
|
```bash
|
|
86
|
-
npx clava classic
|
|
120
|
+
npx clava classic --help
|
|
87
121
|
```
|
package/dist/MISRA.d.ts
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
import { If, Joinpoint, Statement, Switch } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
+
type NodeID = string;
|
|
3
|
+
/**
|
|
4
|
+
* Specifies whether a MISRA rule is applied to a single translation unit
|
|
5
|
+
* or requires analysis of the entire program.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum AnalysisType {
|
|
8
|
+
SINGLE_TRANSLATION_UNIT = "single",
|
|
9
|
+
SYSTEM = "system"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Types of transformations a rule can apply to a AST node.
|
|
13
|
+
*/
|
|
2
14
|
export declare enum MISRATransformationType {
|
|
3
15
|
NoChange = 0,
|
|
4
16
|
DescendantChange = 1,
|
|
5
17
|
Replacement = 2,
|
|
6
18
|
Removal = 3
|
|
7
19
|
}
|
|
20
|
+
export type MISRATransformationResults = Map<NodeID, MISRATransformationType>;
|
|
8
21
|
/**
|
|
9
|
-
* Represents
|
|
22
|
+
* Represents a MISRA-C rule violation.
|
|
10
23
|
*/
|
|
11
24
|
export declare class MISRAError {
|
|
12
25
|
/**
|
|
13
|
-
* Represents the specific MISRA rule that was violated
|
|
26
|
+
* Represents the specific MISRA-C rule that was violated
|
|
14
27
|
*/
|
|
15
|
-
ruleID: string;
|
|
28
|
+
readonly ruleID: string;
|
|
16
29
|
/**
|
|
17
30
|
* The joinpoint where the error was detected
|
|
18
31
|
*/
|
|
19
|
-
|
|
32
|
+
readonly joinpoint: Joinpoint;
|
|
20
33
|
/**
|
|
21
34
|
* Explanation of the violation
|
|
22
35
|
*/
|
|
23
|
-
message: string;
|
|
36
|
+
readonly message: string;
|
|
24
37
|
/**
|
|
25
38
|
*
|
|
26
|
-
* @param ruleID
|
|
27
|
-
* @param $jp
|
|
28
|
-
* @param message
|
|
39
|
+
* @param ruleID Identifier of the violated rule
|
|
40
|
+
* @param $jp Joinpoint where the error was detected
|
|
41
|
+
* @param message Description of the error
|
|
29
42
|
*/
|
|
30
43
|
constructor(ruleID: string, $jp: Joinpoint, message: string);
|
|
31
44
|
/**
|
|
@@ -34,6 +47,10 @@ export declare class MISRAError {
|
|
|
34
47
|
* @returns Returns `true` if the errors are the same, `false` otherwise
|
|
35
48
|
*/
|
|
36
49
|
equals(other: MISRAError): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Checks if the associated joinpoint is still present in program's AST
|
|
52
|
+
*/
|
|
53
|
+
isActiveError(): boolean;
|
|
37
54
|
}
|
|
38
55
|
/**
|
|
39
56
|
* A report of a MISRA transformation, including the transformation type and an optional new joinpoint node.
|
|
@@ -44,11 +61,11 @@ export declare class MISRATransformationReport {
|
|
|
44
61
|
/**
|
|
45
62
|
* The type of the MISRA transformation
|
|
46
63
|
*/
|
|
47
|
-
type: MISRATransformationType;
|
|
64
|
+
readonly type: MISRATransformationType;
|
|
48
65
|
/**
|
|
49
66
|
* An optional new joinpoint node, provided if the transformation involves a replacement
|
|
50
67
|
*/
|
|
51
|
-
newNode?: Joinpoint;
|
|
68
|
+
readonly newNode?: Joinpoint;
|
|
52
69
|
/**
|
|
53
70
|
*
|
|
54
71
|
* @param type The type of the MISRA transformation
|
|
@@ -126,4 +143,5 @@ export declare class MISRASwitchConverter {
|
|
|
126
143
|
*/
|
|
127
144
|
private static organizeCaseGroups;
|
|
128
145
|
}
|
|
146
|
+
export {};
|
|
129
147
|
//# sourceMappingURL=MISRA.d.ts.map
|
package/dist/MISRA.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MISRA.d.ts","sourceRoot":"","sources":["../src/MISRA.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,EAAE,EAAE,SAAS,EAAS,SAAS,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"MISRA.d.ts","sourceRoot":"","sources":["../src/MISRA.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,EAAE,EAAE,SAAS,EAAS,SAAS,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAMjI,KAAK,MAAM,GAAG,MAAM,CAAC;AAErB;;;GAGG;AACH,oBAAY,YAAY;IACpB,uBAAuB,WAAW;IAClC,MAAM,WAAW;CACpB;AAED;;GAEG;AACH,oBAAY,uBAAuB;IAC/B,QAAQ,IAAA;IACR,gBAAgB,IAAA;IAChB,WAAW,IAAA;IACX,OAAO,IAAA;CACV;AA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M,CAAC,gBAAgB;IAiB/B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;CASpC"}
|
package/dist/MISRA.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { Break, Case } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isCommentStmt } from "./utils/CommentUtils.js";
|
|
3
3
|
import ClavaJoinPoints from "@specs-feup/clava/api/clava/ClavaJoinPoints.js";
|
|
4
|
+
import Query from "@specs-feup/lara/api/weaver/Query.js";
|
|
5
|
+
import { countSwitchClauses } from "./utils/SwitchUtils.js";
|
|
6
|
+
/**
|
|
7
|
+
* Specifies whether a MISRA rule is applied to a single translation unit
|
|
8
|
+
* or requires analysis of the entire program.
|
|
9
|
+
*/
|
|
10
|
+
export var AnalysisType;
|
|
11
|
+
(function (AnalysisType) {
|
|
12
|
+
AnalysisType["SINGLE_TRANSLATION_UNIT"] = "single";
|
|
13
|
+
AnalysisType["SYSTEM"] = "system";
|
|
14
|
+
})(AnalysisType || (AnalysisType = {}));
|
|
15
|
+
/**
|
|
16
|
+
* Types of transformations a rule can apply to a AST node.
|
|
17
|
+
*/
|
|
4
18
|
export var MISRATransformationType;
|
|
5
19
|
(function (MISRATransformationType) {
|
|
6
20
|
MISRATransformationType[MISRATransformationType["NoChange"] = 0] = "NoChange";
|
|
@@ -9,30 +23,30 @@ export var MISRATransformationType;
|
|
|
9
23
|
MISRATransformationType[MISRATransformationType["Removal"] = 3] = "Removal";
|
|
10
24
|
})(MISRATransformationType || (MISRATransformationType = {}));
|
|
11
25
|
/**
|
|
12
|
-
* Represents
|
|
26
|
+
* Represents a MISRA-C rule violation.
|
|
13
27
|
*/
|
|
14
28
|
export class MISRAError {
|
|
15
29
|
/**
|
|
16
|
-
* Represents the specific MISRA rule that was violated
|
|
30
|
+
* Represents the specific MISRA-C rule that was violated
|
|
17
31
|
*/
|
|
18
32
|
ruleID;
|
|
19
33
|
/**
|
|
20
34
|
* The joinpoint where the error was detected
|
|
21
35
|
*/
|
|
22
|
-
|
|
36
|
+
joinpoint;
|
|
23
37
|
/**
|
|
24
38
|
* Explanation of the violation
|
|
25
39
|
*/
|
|
26
40
|
message;
|
|
27
41
|
/**
|
|
28
42
|
*
|
|
29
|
-
* @param ruleID
|
|
30
|
-
* @param $jp
|
|
31
|
-
* @param message
|
|
43
|
+
* @param ruleID Identifier of the violated rule
|
|
44
|
+
* @param $jp Joinpoint where the error was detected
|
|
45
|
+
* @param message Description of the error
|
|
32
46
|
*/
|
|
33
47
|
constructor(ruleID, $jp, message) {
|
|
34
48
|
this.ruleID = ruleID;
|
|
35
|
-
this
|
|
49
|
+
this.joinpoint = $jp;
|
|
36
50
|
this.message = message;
|
|
37
51
|
}
|
|
38
52
|
/**
|
|
@@ -42,9 +56,15 @@ export class MISRAError {
|
|
|
42
56
|
*/
|
|
43
57
|
equals(other) {
|
|
44
58
|
return this.ruleID === other.ruleID &&
|
|
45
|
-
this
|
|
59
|
+
this.joinpoint.astId === other.joinpoint.astId &&
|
|
46
60
|
this.message === other.message;
|
|
47
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Checks if the associated joinpoint is still present in program's AST
|
|
64
|
+
*/
|
|
65
|
+
isActiveError() {
|
|
66
|
+
return Query.root().contains(this.joinpoint);
|
|
67
|
+
}
|
|
48
68
|
}
|
|
49
69
|
/**
|
|
50
70
|
* A report of a MISRA transformation, including the transformation type and an optional new joinpoint node.
|
|
@@ -86,7 +106,7 @@ export class MISRASwitchConverter {
|
|
|
86
106
|
* @returns The converted statements or `undefined` if no statements remain
|
|
87
107
|
*/
|
|
88
108
|
static convert(switchStmt) {
|
|
89
|
-
if (switchStmt.hasDefaultCase &&
|
|
109
|
+
if (switchStmt.hasDefaultCase && countSwitchClauses(switchStmt) < 2) { // The statements will always be executed
|
|
90
110
|
return this.convertToConsecutiveStmts(switchStmt);
|
|
91
111
|
}
|
|
92
112
|
else {
|
package/dist/MISRA.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MISRA.js","sourceRoot":"","sources":["../src/MISRA.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,EAAE,IAAI,EAAuD,MAAM,qCAAqC,CAAC;AACjI,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"MISRA.js","sourceRoot":"","sources":["../src/MISRA.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,EAAE,IAAI,EAAuD,MAAM,qCAAqC,CAAC;AACjI,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,eAAe,MAAM,gDAAgD,CAAC;AAC7E,OAAO,KAAK,MAAM,sCAAsC,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAI5D;;;GAGG;AACH,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACpB,kDAAkC,CAAA;IAClC,iCAAiB,CAAA;AACrB,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,uBAKX;AALD,WAAY,uBAAuB;IAC/B,6EAAQ,CAAA;IACR,6FAAgB,CAAA;IAChB,mFAAW,CAAA;IACX,2EAAO,CAAA;AACX,CAAC,EALW,uBAAuB,KAAvB,uBAAuB,QAKlC;AAID;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;OAEG;IACa,MAAM,CAAS;IAC/B;;OAEG;IACa,SAAS,CAAY;IACrC;;OAEG;IACa,OAAO,CAAS;IAEhC;;;;;OAKG;IACH,YAAY,MAAc,EAAE,GAAc,EAAE,OAAe;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;QACrB,IAAI,CAAC,OAAO,GAAI,OAAO,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAiB;QACpB,OAAO,IAAI,CAAC,MAAM,KAA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EAAE,CAAC;QAC9B,IAAI,WAAW,GAAW,EAAE,CAAC;QAE7B,KAAK,MAAM,QAAQ,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;YACtC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAE3B,IAAI,QAAQ,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC,CAAC,0BAA0B;gBAChE,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBAC7B,WAAW,GAAG,EAAE,CAAC;YACrB,CAAC;QACL,CAAC;QAED,8EAA8E;QAC9E,OAAO,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,kBAAkB,CAAC,UAAoB;QAClD,MAAM,gBAAgB,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;QACjG,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;QAE1F,IAAI,YAAY,EAAE,CAAC;YACf,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,gBAAgB,CAAC;IAC5B,CAAC;CACJ"}
|
package/dist/MISRAContext.d.ts
CHANGED
|
@@ -1,21 +1,75 @@
|
|
|
1
1
|
import { Joinpoint } from "@specs-feup/clava/api/Joinpoints.js";
|
|
2
|
-
import { MISRAError } from "./MISRA.js";
|
|
2
|
+
import { MISRAError, MISRATransformationResults, MISRATransformationType } from "./MISRA.js";
|
|
3
|
+
import Context from "./ast-visitor/Context.js";
|
|
3
4
|
/**
|
|
4
|
-
* Tracks MISRA
|
|
5
|
-
* Also
|
|
5
|
+
* Tracks MISRA-C violations during the analysis and/or transformation of the code.
|
|
6
|
+
* Also generates unique variable and function names.
|
|
6
7
|
*/
|
|
7
|
-
export default class MISRAContext {
|
|
8
|
+
export default class MISRAContext extends Context<MISRATransformationResults> {
|
|
8
9
|
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Returns all violations found in the source code.
|
|
12
|
+
*/
|
|
9
13
|
get errors(): MISRAError[];
|
|
10
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Returns violations linked to nodes that are still present in the AST after correction.
|
|
16
|
+
*/
|
|
17
|
+
get activeErrors(): MISRAError[];
|
|
18
|
+
/**
|
|
19
|
+
* Orders errors according to their location
|
|
20
|
+
*/
|
|
21
|
+
private sortErrors;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the user-provided configuration that assists in violation correction, if provided. Otherwise, returns undefined.
|
|
24
|
+
*/
|
|
11
25
|
get config(): Map<string, any> | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Loads the JSON config file and transforms it into an internal Map representation.
|
|
28
|
+
* If the file does not exist, logs an error and exits the process.
|
|
29
|
+
*/
|
|
12
30
|
set config(configFilePath: string);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Clears stored information.
|
|
33
|
+
*/
|
|
34
|
+
resetStorage(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the type of transformation applied by the specified rule to the given AST node.
|
|
37
|
+
* If no transformation was recorded, returns undefined.
|
|
38
|
+
*
|
|
39
|
+
* @param ruleID Identifier of the violated rule
|
|
40
|
+
* @param $jp AST node
|
|
41
|
+
* @returns The type of transformation applied, or undefined if none was recorded.
|
|
42
|
+
*/
|
|
43
|
+
getRuleResult(ruleID: string, $jp: Joinpoint): MISRATransformationType | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Registers the type of transformation a rule applied to a AST node
|
|
46
|
+
* @param ruleID Identifier of the violated rule
|
|
47
|
+
* @param $jp
|
|
48
|
+
* @param result Applied transformation
|
|
49
|
+
*/
|
|
50
|
+
addRuleResult(ruleID: string, $jp: Joinpoint, result: MISRATransformationType): void;
|
|
51
|
+
/**
|
|
52
|
+
* Registers a new violation of the standard
|
|
53
|
+
*
|
|
54
|
+
* @param ruleID Identifier of the violated rule
|
|
55
|
+
* @param $jp Joinpoint where the error was detected
|
|
56
|
+
* @param message Description of the error
|
|
57
|
+
*/
|
|
16
58
|
addMISRAError(ruleID: string, $jp: Joinpoint, message: string): void;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
59
|
+
generateIdentifierName($jp: Joinpoint): string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Outputs a formatted MISRA-C rule violation message
|
|
62
|
+
*
|
|
63
|
+
* @param error - The MISRA error object containing the rule ID, message, and location
|
|
64
|
+
*/
|
|
65
|
+
private outputError;
|
|
66
|
+
/**
|
|
67
|
+
* Displays all violations found in the source code.
|
|
68
|
+
*/
|
|
69
|
+
outputAllErrors(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Displays violations linked to nodes that are still present in the AST after correction.
|
|
72
|
+
*/
|
|
73
|
+
outputActiveErrors(): void;
|
|
20
74
|
}
|
|
21
75
|
//# sourceMappingURL=MISRAContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MISRAContext.d.ts","sourceRoot":"","sources":["../src/MISRAContext.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"MISRAContext.d.ts","sourceRoot":"","sources":["../src/MISRAContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,SAAS,EAA6C,MAAM,qCAAqC,CAAC;AACjI,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAE7F,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAG/C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,OAAO,CAAC,0BAA0B,CAAC;;IA+BzE;;OAEG;IACH,IAAI,MAAM,IAAI,UAAU,EAAE,CAEzB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,UAAU,EAAE,CAE/B;IAED;;OAEG;IACH,OAAO,CAAC,UAAU;IAKnB;;OAEG;IACF,IAAI,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAEzC;IAED;;;OAGG;IACH,IAAI,MAAM,CAAC,cAAc,EAAE,MAAM,EAQhC;IAED;;OAEG;IACH,YAAY;IAQZ;;;;;;;OAOG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,GAAG,uBAAuB,GAAG,SAAS;IAIlF;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,uBAAuB;IAU7E;;;;;;OAMG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM;IAQ7D,sBAAsB,CAAC,GAAG,EAAE,SAAS;IAkBrC;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,eAAe,IAAI,IAAI;IAKvB;;OAEG;IACH,kBAAkB,IAAI,IAAI;CAK7B"}
|
package/dist/MISRAContext.js
CHANGED
|
@@ -1,37 +1,68 @@
|
|
|
1
|
+
import { EnumDecl, FunctionJp, LabelStmt, RecordJp, TypedefDecl, Vardecl } from "@specs-feup/clava/api/Joinpoints.js";
|
|
1
2
|
import { MISRAError } from "./MISRA.js";
|
|
2
3
|
import * as fs from 'fs';
|
|
4
|
+
import Context from "./ast-visitor/Context.js";
|
|
5
|
+
import { compareLocation, getFileLocation } from "./utils/JoinpointUtils.js";
|
|
3
6
|
/**
|
|
4
|
-
* Tracks MISRA
|
|
5
|
-
* Also
|
|
7
|
+
* Tracks MISRA-C violations during the analysis and/or transformation of the code.
|
|
8
|
+
* Also generates unique variable and function names.
|
|
6
9
|
*/
|
|
7
|
-
export default class MISRAContext {
|
|
10
|
+
export default class MISRAContext extends Context {
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
12
|
+
* Stores MISRA-C rule violations.
|
|
13
|
+
*
|
|
14
|
+
* When checking compliance, this includes all detected violations.
|
|
15
|
+
* When performing transformations, it includes only the violations that could not be resolved.
|
|
10
16
|
*/
|
|
11
17
|
#misraErrors = [];
|
|
18
|
+
#misraErrorKeys = new Set();
|
|
12
19
|
/**
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
#misraWarnings = [];
|
|
16
|
-
/**
|
|
17
|
-
* Configuration provided by the user to assist in rule corrections
|
|
20
|
+
* User-provided configuration to assist in violation correction
|
|
18
21
|
*/
|
|
19
22
|
#config = undefined;
|
|
20
23
|
#varCounter = 0;
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
24
|
+
#functionCounter = 0;
|
|
25
|
+
#labelCounter = 0;
|
|
26
|
+
#typeDefCounter = 0;
|
|
27
|
+
#enumCounter = 0;
|
|
28
|
+
#structCounter = 0;
|
|
29
|
+
#unionCounter = 0;
|
|
30
|
+
#varPrefix = "_misra_var_";
|
|
31
|
+
#funcPrefix = "_misra_func_";
|
|
32
|
+
#labelPrefix = "_misra_label_";
|
|
33
|
+
#typeDefPrefix = "_misra_typedef_";
|
|
34
|
+
#enumPrefix = "_misra_enum_";
|
|
35
|
+
#structPrefix = "_misra_struct_";
|
|
36
|
+
#unionPrefix = "_misra_union_";
|
|
37
|
+
/**
|
|
38
|
+
* Returns all violations found in the source code.
|
|
39
|
+
*/
|
|
26
40
|
get errors() {
|
|
27
41
|
return this.#misraErrors;
|
|
28
42
|
}
|
|
29
|
-
|
|
30
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Returns violations linked to nodes that are still present in the AST after correction.
|
|
45
|
+
*/
|
|
46
|
+
get activeErrors() {
|
|
47
|
+
return this.#misraErrors.filter(error => error.isActiveError());
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Orders errors according to their location
|
|
51
|
+
*/
|
|
52
|
+
sortErrors(errors) {
|
|
53
|
+
let errorList = errors ? errors : this.#misraErrors;
|
|
54
|
+
errorList.sort((error1, error2) => compareLocation(error1.joinpoint, error2.joinpoint));
|
|
31
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns the user-provided configuration that assists in violation correction, if provided. Otherwise, returns undefined.
|
|
58
|
+
*/
|
|
32
59
|
get config() {
|
|
33
60
|
return this.#config;
|
|
34
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Loads the JSON config file and transforms it into an internal Map representation.
|
|
64
|
+
* If the file does not exist, logs an error and exits the process.
|
|
65
|
+
*/
|
|
35
66
|
set config(configFilePath) {
|
|
36
67
|
if (fs.existsSync(configFilePath)) {
|
|
37
68
|
const data = fs.readFileSync(configFilePath, 'utf-8');
|
|
@@ -42,34 +73,99 @@ export default class MISRAContext {
|
|
|
42
73
|
process.exit(1);
|
|
43
74
|
}
|
|
44
75
|
}
|
|
45
|
-
|
|
46
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Clears stored information.
|
|
78
|
+
*/
|
|
79
|
+
resetStorage() {
|
|
80
|
+
[...this.storage.keys()].forEach(key => {
|
|
81
|
+
this.storage.set(key, new Map());
|
|
82
|
+
});
|
|
83
|
+
this.#misraErrors = [];
|
|
84
|
+
this.#misraErrorKeys = new Set();
|
|
47
85
|
}
|
|
48
|
-
|
|
49
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Returns the type of transformation applied by the specified rule to the given AST node.
|
|
88
|
+
* If no transformation was recorded, returns undefined.
|
|
89
|
+
*
|
|
90
|
+
* @param ruleID Identifier of the violated rule
|
|
91
|
+
* @param $jp AST node
|
|
92
|
+
* @returns The type of transformation applied, or undefined if none was recorded.
|
|
93
|
+
*/
|
|
94
|
+
getRuleResult(ruleID, $jp) {
|
|
95
|
+
return this.get(ruleID)?.get($jp.astId);
|
|
50
96
|
}
|
|
51
|
-
|
|
52
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Registers the type of transformation a rule applied to a AST node
|
|
99
|
+
* @param ruleID Identifier of the violated rule
|
|
100
|
+
* @param $jp
|
|
101
|
+
* @param result Applied transformation
|
|
102
|
+
*/
|
|
103
|
+
addRuleResult(ruleID, $jp, result) {
|
|
104
|
+
let transformations = this.get(ruleID);
|
|
105
|
+
if (transformations === undefined) {
|
|
106
|
+
transformations = new Map();
|
|
107
|
+
this.put(ruleID, transformations);
|
|
108
|
+
}
|
|
109
|
+
transformations.set($jp.astId, result);
|
|
53
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Registers a new violation of the standard
|
|
113
|
+
*
|
|
114
|
+
* @param ruleID Identifier of the violated rule
|
|
115
|
+
* @param $jp Joinpoint where the error was detected
|
|
116
|
+
* @param message Description of the error
|
|
117
|
+
*/
|
|
54
118
|
addMISRAError(ruleID, $jp, message) {
|
|
55
|
-
const
|
|
56
|
-
if (!this.#
|
|
57
|
-
this.#
|
|
119
|
+
const key = `${ruleID}-${$jp.astId}-${message}`;
|
|
120
|
+
if (!this.#misraErrorKeys.has(key)) {
|
|
121
|
+
this.#misraErrorKeys.add(key);
|
|
122
|
+
this.#misraErrors.push(new MISRAError(ruleID, $jp, message));
|
|
58
123
|
}
|
|
59
124
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
125
|
+
generateIdentifierName($jp) {
|
|
126
|
+
if ($jp instanceof Vardecl) {
|
|
127
|
+
return `${this.#varPrefix}${this.#varCounter++}`;
|
|
128
|
+
}
|
|
129
|
+
else if ($jp instanceof FunctionJp) {
|
|
130
|
+
return `${this.#funcPrefix}${this.#functionCounter++}`;
|
|
131
|
+
}
|
|
132
|
+
else if ($jp instanceof LabelStmt) {
|
|
133
|
+
return `${this.#labelPrefix}${this.#labelCounter++}`;
|
|
134
|
+
}
|
|
135
|
+
else if ($jp instanceof TypedefDecl) {
|
|
136
|
+
return `${this.#typeDefPrefix}${this.#typeDefCounter++}`;
|
|
137
|
+
}
|
|
138
|
+
else if ($jp instanceof EnumDecl) {
|
|
139
|
+
return `${this.#enumPrefix}${this.#enumCounter++}`;
|
|
64
140
|
}
|
|
141
|
+
else if ($jp instanceof RecordJp) {
|
|
142
|
+
return $jp.kind === `struct` ?
|
|
143
|
+
`${this.#structPrefix}${this.#structCounter++}` :
|
|
144
|
+
`${this.#unionPrefix}${this.#unionCounter++}`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Outputs a formatted MISRA-C rule violation message
|
|
149
|
+
*
|
|
150
|
+
* @param error - The MISRA error object containing the rule ID, message, and location
|
|
151
|
+
*/
|
|
152
|
+
outputError(error) {
|
|
153
|
+
console.log(`- [Rule ${error.ruleID}] at ${getFileLocation(error.joinpoint)}: ${error.message}\n`);
|
|
65
154
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Displays all violations found in the source code.
|
|
157
|
+
*/
|
|
158
|
+
outputAllErrors() {
|
|
159
|
+
this.sortErrors();
|
|
160
|
+
this.#misraErrors.forEach(error => this.outputError(error));
|
|
69
161
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Displays violations linked to nodes that are still present in the AST after correction.
|
|
164
|
+
*/
|
|
165
|
+
outputActiveErrors() {
|
|
166
|
+
const errors = this.activeErrors;
|
|
167
|
+
this.sortErrors(errors);
|
|
168
|
+
errors.forEach(error => this.outputError(error));
|
|
73
169
|
}
|
|
74
170
|
}
|
|
75
171
|
//# sourceMappingURL=MISRAContext.js.map
|