How do I run static analysis on custom classes?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Subhajyoti
2024-8-29
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!