Skip to content

Commit f44fd74

Browse files
authored
[bsb] Improve & move some comments for the warning flags (#2718)
1 parent e55a071 commit f44fd74

File tree

2 files changed

+57
-60
lines changed

2 files changed

+57
-60
lines changed

jscomp/bsb/bsb_default.ml

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,11 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
(**
27-
- 6
28-
Label omitted in function application.
29-
- 7
30-
Method overridden.
31-
- 9
32-
Missing fields in a record pattern. (*Not always desired, in some cases need [@@@warning "+9"] *)
33-
- 27
34-
Innocuous unused variable: unused variable that is not bound with let nor as, and doesn’t start with an underscore (_) character.
35-
- 29
36-
Unescaped end-of-line in a string constant (non-portable code).
37-
- 32 .. 39 Unused blabla
38-
- 44
39-
Open statement shadows an already defined identifier.
40-
- 45
41-
Open statement shadows an already defined label or constructor.
42-
- 48
43-
Implicit elimination of optional arguments.
44-
https://caml.inria.fr/mantis/view.php?id=6352
45-
46-
*)
47-
let bsc_flags =
26+
(* for default warning flags, please see bsb_warning.ml *)
27+
let bsc_flags =
4828
[
4929
"-no-alias-deps";
50-
"-color"; "always"
30+
"-color"; "always"
5131
]
5232

5333

jscomp/bsb/bsb_warning.ml

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,76 +23,93 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
type warning_error =
27-
| Warn_error_false
26+
type warning_error =
27+
| Warn_error_false
2828
(* default [false] to make our changes non-intrusive *)
2929
| Warn_error_true
30-
| Warn_error_number of string
30+
| Warn_error_number of string
3131

3232
type t = {
3333
number : string option;
3434
error : warning_error
3535
}
3636

37+
(**
38+
See the meanings of the warning codes here: https://caml.inria.fr/pub/docs/manual-ocaml/comp.html#sec281
39+
40+
- 30 Two labels or constructors of the same name are defined in two mutually recursive types.
41+
- 40 Constructor or label name used out of scope.
42+
43+
- 6 Label omitted in function application.
44+
- 7 Method overridden.
45+
- 9 Missing fields in a record pattern. (*Not always desired, in some cases need [@@@warning "+9"] *)
46+
- 27 Innocuous unused variable: unused variable that is not bound with let nor as, and doesn’t start with an underscore (_) character.
47+
- 29 Unescaped end-of-line in a string constant (non-portable code).
48+
- 32 .. 39 Unused blabla
49+
- 44 Open statement shadows an already defined identifier.
50+
- 45 Open statement shadows an already defined label or constructor.
51+
- 48 Implicit elimination of optional arguments. https://caml.inria.fr/mantis/view.php?id=6352
52+
- 101 (bsb-specific) unsafe polymorphic comparison.
53+
*)
3754
let default_warning_flag = "-w -30-40+6+7+27+32..39+44+45+101"
3855

39-
let get_warning_flag x =
40-
default_warning_flag ^
41-
(match x with
56+
let get_warning_flag x =
57+
default_warning_flag ^
58+
(match x with
4259
| Some {number =None}
4360
| None -> Ext_string.empty
4461
| Some {number = Some x} -> Ext_string.trim x )
4562

4663

4764
let warn_error = " -warn-error A"
4865

49-
let warning_to_string not_dev
50-
warning : string =
51-
default_warning_flag ^
52-
(match warning.number with
53-
| None ->
66+
let warning_to_string not_dev
67+
warning : string =
68+
default_warning_flag ^
69+
(match warning.number with
70+
| None ->
5471
Ext_string.empty
55-
| Some x ->
72+
| Some x ->
5673
Ext_string.trim x) ^
57-
if not_dev then Ext_string.empty
74+
if not_dev then Ext_string.empty
5875
else
59-
match warning.error with
60-
| Warn_error_true ->
76+
match warning.error with
77+
| Warn_error_true ->
6178
warn_error
6279

63-
| Warn_error_number y ->
80+
| Warn_error_number y ->
6481
" -warn-error " ^ y
65-
| Warn_error_false ->
66-
Ext_string.empty
82+
| Warn_error_false ->
83+
Ext_string.empty
6784

6885

6986

70-
let from_map (m : Ext_json_types.t String_map.t) =
71-
let number_opt = String_map.find_opt Bsb_build_schemas.number m in
72-
let error_opt = String_map.find_opt Bsb_build_schemas.error m in
73-
match number_opt, error_opt with
87+
let from_map (m : Ext_json_types.t String_map.t) =
88+
let number_opt = String_map.find_opt Bsb_build_schemas.number m in
89+
let error_opt = String_map.find_opt Bsb_build_schemas.error m in
90+
match number_opt, error_opt with
7491
| None, None -> None
75-
| _, _ ->
76-
let error =
77-
match error_opt with
92+
| _, _ ->
93+
let error =
94+
match error_opt with
7895
| Some (True _) -> Warn_error_true
7996
| Some (False _) -> Warn_error_false
80-
| Some (Str {str ; })
81-
-> Warn_error_number str
97+
| Some (Str {str ; })
98+
-> Warn_error_number str
8299
| Some x -> Bsb_exception.config_error x "expect true/false or string"
83100
| None -> Warn_error_false
84-
(** To make it less intrusive : warning error has to be enabled*)
101+
(** To make it less intrusive : warning error has to be enabled*)
85102
in
86-
let number =
87-
match number_opt with
103+
let number =
104+
match number_opt with
88105
| Some (Str { str = number}) -> Some number
89-
| None -> None
90-
| Some x -> Bsb_exception.config_error x "expect a string"
91-
in
92-
Some {number; error }
106+
| None -> None
107+
| Some x -> Bsb_exception.config_error x "expect a string"
108+
in
109+
Some {number; error }
93110

94-
let opt_warning_to_string not_dev warning =
95-
match warning with
111+
let opt_warning_to_string not_dev warning =
112+
match warning with
96113
| None -> default_warning_flag
97-
| Some w -> warning_to_string not_dev w
114+
| Some w -> warning_to_string not_dev w
98115

0 commit comments

Comments
 (0)