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 equals the list of 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 example x(:, 1) or y{:} will not result in a violation, but 1:10 will.

    • 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 ``*`` 2 will not be reported and 10-2 will.

  • SurroundNameValueEqualsSigns (boolean): Whether or not equals signs in name-value pairs when using the Name=value syntax should be surrounded by spaces (available since MATLAB R2021a). For example, when set to true, the following will be reported: plot(x, y, LineWidth=2) and when set to false, this will be reported as a violation: plot(x, y, LineWidth = 2). The default value is false. 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.

Exemption tag: %@ok<SURSP>