Skip to content

Commit 644adea

Browse files
authored
Merge pull request #1199 from bloomberg/unused_bs_is_an_error
fix #1142, add a flag -bs-no-error-unused-attribute for power users to turn it off
2 parents 781bc4c + fdb3bed commit 644adea

File tree

9 files changed

+59
-19
lines changed

9 files changed

+59
-19
lines changed

jscomp/bin/bsdep.ml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24867,7 +24867,7 @@ val no_builtin_ppx_ml : bool ref
2486724867
val no_builtin_ppx_mli : bool ref
2486824868
val no_warn_ffi_type : bool ref
2486924869
val no_warn_unused_bs_attribute : bool ref
24870-
24870+
val no_error_unused_bs_attribute : bool ref
2487124871
(** check-div-by-zero option *)
2487224872
val check_div_by_zero : bool ref
2487324873
val get_check_div_by_zero : unit -> bool
@@ -25109,7 +25109,7 @@ let no_warn_ffi_type = ref false
2510925109

2511025110
(** TODO: will flip the option when it is ready *)
2511125111
let no_warn_unused_bs_attribute = ref false
25112-
25112+
let no_error_unused_bs_attribute = ref false
2511325113

2511425114
let builtin_exceptions = "Caml_builtin_exceptions"
2511525115
let exceptions = "Caml_exceptions"
@@ -25276,8 +25276,14 @@ let prerr_warning loc x =
2527625276
print_string_warning loc (to_string x)
2527725277

2527825278
let warn_unused_attribute loc txt =
25279-
print_string_warning loc ( Literals.unused_attribute ^ txt ^ " \n" );
25280-
Format.pp_print_flush warning_formatter ()
25279+
if !Js_config.no_error_unused_bs_attribute then
25280+
begin
25281+
print_string_warning loc ( Literals.unused_attribute ^ txt ^ " \n" );
25282+
Format.pp_print_flush warning_formatter ()
25283+
end
25284+
else
25285+
Location.raise_errorf
25286+
~loc "%s%s \n" Literals.unused_attribute txt
2528125287

2528225288
end
2528325289
module Ast_attributes : sig

jscomp/bin/bsppx.ml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6660,7 +6660,7 @@ val no_builtin_ppx_ml : bool ref
66606660
val no_builtin_ppx_mli : bool ref
66616661
val no_warn_ffi_type : bool ref
66626662
val no_warn_unused_bs_attribute : bool ref
6663-
6663+
val no_error_unused_bs_attribute : bool ref
66646664
(** check-div-by-zero option *)
66656665
val check_div_by_zero : bool ref
66666666
val get_check_div_by_zero : unit -> bool
@@ -6902,7 +6902,7 @@ let no_warn_ffi_type = ref false
69026902

69036903
(** TODO: will flip the option when it is ready *)
69046904
let no_warn_unused_bs_attribute = ref false
6905-
6905+
let no_error_unused_bs_attribute = ref false
69066906

69076907
let builtin_exceptions = "Caml_builtin_exceptions"
69086908
let exceptions = "Caml_exceptions"
@@ -7069,8 +7069,14 @@ let prerr_warning loc x =
70697069
print_string_warning loc (to_string x)
70707070

70717071
let warn_unused_attribute loc txt =
7072-
print_string_warning loc ( Literals.unused_attribute ^ txt ^ " \n" );
7073-
Format.pp_print_flush warning_formatter ()
7072+
if !Js_config.no_error_unused_bs_attribute then
7073+
begin
7074+
print_string_warning loc ( Literals.unused_attribute ^ txt ^ " \n" );
7075+
Format.pp_print_flush warning_formatter ()
7076+
end
7077+
else
7078+
Location.raise_errorf
7079+
~loc "%s%s \n" Literals.unused_attribute txt
70747080

70757081
end
70767082
module Ast_attributes : sig

jscomp/bin/whole_compiler.ml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21999,7 +21999,7 @@ val no_builtin_ppx_ml : bool ref
2199921999
val no_builtin_ppx_mli : bool ref
2200022000
val no_warn_ffi_type : bool ref
2200122001
val no_warn_unused_bs_attribute : bool ref
22002-
22002+
val no_error_unused_bs_attribute : bool ref
2200322003
(** check-div-by-zero option *)
2200422004
val check_div_by_zero : bool ref
2200522005
val get_check_div_by_zero : unit -> bool
@@ -22241,7 +22241,7 @@ let no_warn_ffi_type = ref false
2224122241

2224222242
(** TODO: will flip the option when it is ready *)
2224322243
let no_warn_unused_bs_attribute = ref false
22244-
22244+
let no_error_unused_bs_attribute = ref false
2224522245

2224622246
let builtin_exceptions = "Caml_builtin_exceptions"
2224722247
let exceptions = "Caml_exceptions"
@@ -22388,7 +22388,7 @@ type error =
2238822388
| Bs_package_not_found of string
2238922389
| Bs_main_not_exist of string
2239022390
| Bs_invalid_path of string
22391-
22391+
(** TODO: we need add location handling *)
2239222392
exception Error of error
2239322393

2239422394
let error err = raise (Error err)
@@ -25932,8 +25932,14 @@ let prerr_warning loc x =
2593225932
print_string_warning loc (to_string x)
2593325933

2593425934
let warn_unused_attribute loc txt =
25935-
print_string_warning loc ( Literals.unused_attribute ^ txt ^ " \n" );
25936-
Format.pp_print_flush warning_formatter ()
25935+
if !Js_config.no_error_unused_bs_attribute then
25936+
begin
25937+
print_string_warning loc ( Literals.unused_attribute ^ txt ^ " \n" );
25938+
Format.pp_print_flush warning_formatter ()
25939+
end
25940+
else
25941+
Location.raise_errorf
25942+
~loc "%s%s \n" Literals.unused_attribute txt
2593725943

2593825944
end
2593925945
module Bs_ast_invariant
@@ -106320,6 +106326,14 @@ let buckle_script_flags =
106320106326
Arg.String set_eval_string,
106321106327
" (experimental) Set the string to be evaluated, note this flag will be conflicted with -bs-main"
106322106328
)
106329+
::("-bs-no-error-unused-attribute",
106330+
Arg.Set Js_config.no_error_unused_bs_attribute,
106331+
" No error when seeing unused attribute"
106332+
(* We introduce such flag mostly
106333+
for work around
106334+
in case some embarassing compiler bugs
106335+
*)
106336+
)
106323106337
::
106324106338
(
106325106339
"-bs-sort-imports",

jscomp/common/bs_warnings.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,11 @@ let prerr_warning loc x =
5757
print_string_warning loc (to_string x)
5858

5959
let warn_unused_attribute loc txt =
60-
print_string_warning loc ( Literals.unused_attribute ^ txt ^ " \n" );
61-
Format.pp_print_flush warning_formatter ()
60+
if !Js_config.no_error_unused_bs_attribute then
61+
begin
62+
print_string_warning loc ( Literals.unused_attribute ^ txt ^ " \n" );
63+
Format.pp_print_flush warning_formatter ()
64+
end
65+
else
66+
Location.raise_errorf
67+
~loc "%s%s \n" Literals.unused_attribute txt

jscomp/common/js_config.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ let no_warn_ffi_type = ref false
173173

174174
(** TODO: will flip the option when it is ready *)
175175
let no_warn_unused_bs_attribute = ref false
176-
176+
let no_error_unused_bs_attribute = ref false
177177

178178
let builtin_exceptions = "Caml_builtin_exceptions"
179179
let exceptions = "Caml_exceptions"

jscomp/common/js_config.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ val no_builtin_ppx_ml : bool ref
106106
val no_builtin_ppx_mli : bool ref
107107
val no_warn_ffi_type : bool ref
108108
val no_warn_unused_bs_attribute : bool ref
109-
109+
val no_error_unused_bs_attribute : bool ref
110110
(** check-div-by-zero option *)
111111
val check_div_by_zero : bool ref
112112
val get_check_div_by_zero : unit -> bool

jscomp/core/js_main.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ let buckle_script_flags =
151151
Arg.String set_eval_string,
152152
" (experimental) Set the string to be evaluated, note this flag will be conflicted with -bs-main"
153153
)
154+
::("-bs-no-error-unused-attribute",
155+
Arg.Set Js_config.no_error_unused_bs_attribute,
156+
" No error when seeing unused attribute"
157+
(* We introduce such flag mostly
158+
for work around
159+
in case some embarassing compiler bugs
160+
*)
161+
)
154162
::
155163
(
156164
"-bs-sort-imports",

jscomp/depends/bs_exception.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type error =
3232
| Bs_package_not_found of string
3333
| Bs_main_not_exist of string
3434
| Bs_invalid_path of string
35-
35+
(** TODO: we need add location handling *)
3636
exception Error of error
3737

3838
let error err = raise (Error err)

jscomp/test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ $(addsuffix .cmi, $(OTHERS)): ../runtime/js.cmi
102102
$(addsuffix .cmj, $(OTHERS)): ../runtime/js.cmj
103103

104104
COMPFLAGS+= $(MODULE_FLAGS) -w -40
105-
COMPFLAGS+= -bs-no-version-header -bs-diagnose -bs-cross-module-opt -bs-package-name bs-platform
105+
COMPFLAGS+= -bs-no-version-header -bs-no-error-unused-attribute -bs-diagnose -bs-cross-module-opt -bs-package-name bs-platform
106106

107107

108108
$(TESTS): $(CAMLC)

0 commit comments

Comments
 (0)