|
| 1 | +Matlab Code Analyzer |
| 2 | +================== |
| 3 | + |
| 4 | +MATLAB comes with the very important tool MLINT, which can check your code for common defects. Experience shows that these hints can be very helpful for cleaning up MATLAB code, and preventing simple errors. |
| 5 | + |
| 6 | +Crucially though, MLINT is not a style checker. That is where this program comes in: |
| 7 | + |
| 8 | +Say you have some code in `ugly_code.m`. You can analyze this code for problems using one simple command: |
| 9 | + |
| 10 | +```matlab |
| 11 | +check ugly_code.m |
| 12 | +``` |
| 13 | + |
| 14 | +This might produce a report like this: |
| 15 | + |
| 16 | +``` |
| 17 | +Code Analysis for ugly_code.m |
| 18 | +
|
| 19 | + Required files: ugly_code.m, ugly_toolbox.m |
| 20 | + Required toolboxes: MATLAB, Signal Processing Toolbox |
| 21 | +
|
| 22 | + Function ugly_code (Line 1, col 18): |
| 23 | +
|
| 24 | + Number of lines: 67 (high) |
| 25 | + Number of function arguments: 2 (good) |
| 26 | + Number of used variables: 5 (good) |
| 27 | + Max level of nesting: 3 (high) |
| 28 | + Code complexity: 6 (good) |
| 29 | +
|
| 30 | + Line 1, col 1: too few comments (2 comments for 67 lines of code) |
| 31 | + Line 1, col 10: return argument 'szOut' is very short (used 5 times across 38 lines) |
| 32 | + Line 1, col 18: function argument 'testInput' is not mentioned in the documentation |
| 33 | + Line 15, col 84: very long line |
| 34 | + Line 20, col 22: no spaces after operator ',' |
| 35 | + Line 27, col 1: incorrect indentation |
| 36 | + Line 27, col 1: variable 'szOut' is very short (used 5 times across 38 lines) |
| 37 | + Line 27, col 23: variable 'text' shadows a built-in |
| 38 | + Line 27, col 34: Eval should never be used |
| 39 | + Line 39, col 10: no spaces around operator '=' |
| 40 | +``` |
| 41 | + |
| 42 | +A report like this will be printed for every function in the file, for script-files, and for classes. The more serious of these comments will be highlighted in red, whereas less important ones will stay black. Every line number is clickable and opens directly in the editor. |
| 43 | + |
| 44 | +Additionally, this comes with a settings file `check_settings.m`, which can change the thresholds on all warnings, and even enable or disable whole categories of warnings entirely. |
0 commit comments