checkSurrBySpaces
Checks if certain operators are surrounded by spaces. Surrounding for
example '=' by spaces makes the code more readable. This check
excludes strings and comments.
This check has an auto-fixer as well. Clicking the Fix all button in the report fixes all violations for this check, clicking the Fix all in this file button fixes all violations for this check for one file. The Fix on this line button applies the fix on one indivual line. For more information, see section Automatic fixes. In the HTML report at most one violation of the same type per line of code will be shown for this check.
Configurable parameters
-
Operators (list): List of operators that must be surrounded by spaces. Allowed values are:
=,:,^,.^,==,<=,>=,~=,>,<,&,&&,|,||,+,-,*,.``*,/,./and.\. By default, the value of this parameter is a subset of the allowed values.-
When you configure the check to look for
:, code will not be reported as a violation when it is used for indexing. For examplex(:, 1)ory{:}will not result in a violation, but1:10will. -
If you configure the check to look for
-, the check will only report violations if it is used as a subtraction, not to negate a value. So-5 ``*`` 2will not be reported and10-2will.
-
-
OperatorsNotSurrounded (list): List of operators that must not be surrounded by spaces. Allowed values are:
=,:,^,.^,==,<=,>=,~=,>,<,&,&&,|,||,+,-,*,.``*,/,./and.\. By default, the value of this parameter is empty. -
SurroundNameValueEqualsSigns (boolean): Whether or not equals signs in name-value pairs when using the
Name=valuesyntax should be surrounded by spaces (available since MATLAB R2021a). For example, when set totrue, the following will be reported:plot(x, y, LineWidth=2)and when set tofalse, this will be reported as a violation:plot(x, y, LineWidth = 2). The default value isfalse. The behaviour of this check regarding equals signs in name-value pairs is applied regardless of the value of the Operators parameter. When you are not using MATLAB R2021a or newer, this parameter is ignored. -
CheckUnaryOperators (boolean): When set to true, report unary operators that are followed by a space.
Exemption tag: %@ok<SURSP>