CodeInspector Tutorial
The functions in the CodeInspector` context provide functionality for linting of WL code.
CodeInspect[code] | returns a list of problems found in code |
CodeInspectSummarize[code] | returns an inspection summary object |
Next we lint code in an example package. This tutorial assumes that the codetoolsexamples repo is next to the codeinspector repo in your setup.
Collatz[n_Integer] := Prepend[Collatz[(3 n + 1)/2], n] /; OddQ[n] && n > 0;
Implicit Times
CodeInspectImplicitTimes[code] | returns a list of implicit times in code |
CodeInspectImplicitTimesSummarize[code] | returns an inspection summary object |
Finding implicit times in WL code.
Report uses of implicit multiplication. This is a source of bugs but it is hard to automatically determine whether it is incorrect.
The linter has caught an accidental use of implicit multiplication. The equal sign is missing in the usage message assignment. The code should be this:
Collatz::usage = "Collatz[n] gives a list of the iterates in the 3n+1 problem,
starting from n. The conjecture is that this sequence always
terminates."