Scilab code-checking criteria
Table of contents
SCIHOME/slint.xml
file.
In the same file, each criterion may be enabled (default) or disabled.
Starred (*) criteria are enabled by default.
Checking id
|
|
function
- valid name (00004)
Checks the name of functions:
- option: names may be tested against a given regexp pattern
- option: some minimal and maximal lengths of names may be defined.
- Illegal calls (00035)
Checks that function calls are allowed: the list of concerned functions is configurable. Default =
pause, abort, quit, exit
- deprecated (00022)
Looks for calls to deprecated functions.
- number of lines (00016)
Checks the number of lines inside a function body. Too many lines can decrease the readability. Default max lines number = 200.
- number of return() (00040)
Checks that the number of calls to
return
in a function is less than a maximum. Default = only 1.- arguments
- Unused input argument (00006)
Checks if a function's argument is useless or not. Useless arguments can decrease the readability.
- Unassigned output argument (00007)
Checks if output arguments are defined before returning.
- Space after separating commas (00029)
Checks that there is a space after each comma in the list of function arguments at call.
- Duplicate argins or/and duplicate argouts (00005)
Checks if a function's argument (in/out) have no duplicate.
function y=foo(a, b, c, a) // probably an error ... endfunction function [y, a]=foo(a, b, c) // not necessarily an error but could be one ... endfunction
- Order of named inputs (00037)
Checks that named arguments are called at the right place.
function foo(a, b, c) ... endfunction function faa(x, y, z) foo(x, b = 1, z) // not ok endfunction function fee(x, y, z) foo(x, b = 1, c = 2) // ok endfunction function fii(x, y, z) foo(x, c = 2, b = 1) // not ok endfunction
Operators, symbols, keywords
- Bad use of ':' operator (00024)
Checks that in an implicit list a:b one or both bounds a or b is not another implicit list.
- Deprecated @ (not) operator (00027)
Checks that the deprecated
@ (not)
operator is not used.~
must now be used.- no NOT NOT (00034)
Checks that no double negation is used. Such expressions shall be simplified.
- NOT EQUAL consistency (00041)
The 'not equal' operator can be written '~=', '@=' or '<>', so checks that only one is used.
- == instead of = (00019)
Checks if the equality operator is used in a single instruction.
function y=foo(x) y == x + 1; // probably a typo endfunction
- NaN comparisons (00018)
Most often, comparing a number with
%nan
isn't a good idea. Usingisnan
is better.- global keyword (00001)
Checks if the keyword
global
is present.function y=foo(x) global z endfunction
- Redefinition of reserved keywords (00002)
Checks if a variable redefines a Scilab's constant, built-in or macro.
Redefining a Scilab's variable could have undesirable side-effects, so it should be avoided.
function y=foo(x) y = x endfunction function y=bar(x) y = foo(x) endfunction function y=oof(x) // call oof(2) doesn't return 2 ! foo = rand(x, 1); y = bar(x) endfunction
- TODO (00017)
Checks if there are comments including the
TODO
mnemonic. Most often, TODO points to something that still must be achieved.
Code style
- Too long line (00015)
Checks the line length. Scilab code style recommends a 80-char maximal length. This is the default value for slint.
- One instruction per line (00009)
Checks if there is a single instruction on each line.
- Semicolon at end of line (00039)
Checks that lines end with a semicolon.
- Binary operators between spaces (00028)
Checks that each binary operator (
+ - * / > >= < <= = == ..
is surrounded by spaces.- Format of literal decimal numbers (00013)
Checks if in a literal decimal number the correct exponent character is "e" or "E" (instead of "d" or "D"). In addition, checking that the decimal separator is a dot (instead of a comma) can be enabled.
- Bracketed expressions (00033)
Checks that expressions are bracketed: that increases the code readability.
- Comments: minimal required ratio wrt code (00036)
Computes and checks the ratio between number of lines and number of comments is greater than the minimum required. Default ratio = 30%.
- McCabe complexity (00012)
Computes the simplified McCabe complexity of the code, and compares it to a reference.
Loops and blocks
- Empty block (00010)
Checks if there are some empty blocks.
- If or while tested conditions : max number of statements (00032)
Checks that the number of statements in the boolean condition is less than a maximum. Default = 5 max.
- Nesting depth of blocks (00031)
Checks that the nesting depth of blocks is less than a maximum (default 3).
- select (00023)
Checks
select
against various tests:- A default
else
case is expected. - When there is only one
case
,select
shall be replaced with a simplerif
statement. - Empty
case
orelse
blocks are detected. - The homogeneity of tested values is checked: all case values must have the same type.
- A default
- unreachable code after return or break (00021)
Checks for unreachable code after a
break
or areturn
instruction. Unreachable code decreases code readability.- Loop: max number of break or continue (00030)
Check that numbers of
break
orcontinue
in a loop are less than a maximum (default = only 1).
Miscellaneous
- Implicit list a:b without %nan nor %inf bounds (00024)
Checks that an implicit list a:b is specified without any a or b bound set to %nan or %inf.
- printf: number of data matches the format (00014)
In calls to
printf()
, checks when it's possible whether the number of%
formating directives matches the number of provided data. The data types matching is not tested.- save/load with variables names (00026)
Checks that calls to
load()
andsave()
use the names of variables instead of variables handles.- struct: fields and data match (00025)
Checks the
struct()
definition:- The numbers of fields names and values must match.
- option: field names may be tested against a given regexp pattern
- option: some minimal and maximal lengths of fields names may be defined.
- mopen/mclose pairs & mclose all (00011)
Checks when it's possible if the files opened with
mopen()
are closed withmclose()
. Checks as well ifmclose("all")
is not used: it may have some side-effects.- Returned error flag must be tested (00038)
Checks that the error flag returned by some functions is actually retrieved and tested. The list of such functions is configurable.
- Unassigned result. Useless operation (00020)
Checks if an operation without assignment is used in a single instruction.
function y=foo(x) x + 1; // probably useless endfunction
- Variable: valid name (00003)
Checks if a variable's name matches a regex pattern. [some names yield an error and stop code-checking, like "3wrongName"]
- Variable: missing usage or missing local definition (00003)
Looks for variables that are locally defined but unused. Such variables are useless and can decrease the code readability.
Looks for variables used without being locally defined. Values of such variables are silently heritated from the calling level. This may have side effects.
function y=foo(x) scilab = 123; y = bar(x); endfunction function y=bar(x) Scilab = 456; y = scilab + 1; // typo error endfunction
See also
- slint — Checks the Scilab code of given macros against a set of criteria
- debug — enters the Scilab debugger mode
- coverage — Instruments some macros to store runtime information on code coverage and execution time
- test_run — runs unit and non-regression tests of a Scilab or external module, or in a directory
History
Version | Description |
2023.1 | Criteria enabled by default now focus on actual errors. |
Report an issue | ||
<< Lint tool (SLint) | Lint tool (SLint) | slint >> |