CodeInspector Tutorial
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 |
Needs["CodeInspector`"]str = "1+f[,2]";lints = CodeInspect[str]CodeInspectSummarize[str, lints]Next we lint code in an example package. This tutorial assumes that the codetoolsexamples repo is next to the codeinspector repo in your setup.
codetoolsExamplesDir = FileNameJoin[{ParentDirectory[NotebookDirectory[], 5], "codetoolsexamples"}];PrependTo[$Path, codetoolsExamplesDir];CodeInspect[File["Collatz`"]]CodeInspectSummarize[File["Collatz`"], %, ConfidenceLevel -> 0.]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.
Needs["CodeInspector`ImplicitTimes`"]times = CodeInspectImplicitTimes[File["Collatz`"]];CodeInspectImplicitTimesSummarize["Collatz`", times]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."