slint
Checks the Scilab code of given macros against a set of criteria
Calling Sequence
slint(files) slint(files, conf, print) slint(files, resFilename) slint(files, conf, resFilename) out = slint(files) out = slint(files, conf)
Arguments
- files
- matrix of strings: the
.sci
files or the directories to analyze..sce
or other types of input files are ignored. - conf
- a string: the name of the configuration file (by default it's
SCIHOME/slint.xml
). - resFilename
- a string: the path + name of the file of XML-formated results.
- a boolean: if true the result is printed else the result is a struct.
- out
- a struct (if print is false).
Description
slint has been written to check the "quality" of the Scilab's code according to configurable rules.
Scripts that list Scilab instructions out of any function can be analyzed,
provided that their files have the .sci
extension.
The Scilab code to be analyzed must show no error at compilation time. |
slint(files) analyzes given files, and prints results in the console.
slint(files, resFilename) silently records
results in the given resFilename
.
slint(files, conf, resFilename) analyzes given files
according to the custom conf
configuration file, and silently records
results in the given resFilename
.
out = slint(files, conf, %f) analyzes given files
according to the custom conf
configuration file, and silently records
results as a structure in out
.
out = slint(files, conf, %t) does the same, but additionally prints results in the console.
Examples
editor SCIHOME/slint.xml // Main configuration file for criteria editor SCI/modules/slint/tests/unit_tests/files/slint_sample.sci; slint SCI/modules/slint/tests/unit_tests/files/slint_sample.sci;
// File slint_sample.sci: function [a, r]=slint_sample(a, b, a) global param // 1: global keyword sin(abc) // 3: uninitialized abc not in this scope may have side effects // 3wrongname = 3 // invalid variable name => parse error => stops code-checking // 5: Duplicated function arguments: a. (reported after line #1) // 5: Function arguments used as output values: a. (reported after line #1) // 5: A function argument must be preceeded by a single space (a,b, a)(reported after line #1) // 7: function returned value might be unused: r (reported after line #1) a = 1; b = 2; // 9: Two instructions on the same line select a case "a" // 10: empty block case "b" b = 2; else b = 1; end mclose("all"); // 11: The instruction mclose("all") may have any side effects. // 12: McCabe code complexity a = 1d3 // 13: Bad decimal exponent: "e" or "E" instead of "d" or "D" printf("%s %3.2f %d", 3, "abc") // 14: too few data wrt expected ones printf("%s %3.2f %d", 3, "abc", %pi, %t) // 14: too many data wrt expected ones // 15: Maximum line length exceeded at lines #, #, .. (reported after line #1) // TODO: check codechecker codes // 17: TODO exists a > %nan // 18: Comparison with NaN b == (a + 1) // 19: == instead of = b - 2 // 20: Possible useless operation: Unassigned result for i = 1:3 break b = 3 // 21: Unreachable code => !undetected: BUG return c = 3 // 21: Unreachable code => OK end xpause(1000) // 22: deprecated function select a // 23: Missing else case case "a" b = 1; case 3 b = %pi; end select a // 23: Select with only one case: could be replaced with an if statement. case "a" b = 2; else b = 1; end a = 1:%inf; // 24: Invalid list, it contains NaN or Inf. b = %nan:10; // 24: Invalid list, it contains NaN or Inf. c = 3:(2:5); // 24: Bad use of ':' operator. s = struct("r", %pi, "p") // 25: missing value in a struct definition s = struct("r", %pi, %e) // 25: missing field name in a struct definition save(TMPDIR + "/test.tmp", a) // 26: variable's name expected instead of variable's handle b = @a // 27: deprecated @ not operator a = b+2 // 28: Binary operator should be surrounded by single spaces a = linspace(1,3,10); // 29: A function argument must be preceded by a single space. if a == 3 then if b == 4 if c == 5 if d == 6 // 31: Too many nested blocks: 3 max. a = 1; end end end end if a | b | c | d | e | f // 32: Number of expressions in condition is limited: 5 max. e = %eps; end c = a & b == d; // 33: Expression is not bracketed. c = ~~b // 34: double negation disp("Hello") // 35: Illegal call // 36: minimal ratio lines of comments/code. Here all is OK slint_sample(b = 10, 3); // 37: Argument b declared at position 2 and assigned at position 1. a = mopen("abcd.txt"); // 38: Function mopen requires an error checking just after the call. a = %f // 39: ';' expected at end of line endfunction
See also
- Checking codes and 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
- edit — edição de funções
History
Versão | Descrição |
6.0 | slint introduced |
Report an issue | ||
<< Scilab code-checking criteria | Lint tool (SLint) | Web Tools >> |