CodeInspector is a package for finding and reporting problems in Wolfram Language code. CodeInspector has a large collection of rules that can be used to inspect Wolfram Language source code files and can be customized to your preferences.
In a stand-alone kernel:
Needs["CodeInspector`"]
CodeInspectSummarize["If[a,b,b]"]
Out[2]= If[a,b,b]
line 1: If[a,b,b]
^ ^
DuplicateClauses Error Both branches are the same.
Static Analysis Tools in the Wolfram Language
"CodeParser and CodeInspector" on community.wolfram.com
Finding Bugs in the Wolfram Language from WTC 2019: Watch Video (youtube)
Finding Bugs in the Wolfram Language from WTC 2019: Watch Video (wolfram.com)
Finding Bugs in the Wolfram Language from WTC 2019: Download Presentation
CodeInspector depends on CodeParser paclet and CodeFormatter paclet.
CodeInspector and its dependencies are included in Mathematica 12.2 and above.
For older versions, install CodeInspector paclet and dependencies from the public paclet server:
PacletInstall["CodeParser"]
PacletInstall["CodeFormatter"]
PacletInstall["CodeInspector"]
Build and install the CodeInspector paclet locally
After CodeParser and CodeInspector are installed, CodeInspector can be used.
Return the list of all problems found in a string of code:
Needs["CodeInspector`"]
CodeInspect["If[a,b,b]"]
Out[2]= {DuplicateClauses Error Both branches are the same.}
Summarize the problems found in a source code file:
The input to CodeInspect
and CodeInspectSummarize
may be a string, a File
, or a list of bytes.
See this tutorial in the Wolfram System help browser:
- CodeInspector/tutorial/CodeInspectorTutorial
Make sure that the paclets can be found on your system:
Needs["CodeInspector`"]
and try a basic example:
CodeInspect["If[a, b, b]"]