checkBlankLines
Checks the number blank lines that are permitted or required between and around code.
Configurable parameters
-
ItemTypes: List of item types the rule applies to. Options are:
- arguments:
argumentsblock. - case:
caseandotherwise. Since cases do not have an explicitendthe MinAfter and MaxAfter settings are ignored. - code: Any non-blank line that does not fall in any of the other categories.
- comment: Any line that only contains a comment.
- classdef:
classdefblock. - if:
ifblock. - enumeration:
enumerationblock. - events:
eventsblock. - for:
forblock. - function:
functionblock. When functions without explicitendare used, the MinAfter and MaxAfter settings are ignored. - methods:
methodsblock. - parfor:
parforblock. - properties:
propertiesblock. - spmd:
spmdblock. - switch:
switchblock. - try:
tryblock. - while:
whileblock.
- arguments:
-
Levels: Range of nesting levels the rule applies to, e.g.:
1 Infmatches nesting level 1 and above. The nesting level does not depend on indentation.function y = f(u) % 0 persistent x; % 1 <-- The rule applies to this line. if isempty(x) % 1 <-- The rule applies to this line. x = 0; % 2 <-- The rule applies to this line. end % 1 <-- The rule applies to this line. y = x; % 1 <-- The rule applies to this line. x = u; % 1 <-- The rule applies to this line. end % 0function y = f(u) % 0 persistent x; % 1 <-- The rule applies to this line. if isempty(x) % 1 <-- The rule applies to this line. x = 0; % 2 <-- The rule applies to this line. end % 1 <-- The rule applies to this line. y = x; % 1 <-- The rule applies to this line. x = u; % 1 <-- The rule applies to this line. end % 0 -
MinBefore: Minimum number of consecutive blank lines before the item. If one or more comments are directly above the item, the rule applies above these comments.
if isempty(x) % <-- The rule applies to this line. x = 0; end% Initialize when empty. <-- The rule applies to this line. % Default value: 0. if isempty(x) x = 0; end -
MaxBefore: Maximum number of consecutive blank lines before the item. If one or more comments are directly above the item, the rule applies above these comments (see MinBefore).
-
MinAfter: Minimum number of consecutive blank lines after the item.
-
MaxAfter: Maximum number of consecutive blank lines after the item.
-
FirstLastInBlock: How to treat the first and last non-blank line in a block. Options are:
- none: No blank lines before the first line or after the last line in the block are permitted.
- min: The number of blank lines before the first line in the block must be MinBefore and the number of blank lines after the last line in the block must be MinAfter.
- check min: The number of blank lines before the first line in the block must be greater than or equal to MinBefore and the number of blank lines after the last line in the block must be greater than or equal to MinAfter.
- check min/max: The first and last line in the block are treated the same as any other line.
- check max: The number of blank lines before the first line in the block must be less than or equal to MaxBefore and the number of blank lines after the last line in the block must be less than or equal to MaxAfter.
- max: The number of blank lines before the first line in the block must be MaxBefore and the number of blank lines after the last line in the block must be MaxAfter.
if x % <-- begin of block a = 1; % <-- first line in block b = 2; c = 3; % <-- last line in block end % <-- end of block if x % <-- begin of block % Initialize a, b and c. <-- first line in block a = 1; b = 2; c = 3; % <-- last line in block end % <-- end of block switch y % <-- begin of block case 1 % <-- begin of block & first line in block a = 1; % <-- first line in block b = 2; % <-- ignored (see ItemType) case 2 % <-- begin of block a = 2; % <-- first line in block b = 3; % <-- ignored (see ItemType) otherwise % <-- begin of block a = 3; % <-- first line in block b = 4; % <-- last line in block end % <-- end of block
Exemption tag: %@ok<BLALN>