forked from facebookarchive/pfff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer_parse_errors.ml
107 lines (91 loc) · 3.05 KB
/
layer_parse_errors.ml
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(* Yoann Padioleau
*
* Copyright (C) 2010 Facebook
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
* license.txt for more details.
*)
open Common
open Statistics_parsing
(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)
(*****************************************************************************)
(* Types *)
(*****************************************************************************)
(* todo: do some generic red_green_and_heatmap helpers? so can factorize
* code with layer_coverage.ml
*)
(*****************************************************************************)
(* Helper *)
(*****************************************************************************)
(*****************************************************************************)
(* Main entry point *)
(*****************************************************************************)
let gen_red_green_layer ~root ~output stats =
let root = Common2.relative_to_absolute root in
let layer = { Layer_code.
title = "Parsing errors (red/green)";
description = "";
files = stats +> List.map (fun stat ->
let file =
stat.filename +> Common2.relative_to_absolute
+> Common.filename_without_leading_path root
in
file,
{ Layer_code.
micro_level = []; (* TODO use problematic_lines *)
macro_level = [
(if stat.bad > 0
then "bad"
else "ok"
), 1.
];
}
);
kinds = Layer_code.red_green_properties;
}
in
Layer_code.save_layer layer output
let gen_heatmap_layer ~root ~output stats =
let root = Common2.relative_to_absolute root in
let layer = { Layer_code.
title = "Parsing errors (heatmap)";
description = "lower is better";
files = stats +> List.map (fun stat ->
let file =
stat.filename +> Common2.relative_to_absolute
+> Common.filename_without_leading_path root
in
let covered = stat.correct in
let not_covered = stat.bad in
let percent =
try
Common2.pourcent_good_bad not_covered covered
with Division_by_zero -> 0
in
file,
{ Layer_code.
micro_level =
stat.problematic_lines +> List.map (fun (_strs, lineno) ->
lineno, "bad"
);
macro_level = [
(let percent_round = (percent / 10) * 10 in
spf "cover %d%%" percent_round
),
1.
];
}
);
kinds = Layer_code.heat_map_properties;
}
in
Layer_code.save_layer layer output