forked from spot-toolbox/spotless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spot_run_checkcode.m
51 lines (47 loc) · 1.25 KB
/
spot_run_checkcode.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function map = spot_run_checkcode(path)
if nargin < 1,
path = fileparts(mfilename('fullpath'));
end
paths = vertcat({path},list_subdirectories(path));
result = containers.Map;
for j = 1:length(paths)
D = dir([paths{j} filesep '*.m']);
for f = 1:length(D)
fn = [paths{j} filesep D(f).name];
check = checkcode(fn);
if size(check, 1) > 0
result(fn) = check;
end
end
end
keys = result.keys;
for k = 1:length(keys)
print_report(keys{k}, result(keys{k}));
end
if nargout > 0,
map = result;
end
end
function [] = print_report(fn, r)
disp(repmat('<', 1, 60))
disp(fn)
for i = 1:length(r),
disp(sprintf('%5d: %s', r(i).line, r(i).message));
end
disp(repmat('>', 1, 60))
end
function paths = list_subdirectories(path)
D = dir(path);
names = {D.name};
isdir = {D.isdir};
paths = {};
for i = 1:length(names)
if names{i}(1) == '.',
continue;
elseif isdir{i},
sub_path = [path filesep names{i}];
paths{end+1,1} = sub_path;
paths = vertcat(paths, list_subdirectories(sub_path));
end
end
end