Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ Some tips:
- The first sentence or line should show the function call with a very short summary.
- Ideally, every function should have an `## Examples` section with **at least one** example. The examples are compiled to check that they are correct. Use `==` to generate tests from the examples.
- Always use `@deprecated` when applicable.
- Always use `@throw` when applicable.
- Always use `@throws` when applicable.
- Always provide a `See` section pointing to MDN for more information when available.

## Contribute to JSX `domProps`
Expand Down
4 changes: 2 additions & 2 deletions analysis/reanalyze/src/arnold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,10 @@ module Compile = struct
| _ ->
Stats.log_hygiene_named_arg_value ~label ~loc;
raise ArgError
[@@raises ArgError]
[@@throws ArgError]
in
function_arg ()
[@@raises ArgError]
[@@throws ArgError]
in
let function_args_opt =
try Some (function_definition.kind |> List.map get_function_arg)
Expand Down
12 changes: 2 additions & 10 deletions analysis/reanalyze/src/exception.ml
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,7 @@ let traverse_ast ~file ~values_builder ~checks_builder () =
in
let does_not_throw attributes =
attributes
|> Annotation.get_attribute_payload (function
| "doesNotRaise" | "doesnotraise" | "DoesNoRaise" | "doesNotraise"
| "doNotRaise" | "donotraise" | "DoNoRaise" | "doNotraise"
| "doesNotThrow" | "doesnotthrow" | "DoesNoThrow" | "doesNotthrow"
| "doNotThrow" | "donotthrow" | "DoNoThrow" | "doNotthrow" ->
true
| _ -> false)
|> Annotation.get_attribute_payload (fun s -> s = "doesNotThrow")
<> None
in
let expr ~(module_path : Module_path.t) (self : Tast_mapper.mapper)
Expand Down Expand Up @@ -425,9 +419,7 @@ let traverse_ast ~file ~values_builder ~checks_builder () =
in
let get_exceptions_from_annotations attributes =
let throws_annotation_payload =
attributes
|> Annotation.get_attribute_payload (fun s ->
s = "throws" || s = "throw" || s = "raises" || s = "raise")
attributes |> Annotation.get_attribute_payload (fun s -> s = "throws")
in
let rec get_exceptions payload =
match payload with
Expand Down
10 changes: 5 additions & 5 deletions analysis/reanalyze/src/log_.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let item x =
Format.fprintf Format.std_formatter " ";
Format.fprintf Format.std_formatter x

let missing_raise_info_to_text {Issue.missing_annotations; loc_full} =
let missing_throw_info_to_text {Issue.missing_annotations; loc_full} =
let missing_txt =
Format.asprintf "%a" (Exceptions.pp ~exn_table:None) missing_annotations
in
Expand All @@ -107,8 +107,8 @@ let missing_raise_info_to_text {Issue.missing_annotations; loc_full} =

let log_additional_info ~(description : Issue.description) =
match description with
| ExceptionAnalysisMissing missing_raise_info ->
missing_raise_info_to_text missing_raise_info
| ExceptionAnalysisMissing missing_throw_info ->
missing_throw_info_to_text missing_throw_info
| _ -> ""

let missing_throw_info_to_message
Expand All @@ -130,8 +130,8 @@ let description_to_message (description : Issue.description) =
| DeadWarning {path; message} ->
Format.asprintf "@{<info>%s@} %s" path message
| ExceptionAnalysis {message} -> message
| ExceptionAnalysisMissing missing_raise_info ->
missing_throw_info_to_message missing_raise_info
| ExceptionAnalysisMissing missing_throw_info ->
missing_throw_info_to_message missing_throw_info
| Termination {message} -> message

let description_to_name (description : Issue.description) =
Expand Down
4 changes: 2 additions & 2 deletions analysis/reanalyze/src/reanalyze.ml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ let parse_argv (argv : string array) : string option =
let version_and_exit () =
print_endline usage;
exit 0
[@@raises exit]
[@@throws exit]
in
let rec set_all cmt_root =
Run_config.all ();
Expand Down Expand Up @@ -478,7 +478,7 @@ let parse_argv (argv : string array) : string option =
let cli () =
let cmt_root = parse_argv Sys.argv in
run_analysis_and_report ~cmt_root
[@@raises exit]
[@@throws exit]

(* Re-export server module for external callers (e.g. tools/bin/main.ml).
This keeps the wrapped-library layering intact: Reanalyze depends on internal
Expand Down
23 changes: 0 additions & 23 deletions analysis/src/completion_decorators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ Alternatively, use the `@@deprecated` decorator to add a deprecation warning to

[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#expression-deprecated-decorator).|};
] );
( "doesNotRaise",
None,
[
{|The `@doesNotRaise` decorator is deprecated. Please use `@doesNotThrow` instead.

`@doesNotRaise` is uses to override the analysis and state that an expression does not throw any exceptions,
even though the analysis reports otherwise. This can happen for example in the case of array access where
the analysis does not perform range checks but takes a conservative stance that any access
could potentially throw.
[Read more and see examples in the documentation](https://github.com/rescript-association/reanalyze/blob/master/EXCEPTION.md).
> Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|};
] );
( "doesNotThrow",
None,
[
Expand Down Expand Up @@ -151,17 +139,6 @@ The `@new` decorator is used whenever you need to bind to a JavaScript class con

[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#obj-decorator).|};
] );
( "raises",
Some "raises(\"$0\")",
[
{|The `@raises` decorator is deprecated. Please use `@throws` instead.

`@raises` acknowledges that a function can throw exceptions that are not caught, and suppresses
a warning in that case. Callers of the functions are then subjected to the same rule.
Example `@raises(Exn)` or `@raises([E1, E2, E3])` for multiple exceptions.
[Read more and see examples in the documentation](https://github.com/rescript-association/reanalyze/blob/master/EXCEPTION.md).
> Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|};
] );
( "throws",
Some "throws(\"$0\")",
[
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/process_cmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ let rec for_structure_item ~(env : Shared_types.Env.t) ~(exported : Exported.t)
{mb_id; mb_attributes; mb_loc; mb_name = name; mb_expr = {mod_desc}}
when not
(String.length name.txt >= 6
&& (String.sub name.txt 0 6 = "local_") [@doesNotRaise])
&& (String.sub name.txt 0 6 = "local_") [@doesNotThrow])
(* %%private generates a dummy module called local_... *) ->
let item = for_module ~env mod_desc name.txt in
let declared =
Expand Down
1 change: 1 addition & 0 deletions changes/reanalyze-throws-only.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Reanalyze no longer honors `@raises`, `@raise`, `@throw`, `@doesNotRaise` or the other `@doesNotThrow` variants: write `@throws` and `@doesNotThrow` instead.
2 changes: 1 addition & 1 deletion compiler/ext/ext_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let string_of_int_as_char (i : int) : string =
| '\r' -> "\\r"
| '\b' -> "\\b"
| ' ' .. '~' as c ->
let s = (Bytes.create [@doesNotRaise]) 1 in
let s = (Bytes.create [@doesNotThrow]) 1 in
Bytes.unsafe_set s 0 c;
Bytes.unsafe_to_string s
| _ when Uchar.is_valid i -> Ext_utf8.encode_codepoint i
Expand Down
2 changes: 1 addition & 1 deletion compiler/gentype/emit_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ let rec read_cmt_files_recursively ~config ~env
|> create_export_type_map ~config ~from_cmt_read_recursively:true
~file:
(cmt_file |> Filename.basename
|> (Filename.chop_extension [@doesNotRaise]))
|> (Filename.chop_extension [@doesNotThrow]))
in
let cmt_to_export_type_map =
env.cmt_to_export_type_map
Expand Down
4 changes: 2 additions & 2 deletions compiler/gentype/generated_files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let read_lines (file : string) : string list =
done;
[]
with End_of_file ->
close_in chan [@doesNotRaise];
close_in chan [@doesNotThrow];
!lines |> List.rev
in
finished_lines
Expand All @@ -37,7 +37,7 @@ let read_file (file : string) : string = String.concat "\n" (read_lines file)
let write_file (file_path : string) (contents : string) =
let out_file = open_out file_path in
output_string out_file contents;
close_out out_file [@doesNotRaise]
close_out out_file [@doesNotThrow]

let write_file_if_required ~output_file ~file_contents =
if Sys.file_exists output_file then
Expand Down
8 changes: 4 additions & 4 deletions compiler/gentype/gentype_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type case = {label_js: label_js}

let is_js_safe_property_name name =
name = ""
|| (match name.[0] [@doesNotRaise] with
|| (match name.[0] [@doesNotThrow] with
| 'A' .. 'z' -> true
| _ -> false)
&& name
Expand All @@ -42,12 +42,12 @@ let is_number s =
let len = String.length s in
len > 0
&& (match len > 1 with
| true -> (s.[0] [@doesNotRaise]) > '0'
| true -> (s.[0] [@doesNotThrow]) > '0'
| false -> true)
&&
let res = ref true in
for i = 0 to len - 1 do
match s.[i] [@doesNotRaise] with
match s.[i] [@doesNotThrow] with
| '0' .. '9' -> ()
| _ -> res := false
done;
Expand Down Expand Up @@ -222,7 +222,7 @@ module Node_filename = struct

let concat dirname filename =
let is_dir_sep s i =
let c = (s.[i] [@doesNotRaise]) in
let c = (s.[i] [@doesNotThrow]) in
c = '/' || c = '\\' || c = ':'
in
let l = length dirname in
Expand Down
2 changes: 1 addition & 1 deletion compiler/gentype/gentype_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let read_input_cmt is_interface cmt_file =
in
if is_interface then
let cmt_file_impl =
(cmt_file |> (Filename.chop_extension [@doesNotRaise])) ^ ".cmt"
(cmt_file |> (Filename.chop_extension [@doesNotThrow])) ^ ".cmt"
in
let input_cmt_impl = read_cmt cmt_file_impl in
let has_gentype_annotations_impl =
Expand Down
2 changes: 1 addition & 1 deletion compiler/gentype/module_name.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let sanitize_id s =
| c -> c)
else s
in
if s <> "" && (s.[0] [@doesNotRaise]) >= 'A' && (s.[0] [@doesNotRaise]) <= 'z'
if s <> "" && (s.[0] [@doesNotThrow]) >= 'A' && (s.[0] [@doesNotThrow]) <= 'z'
then s
else "_" ^ s

Expand Down
18 changes: 9 additions & 9 deletions compiler/gentype/paths.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ open Gentype_common
let handle_namespace cmt =
let cut_after_dash s =
match String.index s '-' with
| n -> String.sub s 0 n [@doesNotRaise]
| n -> String.sub s 0 n [@doesNotThrow]
| exception Not_found -> s
in
let no_dir = Filename.basename cmt = cmt in
if no_dir then
cmt |> (Filename.chop_extension [@doesNotRaise]) |> cut_after_dash
cmt |> (Filename.chop_extension [@doesNotThrow]) |> cut_after_dash
else
let dir = cmt |> Filename.dirname in
let base =
cmt |> Filename.basename |> (Filename.chop_extension [@doesNotRaise])
cmt |> Filename.basename |> (Filename.chop_extension [@doesNotThrow])
|> cut_after_dash
in
Filename.concat dir base
Expand All @@ -21,10 +21,10 @@ let find_name_space cmt =
let keep_after_dash s =
match String.index s '-' with
| n ->
Some ((String.sub s (n + 1) [@doesNotRaise]) (String.length s - n - 1))
Some ((String.sub s (n + 1) [@doesNotThrow]) (String.length s - n - 1))
| exception Not_found -> None
in
cmt |> Filename.basename |> (Filename.chop_extension [@doesNotRaise])
cmt |> Filename.basename |> (Filename.chop_extension [@doesNotThrow])
|> keep_after_dash

let remove_path_prefix ~prefix path =
Expand All @@ -33,10 +33,10 @@ let remove_path_prefix ~prefix path =
let path_len = String.length path in
let is_prefix =
prefix_len <= path_len
&& (String.sub path 0 prefix_len [@doesNotRaise]) = normalized_prefix
&& (String.sub path 0 prefix_len [@doesNotThrow]) = normalized_prefix
in
if is_prefix then
String.sub path prefix_len (path_len - prefix_len) [@doesNotRaise]
String.sub path prefix_len (path_len - prefix_len) [@doesNotThrow]
else path

let append_suffix ~config source_path =
Expand Down Expand Up @@ -70,10 +70,10 @@ let get_cmt_file cmt =
Filename.concat dir_name (base_name |> String.uncapitalize_ascii)
in
let path_cmti =
(Filename.chop_extension path_cmt [@doesNotRaise]) ^ ".cmti"
(Filename.chop_extension path_cmt [@doesNotThrow]) ^ ".cmti"
in
let path_cmti_lower_case =
(Filename.chop_extension path_cmt_lower_case [@doesNotRaise]) ^ ".cmti"
(Filename.chop_extension path_cmt_lower_case [@doesNotThrow]) ^ ".cmti"
in
(* The compiler's spelling first: on a case-insensitive file system
the lowercase one exists too, and the build file store, which holds
Expand Down
2 changes: 1 addition & 1 deletion compiler/gentype/translate_type_declarations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
= (row_fields_variants.payloads |> List.length)
then
(List.combine variant.payloads row_fields_variants.payloads
[@doesNotRaise])
[@doesNotThrow])
|> List.map (fun (payload, (label, attributes, _)) ->
let case = create_polyvariant_case (label, attributes) in
{payload with case})
Expand Down
2 changes: 1 addition & 1 deletion compiler/gentype/translate_type_expr_from_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ and translateTypeExprFromTypes_ ~config ~type_vars_gen ~type_env
match type_env |> Type_env.lookup_module_type_signature ~path with
| Some (signature, type_env) ->
let type_equations_translation =
(List.combine ids types [@doesNotRaise])
(List.combine ids types [@doesNotThrow])
|> List.map (fun (x, t) ->
( x,
t |> translateTypeExprFromTypes_ ~config ~type_vars_gen ~type_env
Expand Down
2 changes: 1 addition & 1 deletion compiler/ml/ast_mapper_from0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ module T = struct
when lid.txt = Lident "function$" -> (
let decode_arity_string arity_s =
int_of_string
((String.sub [@doesNotRaise]) arity_s 9 (String.length arity_s - 9))
((String.sub [@doesNotThrow]) arity_s 9 (String.length arity_s - 9))
in
let arity_from_type (typ : Parsetree.core_type) =
match typ.ptyp_desc with
Expand Down
6 changes: 3 additions & 3 deletions compiler/syntax/cli/res_cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module Cli_arg_processor = struct
let len = String.length filename in
let process_interface =
is_interface
|| (len > 0 && (String.get [@doesNotRaise]) filename (len - 1) = 'i')
|| (len > 0 && (String.get [@doesNotThrow]) filename (len - 1) = 'i')
in
let source = lazy (Ext_io.load_file filename) in
let load_source () = Lazy.force source in
Expand Down Expand Up @@ -150,7 +150,7 @@ module Cli_arg_processor = struct
in
(print_engine parse_result.newline).print_implementation ~width
~filename ~comments:parse_result.comments parsetree
[@@raises exit]
[@@throws exit]
end

let () =
Expand All @@ -161,4 +161,4 @@ let () =
~target:!Res_clflags.print ~jsx_version:!Res_clflags.jsx_version
~jsx_module:!Res_clflags.jsx_module !Res_clflags.file
~test_ast_conversion:!Res_clflags.test_ast_conversion)
[@@raises exit]
[@@throws exit]
6 changes: 3 additions & 3 deletions compiler/syntax/src/jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let unit_expr ~loc =

let safe_type_from_value value_str =
let value_str = get_label value_str in
if value_str = "" || (value_str.[0] [@doesNotRaise]) <> '_' then value_str
if value_str = "" || (value_str.[0] [@doesNotThrow]) <> '_' then value_str
else "T" ^ value_str

let ref_type_var loc = Typ.var ~loc "ref"
Expand Down Expand Up @@ -107,7 +107,7 @@ let make_props_type_params_tvar named_type_list =
let strip_option core_type =
match core_type with
| {ptyp_desc = Ptyp_constr ({txt = Lident "option"}, core_types)} ->
List.nth_opt core_types 0 [@doesNotRaise]
List.nth_opt core_types 0 [@doesNotThrow]
| _ -> Some core_type

let strip_nullable core_type =
Expand All @@ -121,7 +121,7 @@ let strip_nullable core_type =
Ptyp_constr
({txt = Ldot (Ldot (Lident "Stdlib", "Nullable"), "t")}, core_types);
} ->
List.nth_opt core_types 0 [@doesNotRaise]
List.nth_opt core_types 0 [@doesNotThrow]
| _ -> Some core_type

(* Make type params of the props type *)
Expand Down
2 changes: 1 addition & 1 deletion compiler/syntax/src/res_comment.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ let trim_spaces s =
while !j >= !i && String.unsafe_get s !j = ' ' do
decr j
done;
if !j >= !i then (String.sub [@doesNotRaise]) s !i (!j - !i + 1) else "")
if !j >= !i then (String.sub [@doesNotThrow]) s !i (!j - !i + 1) else "")
else s
4 changes: 2 additions & 2 deletions compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ let make_infix_operator (p : Parser.t) token start_pos end_pos =
Ast_helper.Exp.ident ~loc operator

let negate_string s =
if String.length s > 0 && (s.[0] [@doesNotRaise]) = '-' then
(String.sub [@doesNotRaise]) s 1 (String.length s - 1)
if String.length s > 0 && (s.[0] [@doesNotThrow]) = '-' then
(String.sub [@doesNotThrow]) s 1 (String.length s - 1)
else "-" ^ s

let make_unary_expr start_pos token_end token operand =
Expand Down
2 changes: 1 addition & 1 deletion compiler/syntax/src/res_doc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ let to_string ?(newline = "\n") ~width doc =
else (
Mini_buffer.flush_newline buffer ~newline;
Mini_buffer.add_string buffer
(String.make ind ' ' [@doesNotRaise]);
(String.make ind ' ' [@doesNotThrow]);
process ~pos:ind [] rest)
| _docs ->
process ~pos:ind []
Expand Down
Loading
Loading