LegacyCommentNextConstruct

Affects style violations in the next construct (statement/declaration)

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 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 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

code_annotations.Action to trigger when a matching comment is found.
 

action.custom_parser

Type: typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str], typing.Any] | typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str, bauhaus.config.code_annotations.Issue], bauhaus.analysis.config.GlobPattern] | None

Default: None

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.
 

action.value

Type: Action

Default: 'COMMENT'

The action to trigger when such a comment is found
 

applies_to_c_comments

applies_to_c_comments : bool = True

Whether /* .. */ comments should be checked.
 

applies_to_cpp_comments

applies_to_cpp_comments : bool = True

Whether // comments should be checked.
 

applies_to_pragmas

applies_to_pragmas : bool = False

Whether pragmas should be checked.
 

case_sensitive

case_sensitive : bool = False

Whether the fixed parts of the regex string should be matched case-sensitively.
 

entity

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.
 

entity.custom_parser

Type: typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str], typing.Any] | typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str, bauhaus.config.code_annotations.Issue], bauhaus.analysis.config.GlobPattern] | None

Default: None

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.
 

entity.value

Type: None | Entity | bauhaus.analysis.config.GlobPattern

Default: None

These entities are affected by the comment
 

format

format : str = '\s*Axivion\s+Comment\s+([^:]*)(:.*)?'

A regular expression pattern describing the comment syntax handled by this format.
 

justification

Justification to add to affected issues.
 

justification.custom_parser

Type: typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str], typing.Any] | typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str, bauhaus.config.code_annotations.Issue], bauhaus.analysis.config.GlobPattern] | None

Default: None

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).
 

justification.value

Type: None | Justification | str

Default: 'AFTER_COLON'

This justification is attached to affected issues.
 

kind

Issue kinds addressed with this comment.
 

kind.custom_parser

Type: typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str], typing.Any] | typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str, bauhaus.config.code_annotations.Issue], bauhaus.analysis.config.GlobPattern] | None

Default: None

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.
 

kind.value

Type: IssueKind

Default: 'STYLE'

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:
  • 'Style' or 'Stylecheck' for stylecheck issues
  • 'Metric' or 'Metrics' for metric issues
  • 'Architecture' for architecture issues
  • 'Clone' or 'Clones' for clone issues
  • 'Cycle' or 'Cycles' for cycle issues
  • 'Dead' or 'DeadCode' for dead code issues
  • 'All' for all issue kinds
 

macro

Globbing pattern to restrict the affected issues by their reported macro context.
 

macro.custom_parser

Type: typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str], typing.Any] | typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str, bauhaus.config.code_annotations.Issue], bauhaus.analysis.config.GlobPattern] | None

Default: None

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.
 

macro.value

Type: None | Macro | bauhaus.analysis.config.GlobPattern

Default: None

These macros are affected by the comment.
 

match_always

match_always : bool = True

Whether the comment format is checked even if another format has already matched against the same comment.
 

message

Globbing pattern to restrict the affected issues by their message. For architecture violations, this field is compared against the causing edge type.
 

message.custom_parser

Type: typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str], typing.Any] | typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str, bauhaus.config.code_annotations.Issue], bauhaus.analysis.config.GlobPattern] | None

Default: None

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.
 

message.value

Type: None | Message | bauhaus.analysis.config.GlobPattern

Default: None

These messages are affected by the comment.
 

message_key

Globbing pattern to restrict the affected issues by their message key. For architecture violations, this field is compared against the reflexion edge type.
 

message_key.custom_parser

Type: typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str], typing.Any] | typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str, bauhaus.config.code_annotations.Issue], bauhaus.analysis.config.GlobPattern] | None

Default: None

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.
 

message_key.value

Type: None | MessageKey | bauhaus.analysis.config.GlobPattern

Default: None

These message keys are affected by the comment.
 

rule

Globbing pattern to restrict the affected issues by their rule name.
 

rule.custom_parser

Type: typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str], typing.Any] | typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str, bauhaus.config.code_annotations.Issue], bauhaus.analysis.config.GlobPattern] | None

Default: None

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.
 

rule.value

Type: None | Rule | bauhaus.analysis.config.GlobPattern

Default: 'AXIVION_NAMES'

These rules are affected by the comment
 

scope

Code regions addressed with this comment.
 

scope.custom_parser

Type: typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str], typing.Any] | typing.Callable[[bauhaus.ir.common.scanner.comments.CachedComment, str, bauhaus.config.code_annotations.Issue], bauhaus.analysis.config.GlobPattern] | None

Default: None

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.
 

scope.value

Type: Scope

Default: 'NEXT_CONSTRUCT'

The code regions affected by the comment
 

Option Types

These types are used by options listed above:

Action

Enumeration of possible actions to trigger
 

NONE

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 comment
 

ENTITY_NAME

Entity directly given by name

ENTITY_AS_GLOBBING

Makes entity* out of the given entity

ENTITY_REGEX

The given string for the entity is a regex to match against actual entities

CUSTOM_PARSER

IssueKind

Enumeration of possible issue kinds to address with a comment
 

STYLE

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:
  • 'Style' or 'Stylecheck' for stylecheck issues
  • 'Metric' or 'Metrics' for metric issues
  • 'Architecture' for architecture issues
  • 'Clone' or 'Clones' for clone issues
  • 'Cycle' or 'Cycles' for cycle issues
  • 'Dead' or 'DeadCode' for dead code issues
  • 'All' for all issue kinds

CUSTOM_PARSER

Justification

Selection of the parser to extract the justification from a comment
 

FULL_TEXT

The full text of the matched regex group is the justification

AFTER_COLON

Strip away a leading :script:`:` to extract the justification

CUSTOM_PARSER

Macro

Selection of the parser to extract the affected macro from a comment
 

MACRO_NAME

Macro directly given by name

MACRO_AS_GLOBBING

Makes macro* out of the given macro

MACRO_REGEX

The given string for the macro is a regex to match against actual entities

CUSTOM_PARSER

Message

Selection of the parser to extract the affected messages from a comment
 

FULL_TEXT

The full text of the matched regex group is the message

MESSAGE_AS_GLOBBING

Makes message* out of the given message

MESSAGE_REGEX

The given string for the message is a regex to match against actual messages

MESSAGES_SEPARATED_BY_SPACE

Space-separated list of messages given in the comment

CUSTOM_PARSER

MessageKey

Selection of the parser to extract the affected message keys from a comment
 

FULL_TEXT

The full text of the matched regex group is the message key

CUSTOM_PARSER

Rule

Selection of the parser to extract the affected rules from a comment
 

AXIVION_NAME

Axivion full rule name given in the comment

AXIVION_NAMES

Comma-separated list of Axivion rulenames given in the comment

AXIVION_NAMES_SEPARATED_BY_SPACE

Space-separated list of Axivion rulenames given in the comment

MISRA_C_2004_NUMBER

Only the number (like 10.1) is given

MISRA_C_2012_NUMBER

Only the number with optional R or D prefix (like 1.1, R1.1, or D1.1) is given

MISRA_C_2019_NUMBER

Only the number with optional R or D prefix (like 1.1, R1.1, or D1.1) is given

MISRA_C_2023_NUMBER

Only the number with optional R or D prefix (like 1.1, R1.1, or D1.1) is given

MISRA_C_2025_NUMBER

Only the number with optional R or D prefix (like 1.1, R1.1, or D1.1) is given

MISRA_CPP_2008_NUMBER

Only the number (like 10.1.1) is given

MISRA_CPP_2023_NUMBER

Only the number (like 10.1.1) is given

LINT_NUMBER

A single lint rule number (like 715) is given

LINT_NUMBERS

A comma-separated list of lint rule numbers is given

LINT_SAMELINE_NUMBERS

A space-separated list of lint rule numbers, each preceded by !e

PRQA_NUMBER

A single PRQA rule number (like 1234) is given

PRQA_NUMBERS

A comma-separated list of PRQA rule numbers is given

PARASOFT_NAME

A single rule name in Parasoft name format is given

POLYSPACE_NAME

A single rule name in Polyspace name format is given

CUSTOM_PARSER

Scope

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.

CUSTOM_PARSER