Incorrect expression line break (IncorrectLineBreak)¶
Type | Scope | Severity | Activated by default |
Minutes to fix |
Tags |
---|---|---|---|---|---|
Code smell |
BSL OS |
Info |
Yes |
2 |
standard badpractice |
Parameters¶
Name | Type | Description | Default value |
---|---|---|---|
checkFirstSymbol |
Boolean |
Check beginning of line for invalid characters |
true |
listOfIncorrectFirstSymbol |
String |
Vertical bar-separated characters that should not start the line (special characters must be escaped) |
\)|;|,\s*\S+|\); |
checkLastSymbol |
Boolean |
Check end of line for invalid characters |
true |
listOfIncorrectLastSymbol |
String |
Vertical bar-separated characters that must not end in the line (special characters must be escaped) |
ИЛИ|И|OR|AND|\+|-|/|%|\* |
Description¶
Long arithmetic expressions are carried as follows: one entry can contain more than one operand; when wrapping, operation characters are written at the beginning of the line (and not at the end of the previous line); operands on a new line are preceded by standard indentation, or they are aligned to the beginning of the first operand, regardless of the operation signs.
If necessary, parameters of procedures, functions and methods should be transferred as follows:
- parameters are either aligned to the beginning of the first parameter, or preceded by standard indentation;
- closing parenthesis and operator separator ";" are written on the same line as the last parameter;
- the formatting method that offers the auto-formatting function in the configurator is also acceptable
Complex logical conditions in If ... ElseIf ... EndIf should be carried as follows:
- The basis for the newline if the line length is limited to 120 characters;
- logical operators AND, OR are placed at the beginning of a line, and not at the end of the previous line;
- all conditions are preceded by the standard first indent, or they are aligned at the start of work without taking into account the logical operator (it is recommended to use spaces to align expressions relative to the first line).
Examples of configuring exclusions:
- If your design standard requires a closing brace and statement separator ";" were written after the line containing the last parameter, then you need to change the
listOfIncorrectFirstSymbol
parameter - instead of the substring
|\);
(at the end of the setting) you need to write the substring|\)\s*;\s*\S+
- final version
\)|;|,\s*\S+|\)s*;\s*\S+
- code example is listed in the examples section
Without the specified setting, the rule will issue notes on the closing bracket and the operator separator ";", located on a separate line
Examples¶
Incorrect:
AmountDocument = AmountWithoutDiscount +
AmountManualDiscounts +
AmountAutomaticDiscount;
Correct:
AmountDocument = AmountWithoutDiscount
+ AmountManualDiscounts
+ AmountAutomaticDiscount;
or
AmountDocument = AmountWithoutDiscount
+ AmountManualDiscounts
+ AmountAutomaticDiscount;
An example of a possible arrangement of parameters and a closing bracket with the operator separator ";"
Names = New ValueList;
Names.Add(Name,
Synonym);
An example of a possible location of the closing bracket with the operator separator ";" on a separate line:
- without changing the listOfIncorrectFirstSymbol
parameter (see above), the diagnostics will generate a issue for such expression wrapping.
Names = New ValueList;
Names.Add(
Name,
Synonym
);
Sources¶
- Standard: Wrap expressions (RU)
Snippets¶
Diagnostic ignorance in code¶
// BSLLS:IncorrectLineBreak-off
// BSLLS:IncorrectLineBreak-on
Parameter for config¶
"IncorrectLineBreak": {
"checkFirstSymbol": true,
"listOfIncorrectFirstSymbol": "\\)|;|,\\s*\\S+|\\);",
"checkLastSymbol": true,
"listOfIncorrectLastSymbol": "ИЛИ|И|OR|AND|\\+|-|/|%|\\*"
}