How do I run static analysis on custom classes?
Mostra commenti meno recenti
Is there a mechanism in MATLAB to get it to run a static analysis/linter to ensure that my classes are being accessed correctly (no typos, undefined fields,...)? For example, say I have myclass.m:
classdef myclass
properties
prop (1,1) int16 {mustBePositive} = 1
end
methods
% ...
end
end
and script.m:
test = myclass;
test.prop = 2; % is fine
test.porp = 2; % error, 'prop' is misspelled
test.name = 'test'; % error, no property named 'name'
test.prop = 1.1; % error, 'prop' is an integer
test.prop = [1 2]; % error, 'prop' must have size (1,1)
The errors only show up once I run the code and not while I am editing. Is there a linter or something similar to what I get in C/C++ (in vscode for example) that can give me these errors without running everything? At the very least I'd like to be able to identify the first two issues (which are really the same issue) of trying to access a property that doesn't exist.
Risposte (1)
Subhajyoti
il 29 Ago 2024
0 voti
When you are typing in the MATLAB Editor, there are handy suggestions pop-up for objects, functions, variables, etc. by default. You can refer to the following link to know more about ‘Customize Code Suggestions and Completions’ in MATLAB:

Also, you can run MATLAB Code in Visual Studio Code (VS Code) with features such as syntax highlighting, code analysis, navigation support, and more using the ‘MATLAB’ extension.

You can refer to the following link to know more about ‘Run MATLAB in Visual Studio Code’:
Also, the following is a helpful resource you can refer to ‘Avoiding Repetitive Typing with Tab Completion’ in MATLAB:
I hope this helps.
1 Commento
Benjamin
il 29 Ago 2024
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!