OCLint¶
An oclint test analyzes the translation unit’s source code and enforces the predefined rules. Each translation unit requires its own set of rules. If the analyzed code violates at least one rule, the test is failed, and feedback on what rules have been violated is given. Otherwise, feedback that the oclint test has been passed successfully is given. The tool OCLint is used to perform the analysis for this test case.
In addition to the configuration options presented in Test definition file the following attributes are available:
suppress_line: allow/disallow comments to suppress the analysis of the commented line.
suppress_range: allow/disallow annotations to suppress the analysis.
disable_rules: use all rules except for the rules given in this array.
apply_rules: only use the rules given in this array.
Note
For the oclint analysis the NDEBUG
flag is always set during OCLint’s the integrated compilation step in order to disable the analysis of assert
statements.
Attribute details¶
Details on the additional configuration options for oclint tests are given in the following sections.
suppress_line
¶
This rule indicates whether students are allowed to suppress OCLint warnings using the //!OCLint
comment.
Possible values:
true
: the suppression of OCLint warnings using the//!OCLint
comment is allowed.false
(default): the suppression of OCLint warnings using the//!OCLint
comment is not allowed.
Example:
suppress_line: true
If suppression of warnings is allowed all warnings generated by a line of code can be suppressed as follows:
void a() {
int unusedLocalVariable; //!OCLint
}
See !OCLint Comment in the OCLint documentation for further details and examples.
suppress_range
¶
This rule indicates whether students are allowed to suppress OCLint rules using annotations.
Possible values:
true
: the suppression of OCLint rules using annotations is allowed.false
(default): the suppression of OCLint rules using annotations is not allowed.
Example:
suppress_range: true
If suppression of rules is allowed all rules in the annotated scope are suppressed as follows:
__attribute__((annotate("oclint:suppress")))
See Annotations in the OCLint documentation for further details and examples.
disable_rules
¶
Array indicating the OCLint rules that should not be applied to the analyzed translation unit.
Possible values:
All rules defined in the Rule Index of the OCLint documentation. The rules have to be written as given in the referenced rule index.
Example:
disable_rules:
- ShortVariableName
- UselessParentheses
apply_rules
¶
Array indicating the OCLint rules that be applied to the analyzed translation unit.
Possible values:
All rules defined in the Rule Index of the OCLint documentation. The rules have to be written as given in the referenced rule index.
Example:
apply_rules:
- GotoStatement
- EmptyElseBlock
- LongVariableName
- LongLine
Example code structure test definitions:¶
In this section, a few examples for oclint test definitions are given.
Example 1: select all applied rules by hand.
1version: "0.0"
2translation_unit: hello_world.c
3tests:
4 - type: oclint
5 name: Linter
6 apply_rules:
7 - GotoStatement
8 - EmptyElseBlock
9 - LongVariableName
10 - LongLine
Example 2: select all applied rules by hand and allow students to disable rules.
version: "0.0"
translation_unit: hello_world.c
tests:
- type: oclint
name: Linter
suppress_line: true
suppress_range: true
apply_rules:
- GotoStatement
- EmptyElseBlock
- LongVariableName
- LongLine
Example 3: disable selected rules and allow students to disable rules with line comments only.
version: "0.0"
translation_unit: hello_world.c
tests:
- type: oclint
name: Linter
suppress_line: true
disable_rules:
- BitwiseOperatorInConditional
- MissingBreakInSwitchStatement
- UselessParentheses
- HighCyclomaticComplexity
- HighNPathComplexity
- HighNcssMethod
- ShortVariableName
- EmptyIfStatement
- MissingDefaultStatement
- UselessParentheses