Code annotations are special comments that can be used to suppress
issues and/or to assign a justification to an issue. This rule
describes comments that can be used for such code annotations. Each code
annotation rule specifies the syntax for such a comment (option
format).
The code annotation rule can limit the affected issues by, for example:
the code portion (scope) where an issue is
reported
the issue kind(s) like style violations vs. metric
issues
These options have a similar structure: First, you set their group
attribute to the regular expression group in the format string which defines
the relevant portion of the comment for this field (group 0 is the complete
comment, group 1 the first group in parens, etc.). Then choose as
value attribute how the required information should be extracted
from the selected comment portion, or provide that information directly.
You can define your own comment format by copying the rule and changing
options as required, e.g. to use your company's name instead of
Axivion in the comments.
Assuming the default settings for this rule, a code annotation example
comment using this rule would be:
/* AXIVION Comment Line MisraC2012-20.5: my justification */
When selecting a custom parser, this is the Python function to call as parser.
You have to supply this function in a Python layer.
It should return an allowed value and it takes as arguments, in order:
1. The comment object
2. The text corresponding to the selected regex group
3. Optionally: issue details of the issue being affected (only needed if the
comment should behave differently for different issues)
Ignored when not selecting a custom parser.
action.group : int = 0
Index of the regex group in the format which should be handed over to the given
parser in order to dynamically extract the value from the comment.
Index 0 is the complete comment text, index 1 the first group in (), etc.
Ignored when selecting a statically known value instead of a parser.
Globbing pattern to restrict the affected issues by their reported entity.
For architecture violations, this field is compared against the name of
the source entity of the causing edge.
When selecting a custom parser, this is the Python function to call as parser.
You have to supply this function in a Python layer.
It should return an allowed value and it takes as arguments, in order:
1. The comment object
2. The text corresponding to the selected regex group
3. Optionally: issue details of the issue being affected (only needed if the
comment should behave differently for different issues)
Ignored when not selecting a custom parser.
entity.group : int = 0
Index of the regex group in the format which should be handed over to the given
parser in order to dynamically extract the value from the comment.
Index 0 is the complete comment text, index 1 the first group in (), etc.
Ignored when selecting a statically known value instead of a parser.
When selecting a custom parser, this is the Python function to call as parser.
You have to supply this function in a Python layer.
It should return an allowed value and it takes as arguments, in order:
1. The comment object
2. The text corresponding to the selected regex group
3. Optionally: issue details of the issue being affected (only needed if the
comment should behave differently for different issues)
Ignored when not selecting a custom parser.
justification.group : int = 2
Index of the regex group in the format which should be handed over to the given
parser in order to dynamically extract the value from the comment.
Index 0 is the complete comment text, index 1 the first group in (), etc.
Ignored when selecting a statically known value instead of a parser.
justification.in_next_comment : bool = False
Whether the justification appears in the next comment. Only used for
dynamically extracted justifications.
justification.in_previous_comment : bool = False
Whether the justification appears in the previous comment. Only used for
dynamically extracted justifications.
justification.transparent : bool = False
If there is no justification in a comment, affected issues will continue to
search for their justification in preceding comments. Only affects suppressing
annotations (pure commenting annotations always continue the search).
When selecting a custom parser, this is the Python function to call as parser.
You have to supply this function in a Python layer.
It should return an allowed value and it takes as arguments, in order:
1. The comment object
2. The text corresponding to the selected regex group
3. Optionally: issue details of the issue being affected (only needed if the
comment should behave differently for different issues)
Ignored when not selecting a custom parser.
kind.group : int = 0
Index of the regex group in the format which should be handed over to the given
parser in order to dynamically extract the value from the comment.
Index 0 is the complete comment text, index 1 the first group in (), etc.
Ignored when selecting a statically known value instead of a parser.
The issue kind(s) affected by the comment. If the issue kind is read from
the comment instead of being a fixed choice, use the following keywords
for the different issue kinds:
When selecting a custom parser, this is the Python function to call as parser.
You have to supply this function in a Python layer.
It should return an allowed value and it takes as arguments, in order:
1. The comment object
2. The text corresponding to the selected regex group
3. Optionally: issue details of the issue being affected (only needed if the
comment should behave differently for different issues)
Ignored when not selecting a custom parser.
macro.group : int = 0
Index of the regex group in the format which should be handed over to the given
parser in order to dynamically extract the value from the comment.
Index 0 is the complete comment text, index 1 the first group in (), etc.
Ignored when selecting a statically known value instead of a parser.
When selecting a custom parser, this is the Python function to call as parser.
You have to supply this function in a Python layer.
It should return an allowed value and it takes as arguments, in order:
1. The comment object
2. The text corresponding to the selected regex group
3. Optionally: issue details of the issue being affected (only needed if the
comment should behave differently for different issues)
Ignored when not selecting a custom parser.
message.group : int = 0
Index of the regex group in the format which should be handed over to the given
parser in order to dynamically extract the value from the comment.
Index 0 is the complete comment text, index 1 the first group in (), etc.
Ignored when selecting a statically known value instead of a parser.
Globbing pattern to restrict the affected issues by their message key.
For architecture violations, this field is compared against the
reflexion edge type.
When selecting a custom parser, this is the Python function to call as parser.
You have to supply this function in a Python layer.
It should return an allowed value and it takes as arguments, in order:
1. The comment object
2. The text corresponding to the selected regex group
3. Optionally: issue details of the issue being affected (only needed if the
comment should behave differently for different issues)
Ignored when not selecting a custom parser.
message_key.group : int = 0
Index of the regex group in the format which should be handed over to the given
parser in order to dynamically extract the value from the comment.
Index 0 is the complete comment text, index 1 the first group in (), etc.
Ignored when selecting a statically known value instead of a parser.
When selecting a custom parser, this is the Python function to call as parser.
You have to supply this function in a Python layer.
It should return an allowed value and it takes as arguments, in order:
1. The comment object
2. The text corresponding to the selected regex group
3. Optionally: issue details of the issue being affected (only needed if the
comment should behave differently for different issues)
Ignored when not selecting a custom parser.
rule.group : int = 1
Index of the regex group in the format which should be handed over to the given
parser in order to dynamically extract the value from the comment.
Index 0 is the complete comment text, index 1 the first group in (), etc.
Ignored when selecting a statically known value instead of a parser.
When selecting a custom parser, this is the Python function to call as parser.
You have to supply this function in a Python layer.
It should return an allowed value and it takes as arguments, in order:
1. The comment object
2. The text corresponding to the selected regex group
3. Optionally: issue details of the issue being affected (only needed if the
comment should behave differently for different issues)
Ignored when not selecting a custom parser.
scope.group : int = 0
Index of the regex group in the format which should be handed over to the given
parser in order to dynamically extract the value from the comment.
Index 0 is the complete comment text, index 1 the first group in (), etc.
Ignored when selecting a statically known value instead of a parser.
Enumeration of possible code regions being addressed with a comment
REST_OF_FILE
Comment affects all issues in subsequent lines of the file until a
corresponding suppressing comment
SAME_LINE
Comment affects all issues in the same line
NEXT_LINE
Comment affects all issues in the next line
PREVIOUS_LINE
Comment affects all issues in the previous line
SAME_CONSTRUCT
Comment affects all issues inside the statement, lambda or declaration in which
the comment itself is placed (e.g., in same statement sequence)
NEXT_CONSTRUCT
Comment affects all issues in the next statement, lambda or declaration, whatever
comes earlier
NEXT_CONSTRUCT_OR_DIRECTIVE
Comment affects all issues in the next statement, lambda, declaration, #line
or #pragma, whatever comes earlier
NEXT_CODELINE
Comment affects all issues in the first line of the next statement, lambda,
declaration, expression, #line or #pragma, whatever comes earlier
PREVIOUS_CONSTRUCT
Comment affects all issues in the preceding statement, lambda or declaration
SAME_ROUTINE
Comment affects all issues in the routine inside which the comment is placed.
NEXT_ROUTINE
Comment affects all issues in the next routine after the comment
PREVIOUS_ROUTINE
Comment affects all issues in the previous routine before the comment
PROJECT
Comment affects the whole project (no scope restriction)
NEXT_N_LINES
Comment affects all issues in the next N lines, where N is parsed from the
comment (0 or empty string means "same line", negative means "previous N lines");
ATTENTION: if an omitted optional match group should mean "same line" then you
have to write it as (regex|) and not (regex)? so that
the match group matches the empty string and not None
ROUTINE_BY_NAME
The affected routine is named in the comment
MACRO_BY_NAME
Comment affects all issues in invocations of the given macros.
Globbing patterns are supported for the macro names.
FILE
Comment affects all issues in the same file as the comment.
CommentSameLine¶
Affects style violations on the same line
Code annotations are special comments that can be used to suppress issues and/or to assign a justification to an issue. This rule describes comments that can be used for such code annotations. Each code annotation rule specifies the syntax for such a comment (option format). The code annotation rule can limit the affected issues by, for example:- the code portion (scope) where an issue is
reported
- the issue kind(s) like style violations vs. metric
issues
- the rule which reports the issue,
- the message,
message key or entity
being reported in the issue
These options have a similar structure: First, you set theirgroupattribute to the regular expression group in the format string which defines the relevant portion of the comment for this field (group 0 is the complete comment, group 1 the first group in parens, etc.). Then choose asvalueattribute how the required information should be extracted from the selected comment portion, or provide that information directly. You can define your own comment format by copying the rule and changing options as required, e.g. to use your company's name instead ofAxivionin the comments.Assuming the default settings for this rule, a code annotation example comment using this rule would be:
/* AXIVION Comment Line MisraC2012-20.5: my justification */Possible Messages
This rule has no predefined messages.
Options¶
The following places define options that affect this rule: CodeAnnotations, Analysis-GlobalOptions
action¶
applies_to_c_comments¶
applies_to_c_comments : bool =
Whether /* .. */ comments should be checked.Trueapplies_to_cpp_comments¶
applies_to_cpp_comments : bool =
Whether // comments should be checked.Trueapplies_to_pragmas¶
applies_to_pragmas : bool =
Whether pragmas should be checked.Falsecase_sensitive¶
case_sensitive : bool =
Whether the fixed parts of the regex string should be matched case-sensitively.Falseentity¶
format¶
format : str =
A regular expression pattern describing the comment syntax handled by this format.'\s*AXIVION\s+Comment\s+Line\s+([^:]*)(:.*)?'justification¶
kind¶
macro¶
match_always¶
match_always : bool =
Whether the comment format is checked even if another format has already matched against the same comment.Truemessage¶
message_key¶
rule¶
scope¶
Option Types¶
These types are used by options listed above:
Action¶
Enumeration of possible actions to triggerNONE
Comment does not trigger any action.ACTIVATE
Activate the given rule(s) in the given scope.SUPPRESS
Suppress the given rule(s) in the given scope.COMMENT
Only add a justification to issues in the given scope.ENABLE_DISABLE_KEYWORD
ENABLE to activate, DISABLE to suppress the given rule(s) in the given scope.PLUS_MINUS_KEYWORD
+ to activate, - to suppress the given rule(s) in the given scope.BEGIN_END_SUPPRESS_KEYWORD
begin to activate, end to suppress the given rule(s) in the given scope.RHAPSODY_ENABLE_DISABLE_KEYWORD
[ to activate, ] to suppress the given rule(s) in the given scope.CUSTOM_PARSER
Entity¶
Selection of the parser to extract the affected entity from a commentENTITY_NAME
Entity directly given by nameENTITY_AS_GLOBBING
Makes entity* out of the given entityENTITY_REGEX
The given string for the entity is a regex to match against actual entitiesCUSTOM_PARSER
IssueKind¶
Enumeration of possible issue kinds to address with a commentSTYLE
Matches all stylecheck issues.METRIC
Matches all metric issues.ARCHITECTURE
Matches all architecture check issues.CLONE
Matches all clone detection issues.CYCLE
Matches all cycle detection issues.DEAD
Matches all dead code issues.ALL
Matches all issue kinds.ISSUE_KIND_KEYWORD
The issue kind is read from the comment where the following keywords can be used for the different issue kinds:CUSTOM_PARSER
Justification¶
Selection of the parser to extract the justification from a commentFULL_TEXT
The full text of the matched regex group is the justificationAFTER_COLON
Strip away a leading :script:`:` to extract the justificationCUSTOM_PARSER
Macro¶
Selection of the parser to extract the affected macro from a commentMACRO_NAME
Macro directly given by nameMACRO_AS_GLOBBING
Makes macro* out of the given macroMACRO_REGEX
The given string for the macro is a regex to match against actual entitiesCUSTOM_PARSER
Message¶
Selection of the parser to extract the affected messages from a commentFULL_TEXT
The full text of the matched regex group is the messageMESSAGE_AS_GLOBBING
Makes message* out of the given messageMESSAGE_REGEX
The given string for the message is a regex to match against actual messagesMESSAGES_SEPARATED_BY_SPACE
Space-separated list of messages given in the commentCUSTOM_PARSER
MessageKey¶
Selection of the parser to extract the affected message keys from a commentFULL_TEXT
The full text of the matched regex group is the message keyCUSTOM_PARSER
Rule¶
Selection of the parser to extract the affected rules from a commentAXIVION_NAME
Axivion full rule name given in the commentAXIVION_NAMES
Comma-separated list of Axivion rulenames given in the commentAXIVION_NAMES_SEPARATED_BY_SPACE
Space-separated list of Axivion rulenames given in the commentMISRA_C_2004_NUMBER
Only the number (like 10.1) is givenMISRA_C_2012_NUMBER
Only the number with optional R or D prefix (like 1.1, R1.1, or D1.1) is givenMISRA_C_2019_NUMBER
Only the number with optional R or D prefix (like 1.1, R1.1, or D1.1) is givenMISRA_C_2023_NUMBER
Only the number with optional R or D prefix (like 1.1, R1.1, or D1.1) is givenMISRA_C_2025_NUMBER
Only the number with optional R or D prefix (like 1.1, R1.1, or D1.1) is givenMISRA_CPP_2008_NUMBER
Only the number (like 10.1.1) is givenMISRA_CPP_2023_NUMBER
Only the number (like 10.1.1) is givenLINT_NUMBER
A single lint rule number (like 715) is givenLINT_NUMBERS
A comma-separated list of lint rule numbers is givenLINT_SAMELINE_NUMBERS
A space-separated list of lint rule numbers, each preceded by !ePRQA_NUMBER
A single PRQA rule number (like 1234) is givenPRQA_NUMBERS
A comma-separated list of PRQA rule numbers is givenPARASOFT_NAME
A single rule name in Parasoft name format is givenPOLYSPACE_NAME
A single rule name in Polyspace name format is givenCUSTOM_PARSER
Scope¶
Enumeration of possible code regions being addressed with a commentREST_OF_FILE
Comment affects all issues in subsequent lines of the file until a corresponding suppressing commentSAME_LINE
Comment affects all issues in the same lineNEXT_LINE
Comment affects all issues in the next linePREVIOUS_LINE
Comment affects all issues in the previous lineSAME_CONSTRUCT
Comment affects all issues inside the statement, lambda or declaration in which the comment itself is placed (e.g., in same statement sequence)NEXT_CONSTRUCT
Comment affects all issues in the next statement, lambda or declaration, whatever comes earlierNEXT_CONSTRUCT_OR_DIRECTIVE
Comment affects all issues in the next statement, lambda, declaration, #line or #pragma, whatever comes earlierNEXT_CODELINE
Comment affects all issues in the first line of the next statement, lambda, declaration, expression, #line or #pragma, whatever comes earlierPREVIOUS_CONSTRUCT
Comment affects all issues in the preceding statement, lambda or declarationSAME_ROUTINE
Comment affects all issues in the routine inside which the comment is placed.NEXT_ROUTINE
Comment affects all issues in the next routine after the commentPREVIOUS_ROUTINE
Comment affects all issues in the previous routine before the commentPROJECT
Comment affects the whole project (no scope restriction)NEXT_N_LINES
Comment affects all issues in the next N lines, where N is parsed from the comment (0 or empty string means "same line", negative means "previous N lines"); ATTENTION: if an omitted optional match group should mean "same line" then you have to write it as(regex|)and not(regex)?so that the match group matches the empty string and notNoneROUTINE_BY_NAME
The affected routine is named in the commentMACRO_BY_NAME
Comment affects all issues in invocations of the given macros. Globbing patterns are supported for the macro names.FILE
Comment affects all issues in the same file as the comment.CUSTOM_PARSER