checkArgumentsBlockUsed
Checks whether an arguments
block is used for
input validation for the specified categories of functions among the
files selected for checking. The arguments
block introduced in MATLAB R2019b
is very useful for input argument validation and can also be used for
automatic casting. It provides a more readable and more performant
alternative to functions such as inputParser
,
narginchk
, nargin
and varargin
. If your code does not need to
support older MATLAB releases, you might want to enable this check. Its
parameters facilitate only checking publicly available functions for the
presence of an arguments
block. This check ignores functions that:
-
Have no input arguments.
-
Are local (subfunctions), including any functions in a script.
-
Are nested. These are not allowed to have
arguments
blocks anyway. -
Have all their inputs ignored (with the
~
-notation).
If a function only uses arguments
blocks with
the Output
attribute (introduced in MATLAB R2022b), the function is
reported as a violation.
Configurable parameters
-
OnlyPublicFunctions (boolean): Set this to
true
(default) to only check if public, visible functions and methods usearguments
blocks. In addition to the list above, enabling this parameter makes the check ignore:-
Functions in a private folder.
-
Methods with any access restriction.
-
Hidden methods.
If the function is a method in a separate file and its class information could not be obtained (usually because of an error in the classdef file or while initializing its property values), the function will be checked and reported if there is no
arguments
block. -
-
IgnoreSingleInputOrdinaryMethods (boolean): Set to
true
(default) to have this check ignore all ordinary (non-static) methods with a single input (one or more objects) that are not constructors. Adding anarguments
block for these types of methods is generally not needed, and this parameter helps to prevent reporting unnecessary violations. -
ExemptFolders (list): A list of folder-names whose files should be ignored by this check. This can be useful, for example, if you have a package folder that is not for public use. The folders of this parameter are checked for at the end of the path of a checked file. This means that specifying
test
as an exempt folder, makes this check ignoreC:\somefolder\test\myFile.m
, but it will still checkC:\test\somefolder\myFile.m
andC:\somefolder\foldertest\myFile.m
.Alternatively, you can provide multiple layers for one folder. By specifying
test\+internal
as an exempt folder, you ignoreC:\test\+internal\myFile.m
, but will still checkC:\otherFolder\+internal\myFile.m
andC:\test\myFile.m
. By default, the list is empty.
Exemption tag: %@ok<CARBU>