Skip to content

Commit 25753ed

Browse files
authored
Merge pull request #4650 from rescript-lang/warn_as_error
make bsb the source of truth for error/warning reporting
2 parents 9e3fa93 + 3ce9538 commit 25753ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+414
-428
lines changed

jscomp/bsb/bsb_templates.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ let root = OCamlRes.Res.([
2121
\ \"suffix\": \".bs.js\",\n\
2222
\ \"bs-dependencies\": [\n\
2323
\ ],\n\
24-
\ \"warnings\": {\n\
25-
\ \"error\" : \"+101\"\n\
26-
\ },\n\
2724
\ \"refmt\": 3\n\
2825
}\n\
2926
") ;

jscomp/bsb/bsb_warning.ml

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

2525

26-
type warning_error =
27-
| Warn_error_false
28-
(* default [false] to make our changes non-intrusive *)
29-
| Warn_error_true
30-
| Warn_error_number of string
3126

3227
type t0 = {
33-
number : string option;
34-
error : warning_error
35-
}
28+
number : string option;
29+
} [@@ocaml.unboxed]
3630

3731
type nonrec t = t0 option
3832

@@ -70,27 +64,13 @@ let to_merlin_string x =
7064

7165
let from_map (m : Ext_json_types.t Map_string.t) =
7266
let number_opt = Map_string.find_opt m Bsb_build_schemas.number in
73-
let error_opt = Map_string.find_opt m Bsb_build_schemas.error in
74-
match number_opt, error_opt with
75-
| None, None -> None
76-
| _, _ ->
77-
let error =
78-
match error_opt with
79-
| Some (True _) -> Warn_error_true
80-
| Some (False _) -> Warn_error_false
81-
| Some (Str {str ; })
82-
-> Warn_error_number str
83-
| Some x -> Bsb_exception.config_error x "expect true/false or string"
84-
| None -> Warn_error_false
85-
(** To make it less intrusive : warning error has to be enabled*)
86-
in
87-
let number =
88-
match number_opt with
89-
| Some (Str { str = number}) -> Some number
90-
| None -> None
91-
| Some x -> Bsb_exception.config_error x "expect a string"
92-
in
93-
Some {number; error }
67+
let number =
68+
match number_opt with
69+
| Some (Str { str = number}) -> Some number
70+
| None -> None
71+
| Some x -> Bsb_exception.config_error x "expect a string"
72+
in
73+
Some {number }
9474

9575

9676
let to_bsb_string ~toplevel warning =
@@ -103,15 +83,6 @@ let to_bsb_string ~toplevel warning =
10383
Ext_string.empty
10484
| Some x ->
10585
prepare_warning_concat ~beg:true x
106-
) ^
107-
(
108-
match warning.error with
109-
| Warn_error_true ->
110-
" -warn-error A"
111-
| Warn_error_number y ->
112-
" -warn-error " ^ y
113-
| Warn_error_false ->
114-
Ext_string.empty
115-
)
86+
)
11687
else " -w a"
11788
(* TODO: this is the current default behavior *)

jscomp/bsb/templates/basic/bsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,5 @@
1212
"suffix": ".bs.js",
1313
"bs-dependencies": [
1414
],
15-
"warnings": {
16-
"error" : "+101"
17-
},
1815
"refmt": 3
1916
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
var p = require("child_process");
2+
const { assert } = require("console");
23

34
var o = p.spawnSync(`bsb`);
45

56
console.log(o.stderr + "");
67
console.log("-----");
78
console.log(o.stdout + "");
8-
if (o.error) {
9-
throw o.error;
10-
}
9+
assert(o.status === 0)

jscomp/build_tests/bucklescript-tea/src/tea_app.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ let programLoop update view subscriptions initModel initCmd = function
195195
(* We own the passed in node, clear it out TODO: Clear it out properly *)
196196
(* let () = Js.log ("Blah", Web.Node.firstChild parentNode, Js.Null.test (Web.Node.firstChild parentNode), false, true) in *)
197197
let clearPnode () = while (Js.Array.length (Web.Node.childNodes parentNode)) > 0 do
198-
match Js.Null.to_opt (Web.Node.firstChild parentNode) with
198+
match Js.Null.toOption (Web.Node.firstChild parentNode) with
199199
| None -> ()
200200
| Some firstChild -> let _removedChild = Web.Node.removeChild parentNode firstChild in ()
201201
done in
@@ -256,7 +256,7 @@ let program : ('flags, 'model, 'msg) program -> Web.Node.t Js.null_undefined ->
256256
fun {init; update; view; subscriptions; shutdown} pnode flags ->
257257
let () = Web.polyfills () in
258258
let initModel, initCmd = init flags in
259-
let opnode = Js.Null_undefined.to_opt pnode in
259+
let opnode = Js.Null_undefined.toOption pnode in
260260
let pumpInterface = programLoop update view subscriptions initModel initCmd opnode in
261261
programStateWrapper initModel pumpInterface shutdown
262262

@@ -286,7 +286,7 @@ let map func vnode =
286286
Vdom.map func vnode
287287

288288
(* let fullProgram program pnode flags =
289-
match Js.Null_undefined.to_opt pnode with
289+
match Js.Null_undefined.toOption pnode with
290290
| None -> Web.Document.body ()
291291
| Some parentNode -> parentNode *)
292292

@@ -346,7 +346,7 @@ let programLoop = function
346346
347347
let program {init; update; view} pnode flags =
348348
let initModel, initCmd = init flags in
349-
let opnode = Js.Null_undefined.to_opt pnode in
349+
let opnode = Js.Null_undefined.toOption pnode in
350350
let modelState = programStateWrapperInit initModel in
351351
let rec viewState msgHandler = programLoopInit msgHandler view initModel opnode
352352
and pump_unfixed msgHandler = programLoop viewState update view initModel msgHandler in
@@ -360,17 +360,17 @@ let program {init; update; view} pnode flags =
360360
initModel
361361
initCmds
362362
view
363-
(Js.Null_undefined.to_opt pnode) *)
363+
(Js.Null_undefined.toOption pnode) *)
364364

365365
(* {
366366
internal = (fun () -> Js.log "internal update");
367367
init = init;
368368
update = update;
369369
view = view;
370-
} (Js.Null_undefined.to_opt pnode) flags *)
370+
} (Js.Null_undefined.toOption pnode) flags *)
371371

372372

373-
(* match Js.Null_undefined.to_opt pnode with
373+
(* match Js.Null_undefined.toOption pnode with
374374
| None -> Web.Document.body ()
375375
| Some parentNode -> parentNode *)
376376

@@ -379,11 +379,11 @@ let program {init; update; view} pnode flags =
379379
| None -> Js.log 42
380380
| Some parentNode -> Js.log 84 *)
381381

382-
(* let beginnerProgram program pnode = match Js.Null_undefined.to_opt pnode with
382+
(* let beginnerProgram program pnode = match Js.Null_undefined.toOption pnode with
383383
| None -> Web.Document.body ()
384384
| Some node -> node *)
385385

386-
(* let beginnerPrograms pnode = match Js.Null_undefined.to_opt pnode with
386+
(* let beginnerPrograms pnode = match Js.Null_undefined.toOption pnode with
387387
| None -> Web.Document.body ()
388388
| Some node -> Web.Node.style node *)
389389

jscomp/build_tests/bucklescript-tea/src/tea_html.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ let onMsg eventName msg = onMsg eventName msg
170170
let onInputOpt ?(key="") msg =
171171
onCB "input" key
172172
(fun ev ->
173-
match Js.Undefined.to_opt ev##target with
173+
match Js.Undefined.toOption ev##target with
174174
| None -> None
175-
| Some target -> match Js.Undefined.to_opt target##value with
175+
| Some target -> match Js.Undefined.toOption target##value with
176176
| None -> None
177177
| Some value -> msg value
178178
)
@@ -182,9 +182,9 @@ let onInput ?(key="") msg = onInputOpt ~key:key (fun ev -> Some (msg ev))
182182
let onChangeOpt ?(key="") msg =
183183
onCB "change" key
184184
(fun ev ->
185-
match Js.Undefined.to_opt ev##target with
185+
match Js.Undefined.toOption ev##target with
186186
| None -> None
187-
| Some target -> match Js.Undefined.to_opt target##value with
187+
| Some target -> match Js.Undefined.toOption target##value with
188188
| None -> None
189189
| Some value -> msg value
190190
)
@@ -206,9 +206,9 @@ let onFocus msg =
206206
let onCheckOpt ?(key="") msg =
207207
onCB "change" key
208208
(fun ev ->
209-
match Js.Undefined.to_opt ev##target with
209+
match Js.Undefined.toOption ev##target with
210210
| None -> None
211-
| Some target -> match Js.Undefined.to_opt target##checked with
211+
| Some target -> match Js.Undefined.toOption target##checked with
212212
| None -> None
213213
| Some value -> msg value
214214
)

jscomp/build_tests/bucklescript-tea/src/tea_html_cmds.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
let focus id =
3-
Tea_cmd.call (fun _enqueue -> match Js.Null_undefined.to_opt (Web.Document.getElementById id) with
3+
Tea_cmd.call (fun _enqueue -> match Js.Null_undefined.toOption (Web.Document.getElementById id) with
44
| None -> Js.log ("Attempted to focus a non-existant element of: ", id)
55
| Some elem ->
66
(* let () = Js.log ("Focusing element", id, elem) in *)

jscomp/build_tests/bucklescript-tea/src/tea_http.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ let send resultToMessage (Request (request, maybeEvents)) =
153153
()
154154
)
155155

156-
external encodeURIComponent : string -> string = "" [@@bs.val]
156+
external encodeURIComponent : string -> string = "encodeURIComponent" [@@bs.val]
157157

158158
let encodeUri str =
159159
encodeURIComponent str
160160

161-
external decodeURIComponent : string -> string = "" [@@bs.val]
161+
external decodeURIComponent : string -> string = "decodeURIComponent" [@@bs.val]
162162

163163
let decodeUri str =
164164
try Some (decodeURIComponent str)

jscomp/build_tests/bucklescript-tea/src/tea_result.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

33
(* TODO: Remove this when Bucklescript is updated to OCaml 4.03 as it includes result *)
4-
type ('a, 'b) t (* result *) =
4+
type ('a, 'b) t (* result *) = ('a,'b) result =
55
| Ok of 'a
66
| Error of 'b
77

@@ -55,6 +55,6 @@ let rec error_of_any = function
5555
| Error e -> Some e
5656
| Ok _ -> error_of_any tl
5757

58-
let rec error_of_first fst = function
58+
let error_of_first fst = function
5959
| Error e -> Some e
6060
| Ok _ -> error fst

jscomp/build_tests/bucklescript-tea/src/tea_task.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ let testing () =
177177
let () = doTest (Ok 42) e0 in
178178
let e1 = fail "file not found" |> onError (fun _msg -> fail 42) in
179179
let () = doTest (Error 42) e1 in
180-
let n0 = sequence [ mapError string_of_int (fail 42); mapError string_of_float (fail 3.14) ] in
180+
let n0 = sequence [ mapError string_of_int (fail 42); mapError Js.Float.toString (fail 3.14) ] in
181181
let () = doTest (Error "42") n0 in
182-
let n1 = sequence [ mapError string_of_int (succeed 1); mapError string_of_float (fail 3.14)] in
182+
let n1 = sequence [ mapError string_of_int (succeed 1); mapError Js.Float.toString (fail 3.14)] in
183183
let () = doTest (Error "3.14") n1 in
184-
let n2 = sequence [ mapError string_of_int (succeed 1); mapError string_of_float (succeed 2)] in
184+
let n2 = sequence [ mapError string_of_int (succeed 1); mapError Js.Float.toString (succeed 2)] in
185185
let () = doTest (Ok [1;2]) n2 in
186186
let _c0 = perform (fun _ -> 42) (succeed 18) in
187187
(* (\* Should not compile *\) let _c1 = perform (fun _ -> 42) (fail 18) in *)

jscomp/build_tests/bucklescript-tea/src/tea_time.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type 'msg myCmd =
1313

1414
let every interval tagger =
1515
let open Vdom in
16-
let key = string_of_float interval in
16+
let key = Js.Float.toString interval in
1717
let enableCall callbacks =
1818
let id = (Web.Window.setInterval (fun () -> callbacks.enqueue (tagger (Web.Date.now ())) ) interval) in
1919
(* let () = Js.log ("Time.every", "enable", interval, tagger, callbacks) in *)

jscomp/build_tests/bucklescript-tea/src/web_json.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type nothingYet
55
external stringify : 't -> nothingYet Js.null -> int -> string = "JSON.stringify" [@@bs.val]
66

77
let string_of_json ?(indent=2) value =
8-
match Js.Undefined.to_opt value with
8+
match Js.Undefined.toOption value with
99
| None -> "undefined"
1010
| Some v ->
1111
try stringify v Js.Null.empty indent

jscomp/build_tests/bucklescript-tea/src/web_node.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ let setStyle n key value = setStyle n##style key value
5252

5353
let setStyleProperty n ?(priority=false) key value =
5454
let style = n##style in
55-
match Js.Undefined.to_opt style##setProperty with
55+
match Js.Undefined.toOption style##setProperty with
5656
| None -> setStyle n key value (* TODO: Change this to setAttribute sometime, maybe... *)
5757
| Some _valid -> style##setProperty__ key value (if priority then (Js.Null.return "important") else Js.Null.empty)
5858

jscomp/build_tests/bucklescript-tea/src/web_window_history.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@ type t = <
1111
> Js.t
1212

1313

14-
let length window = match Js.Undefined.to_opt window##history with
14+
let length window = match Js.Undefined.toOption window##history with
1515
| None -> -1
1616
| Some history -> history##length
1717

18-
let back window = match Js.Undefined.to_opt window##history with
18+
let back window = match Js.Undefined.toOption window##history with
1919
| None -> ()
2020
| Some history -> history##back
2121

22-
let forward window = match Js.Undefined.to_opt window##history with
22+
let forward window = match Js.Undefined.toOption window##history with
2323
| None -> ()
2424
| Some history -> history##forward
2525

26-
let go window to' = match Js.Undefined.to_opt window##history with
26+
let go window to' = match Js.Undefined.toOption window##history with
2727
| None -> ()
2828
| Some history -> history##go to'
2929

30-
let pushState window state title url = match Js.Undefined.to_opt window##history with
30+
let pushState window state title url = match Js.Undefined.toOption window##history with
3131
| None -> ()
3232
| Some history -> history##pushState state title url
3333

34-
let replaceState window state title url = match Js.Undefined.to_opt window##history with
34+
let replaceState window state title url = match Js.Undefined.toOption window##history with
3535
| None -> ()
3636
| Some history -> history##replaceState state title url
3737

38-
let state window = match Js.Undefined.to_opt window##history with
38+
let state window = match Js.Undefined.toOption window##history with
3939
| None -> Js.Undefined.empty
4040
| Some history -> history##state

jscomp/build_tests/bucklescript-tea/src/web_window_localstorage.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@ type t = <
99
setItem : string -> string -> unit [@bs.meth];
1010
> Js.t
1111

12-
let length window = match Js.Undefined.to_opt window##localStorage with
12+
let length window = match Js.Undefined.toOption window##localStorage with
1313
| None -> None
1414
| Some localStorage -> Some (localStorage##length)
1515

1616

17-
let clear window = match Js.Undefined.to_opt window##localStorage with
17+
let clear window = match Js.Undefined.toOption window##localStorage with
1818
| None -> None
1919
| Some localStorage -> Some (localStorage##clear ())
2020

2121

22-
let key window idx = match Js.Undefined.to_opt window##localStorage with
22+
let key window idx = match Js.Undefined.toOption window##localStorage with
2323
| None -> None
2424
| Some localStorage -> Some (localStorage##key idx)
2525

2626

27-
let getItem window key = match Js.Undefined.to_opt window##localStorage with
27+
let getItem window key = match Js.Undefined.toOption window##localStorage with
2828
| None -> None
2929
| Some localStorage ->
3030
try Some (localStorage##getItem key)
3131
with _ -> None
3232

3333

34-
let removeItem window key = match Js.Undefined.to_opt window##localStorage with
34+
let removeItem window key = match Js.Undefined.toOption window##localStorage with
3535
| None -> None
3636
| Some localStorage -> Some (localStorage##removeItem key)
3737

3838

39-
let setItem window key value = match Js.Undefined.to_opt window##localStorage with
39+
let setItem window key value = match Js.Undefined.toOption window##localStorage with
4040
| None -> None
4141
| Some localStorage -> Some (localStorage##setItem key value)

0 commit comments

Comments
 (0)