Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.0.0 - Русский


Scilab code-checking criteria

Checking codes and default parameters are defined in the SCIHOME/slint.xml file. In the same file, each criterion may be enabled (default) or disabled. Starred (*) criteria are enabled by default.

Checking id

00001 global keyword
00002 Redefinition of reserved keywords (*)
00003 Variable: valid name (*)
00003 Variable: missing usage or missing local definition (*)
00004 function: valid name (*)
00005 Duplicate argins or/and duplicate argouts
00006 Unused input arguments
00007 Unassigned output argument (*)
00009 One instruction per line
00010 Empty block
00011 mopen/mclose pairs & mclose all
00012 McCabe complexity
00013 Format of literal decimal numbers
00014 printf: number of data matches the format (*)
00015 Too long line
00016 function: max number of lines
00017 TODO exists
00018 NaN comparisons
00019 == instead of = (*)
00020 Unassigned result. Useless operation
00021 unreachable code after return or break
00022 Deprecated functions (*)
00023 select without else
00024 Implicit list a:b without %nan nor %inf bounds (*)
00024 Bad use of ':' operator (*)
00025 struct: fields and data match (*)
00026 save/load with variables names (*)
00027 Deprecated @ (not) operator (*)
00028 Binary operators between spaces
00029 Space after separating commas in argin list at function call
00030 Loop: max number of break or continue
00031 Nesting depth of blocks
00032 If or while tested conditions : max number of statements
00033 Bracketed expressions
00034 no NOT NOT
00035 function: illegal calls (*)
00036 Comments: minimal required ratio wrt code
00037 order of named inputs
00038 Returned error flag must be tested
00039 Semicolon at end of line
00040 function: max number of return()
00041 NOT EQUAL consistency

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. Using isnan 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 simpler if statement.
  • Empty case or else blocks are detected.
  • The homogeneity of tested values is checked: all case values must have the same type.

unreachable code after return or break (00021)

Checks for unreachable code after a break or a return instruction. Unreachable code decreases code readability.

Loop: max number of break or continue (00030)

Check that numbers of break or continue 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() and save() 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 with mclose(). Checks as well if mclose("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.

function foo(a, b, c)
   [fd, err] = mopen(...) // ok err is returned
   if err ... then // ok err is checked
      ...
   end
   ...
   mclose(fd);
endfunction

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 — Среда отладки в Scilab
  • 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

ВерсияОписание
2023.1 Criteria enabled by default now focus on actual errors.
Report an issue
<< Lint tool (SLint) Lint tool (SLint) slint >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 24 11:18:38 CEST 2024