Skip to content

Commit cc42052

Browse files
authored
chore: camelCase to snake_case 🐍 (rescript-lang#6702)
* format files * manual: fix dune build * manual renames * dune fmt * update CHANGELOG.md * update CONTRIBUTING.md
1 parent 2f9c120 commit cc42052

File tree

173 files changed

+20223
-19593
lines changed

Some content is hidden

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

173 files changed

+20223
-19593
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
- Allow `@directive` on functions for emitting function level directive code (`let serverAction = @directive("'use server'") (~name) => {...}`). https://github.com/rescript-lang/rescript-compiler/pull/6756
1818

19+
#### :house: Internal
20+
21+
- Convert OCaml codebase to snake case style. https://github.com/rescript-lang/rescript-compiler/pull/6702
22+
1923
#### :boom: Breaking Change
2024

2125
- `lazy` syntax is no longer supported. If you're using it, use `Lazy` module or `React.lazy_` instead. https://github.com/rescript-lang/rescript-compiler/pull/6342

CONTRIBUTING.md

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ make test-syntax-roundtrip
9292
make artifacts
9393
```
9494

95+
## Coding Style
96+
97+
- OCaml Code: snake case format is used, e.g, `to_string`
98+
- ReScript Code: the camel case format is used, e.g `toString`
99+
95100
## Adding new Files to the Npm Package
96101

97102
To make sure that no files are added to or removed from the npm package inadvertently, an artifact list is kept at `packages/artifacts.txt`. During CI build, it is verified that only the files that are listed there are actually included in the npm package.

jscomp/bsc/rescript_compiler_main.ml

+17-17
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ let process_file sourcefile ?(kind ) ppf =
7272
let sourcefile = set_abs_input_name sourcefile in
7373
setup_compiler_printer `rescript;
7474
Js_implementation.implementation
75-
~parser:(Res_driver.parse_implementation ~ignoreParseErrors:!Clflags.ignore_parse_errors)
75+
~parser:(Res_driver.parse_implementation ~ignore_parse_errors:!Clflags.ignore_parse_errors)
7676
ppf sourcefile
7777
| Resi ->
7878
let sourcefile = set_abs_input_name sourcefile in
7979
setup_compiler_printer `rescript;
8080
Js_implementation.interface
81-
~parser:(Res_driver.parse_interface ~ignoreParseErrors:!Clflags.ignore_parse_errors)
81+
~parser:(Res_driver.parse_interface ~ignore_parse_errors:!Clflags.ignore_parse_errors)
8282
ppf sourcefile
8383
| Intf_ast
8484
->
@@ -113,32 +113,32 @@ let reprint_source_file sourcefile =
113113
let sourcefile = set_abs_input_name sourcefile in
114114
let res = match kind with
115115
| Res ->
116-
let parseResult =
117-
Res_driver.parsingEngine.parseImplementation ~forPrinter:true ~filename:sourcefile
116+
let parse_result =
117+
Res_driver.parsing_engine.parse_implementation ~for_printer:true ~filename:sourcefile
118118
in
119-
if parseResult.invalid then (
120-
Res_diagnostics.printReport parseResult.diagnostics parseResult.source;
119+
if parse_result.invalid then (
120+
Res_diagnostics.print_report parse_result.diagnostics parse_result.source;
121121
exit 1
122122
);
123123
Res_compmisc.init_path ();
124-
parseResult.parsetree
124+
parse_result.parsetree
125125
|> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Ml
126126
|> Ppx_entry.rewrite_implementation
127-
|> Res_printer.printImplementation ~width:100 ~comments:parseResult.comments
127+
|> Res_printer.print_implementation ~width:100 ~comments:parse_result.comments
128128
|> print_endline
129129
| Resi ->
130-
let parseResult =
131-
Res_driver.parsingEngine.parseInterface ~forPrinter:true ~filename:sourcefile
130+
let parse_result =
131+
Res_driver.parsing_engine.parse_interface ~for_printer:true ~filename:sourcefile
132132
in
133-
if parseResult.invalid then (
134-
Res_diagnostics.printReport parseResult.diagnostics parseResult.source;
133+
if parse_result.invalid then (
134+
Res_diagnostics.print_report parse_result.diagnostics parse_result.source;
135135
exit 1
136136
);
137137
Res_compmisc.init_path ();
138-
parseResult.parsetree
138+
parse_result.parsetree
139139
|> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Mli
140140
|> Ppx_entry.rewrite_signature
141-
|> Res_printer.printInterface ~width:100 ~comments:parseResult.comments
141+
|> Res_printer.print_interface ~width:100 ~comments:parse_result.comments
142142
|> print_endline
143143
| _
144144
->
@@ -198,7 +198,7 @@ let format_file input =
198198
| Ml | Mli -> `ml
199199
| Res | Resi -> `res
200200
| _ -> Bsc_args.bad_arg ("don't know what to do with " ^ input) in
201-
let formatted = Res_multi_printer.print ~ignoreParseErrors:!Clflags.ignore_parse_errors syntax ~input in
201+
let formatted = Res_multi_printer.print ~ignore_parse_errors:!Clflags.ignore_parse_errors syntax ~input in
202202
match !Clflags.output_name with
203203
| None ->
204204
output_string stdout formatted
@@ -293,11 +293,11 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
293293
"*internal* Set jsx version";
294294

295295
"-bs-jsx-module", string_call (fun i ->
296-
let isGeneric = match i |> String.lowercase_ascii with
296+
let is_generic = match i |> String.lowercase_ascii with
297297
| "react" -> false
298298
| _ -> true in
299299
Js_config.jsx_module := Js_config.jsx_module_of_string i;
300-
if isGeneric then (
300+
if is_generic then (
301301
Js_config.jsx_mode := Automatic;
302302
Js_config.jsx_version := Some Jsx_v4
303303
)),

jscomp/common/js_config.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
(** Browser is not set via command line only for internal use *)
2626

2727
type jsx_version = Jsx_v3 | Jsx_v4
28-
type jsx_module = React | Generic of {moduleName: string}
28+
type jsx_module = React | Generic of {module_name: string}
2929
type jsx_mode = Classic | Automatic
3030

3131
let no_version_header = ref false
@@ -63,7 +63,7 @@ let int_of_jsx_version = function
6363

6464
let string_of_jsx_module = function
6565
| React -> "react"
66-
| Generic {moduleName} -> moduleName
66+
| Generic {module_name} -> module_name
6767

6868
let string_of_jsx_mode = function
6969
| Classic -> "classic"
@@ -76,7 +76,7 @@ let jsx_version_of_int = function
7676

7777
let jsx_module_of_string = function
7878
| "react" -> React
79-
| moduleName -> Generic {moduleName}
79+
| module_name -> Generic {module_name}
8080

8181
let jsx_mode_of_string = function
8282
| "classic" -> Classic

jscomp/common/js_config.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525
type jsx_version = Jsx_v3 | Jsx_v4
26-
type jsx_module = React | Generic of {moduleName: string}
26+
type jsx_module = React | Generic of {module_name: string}
2727
type jsx_mode = Classic | Automatic
2828

2929
(* val get_packages_info :

jscomp/common/pattern_printer.ml

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ let mkpat desc = Ast_helper.Pat.mk desc
77
let untype typed =
88
let rec loop pat =
99
match pat.pat_desc with
10-
| Tpat_or (p1, { pat_desc = Tpat_or (p2, p3, rI) }, rO) ->
10+
| Tpat_or (p1, { pat_desc = Tpat_or (p2, p3, r_i) }, r_o) ->
1111
(* Turn A | (B | C) into (A | B) | C for pretty printing without parens *)
12-
let newInner = { pat with pat_desc = Tpat_or (p1, p2, rI) } in
13-
let newOuter = { pat with pat_desc = Tpat_or (newInner, p3, rO) } in
14-
loop newOuter
12+
let new_inner = { pat with pat_desc = Tpat_or (p1, p2, r_i) } in
13+
let new_outer = { pat with pat_desc = Tpat_or (new_inner, p3, r_o) } in
14+
loop new_outer
1515
| Tpat_or (pa, pb, _) -> mkpat (Ppat_or (loop pa, loop pb))
1616
| Tpat_any | Tpat_var _ -> mkpat Ppat_any
1717
| Tpat_constant c -> mkpat (Ppat_constant (Untypeast.constant c))
@@ -44,5 +44,5 @@ let untype typed =
4444

4545
let print_pattern typed =
4646
let pat = untype typed in
47-
let doc = Res_printer.printPattern pat Res_comments_table.empty in
48-
Res_doc.toString ~width:80 doc
47+
let doc = Res_printer.print_pattern pat Res_comments_table.empty in
48+
Res_doc.to_string ~width:80 doc

jscomp/core/bs_conditional_initial.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let setup_env () =
4949

5050
Rescript_cpp.replace_directive_bool "BS" true;
5151
Rescript_cpp.replace_directive_bool "JS" true;
52-
Printtyp.print_res_poly_identifier := Res_printer.polyVarIdentToString;
52+
Printtyp.print_res_poly_identifier := Res_printer.polyvar_ident_to_string;
5353
Rescript_cpp.replace_directive_string "BS_VERSION" Bs_version.version
5454
(*; Switch.cut := 100*) (* tweakable but not very useful *)
5555

jscomp/core/j.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ and expression_desc =
160160
*)
161161
| Number of number
162162
| Object of property_map
163-
| Undefined of {isUnit: bool}
163+
| Undefined of {is_unit: bool}
164164
| Null
165165
| Await of expression
166166

jscomp/core/js_cmj_format.ml

+21-21
Original file line numberDiff line numberDiff line change
@@ -104,57 +104,57 @@ let to_file name ~check_exists (v : t) =
104104
output_string oc s;
105105
close_out oc)
106106

107-
let keyComp (a : string) b = Map_string.compare_key a b.name
107+
let key_comp (a : string) b = Map_string.compare_key a b.name
108108

109109
let not_found key =
110110
{ name = key; arity = single_na; persistent_closed_lambda = None }
111111

112-
let get_result midVal =
113-
match midVal.persistent_closed_lambda with
112+
let get_result mid_val =
113+
match mid_val.persistent_closed_lambda with
114114
| Some
115115
(Lconst
116116
(Const_js_null | Const_js_undefined _ | Const_js_true | Const_js_false))
117117
| None ->
118-
midVal
118+
mid_val
119119
| Some _ ->
120-
if !Js_config.cross_module_inline then midVal
121-
else { midVal with persistent_closed_lambda = None }
120+
if !Js_config.cross_module_inline then mid_val
121+
else { mid_val with persistent_closed_lambda = None }
122122

123-
let rec binarySearchAux arr lo hi (key : string) =
123+
let rec binary_search_aux arr lo hi (key : string) =
124124
let mid = (lo + hi) / 2 in
125-
let midVal = Array.unsafe_get arr mid in
126-
let c = keyComp key midVal in
127-
if c = 0 then get_result midVal
125+
let mid_val = Array.unsafe_get arr mid in
126+
let c = key_comp key mid_val in
127+
if c = 0 then get_result mid_val
128128
else if c < 0 then
129129
(* a[lo] =< key < a[mid] <= a[hi] *)
130130
if hi = mid then
131-
let loVal = Array.unsafe_get arr lo in
132-
if loVal.name = key then get_result loVal else not_found key
133-
else binarySearchAux arr lo mid key
131+
let lo_val = Array.unsafe_get arr lo in
132+
if lo_val.name = key then get_result lo_val else not_found key
133+
else binary_search_aux arr lo mid key
134134
else if (* a[lo] =< a[mid] < key <= a[hi] *)
135135
lo = mid then
136-
let hiVal = Array.unsafe_get arr hi in
137-
if hiVal.name = key then get_result hiVal else not_found key
138-
else binarySearchAux arr mid hi key
136+
let hi_val = Array.unsafe_get arr hi in
137+
if hi_val.name = key then get_result hi_val else not_found key
138+
else binary_search_aux arr mid hi key
139139

140-
let binarySearch (sorted : keyed_cmj_values) (key : string) : keyed_cmj_value =
140+
let binary_search (sorted : keyed_cmj_values) (key : string) : keyed_cmj_value =
141141
let len = Array.length sorted in
142142
if len = 0 then not_found key
143143
else
144144
let lo = Array.unsafe_get sorted 0 in
145-
let c = keyComp key lo in
145+
let c = key_comp key lo in
146146
if c < 0 then not_found key
147147
else
148148
let hi = Array.unsafe_get sorted (len - 1) in
149-
let c2 = keyComp key hi in
150-
if c2 > 0 then not_found key else binarySearchAux sorted 0 (len - 1) key
149+
let c2 = key_comp key hi in
150+
if c2 > 0 then not_found key else binary_search_aux sorted 0 (len - 1) key
151151

152152
(* FIXME: better error message when ocamldep
153153
get self-cycle
154154
*)
155155
let query_by_name (cmj_table : t) name : keyed_cmj_value =
156156
let values = cmj_table.values in
157-
binarySearch values name
157+
binary_search values name
158158

159159
type path = string
160160

jscomp/core/js_dump.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
524524
params body env
525525
| _ ->
526526
let el = match el with
527-
| [e] when e.expression_desc = Undefined {isUnit = true} ->
527+
| [e] when e.expression_desc = Undefined {is_unit = true} ->
528528
(* omit passing undefined when the call is f() *)
529529
[]
530530
| _ ->
@@ -548,8 +548,8 @@ and expression_desc cxt ~(level : int) f x : cxt =
548548
P.string f L.null;
549549
comma_sp f;
550550
expression ~level:1 cxt f el))
551-
| Tagged_template (callExpr, stringArgs, valueArgs) ->
552-
let cxt = expression cxt ~level f callExpr in
551+
| Tagged_template (call_expr, string_args, value_args) ->
552+
let cxt = expression cxt ~level f call_expr in
553553
P.string f "`";
554554
let rec aux cxt xs ys = match xs, ys with
555555
| [], [] -> ()
@@ -563,14 +563,14 @@ and expression_desc cxt ~(level : int) f x : cxt =
563563
aux cxt x_rest y_rest
564564
| _ -> assert false
565565
in
566-
aux cxt stringArgs valueArgs;
566+
aux cxt string_args value_args;
567567
P.string f "`";
568568
cxt
569569
| String_index (a, b) ->
570570
P.group f 1 (fun _ ->
571571
let cxt = expression ~level:15 cxt f a in
572572
P.string f L.dot;
573-
P.string f L.codePointAt;
573+
P.string f L.code_point_at;
574574
(* FIXME: use code_point_at *)
575575
P.paren_group f 1 (fun _ -> expression ~level:0 cxt f b))
576576
| Str { delim; txt } ->

jscomp/core/js_dump_import_export.ml

+11-11
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module L = Js_dump_lit
2727

2828
let default_export = "default"
2929

30-
let esModule = ("__esModule", "true")
30+
let es_module = ("__esModule", "true")
3131
(* Exports printer *)
3232

3333
let rev_iter_inter lst f inter =
@@ -50,7 +50,7 @@ let exports cxt f (idents : Ident.t list) =
5050
( cxt,
5151
if id_name = default_export then
5252
(* TODO check how it will affect AMDJS*)
53-
esModule :: (default_export, str) :: acc
53+
es_module :: (default_export, str) :: acc
5454
else (s, str) :: acc ))
5555
in
5656
P.at_least_two_lines f;
@@ -124,23 +124,23 @@ let requires require_lit cxt f (modules : (Ident.t * string * bool) list) =
124124
P.newline f);
125125
outer_cxt
126126

127-
let dumpImportAttributes f (importAttributes : External_ffi_types.import_attributes option) =
128-
match importAttributes with
127+
let dump_import_attributes f (import_attributes : External_ffi_types.import_attributes option) =
128+
match import_attributes with
129129
| None -> ()
130-
| Some importAttributes ->
130+
| Some import_attributes ->
131131
P.space f;
132132
P.string f "with";
133133
P.space f;
134-
let total = Hashtbl.length importAttributes in
134+
let total = Hashtbl.length import_attributes in
135135
let idx = ref 1 in
136136
P.brace_group f 0 (
137137
fun _ ->
138-
importAttributes |> Hashtbl.iter(fun key value ->
138+
import_attributes |> Hashtbl.iter(fun key value ->
139139
Js_dump_string.pp_string f key;
140140
P.string f L.colon_space;
141141
Js_dump_string.pp_string f value;
142-
let shouldAddComma = !idx < total in
143-
if shouldAddComma then (
142+
let should_add_comma = !idx < total in
143+
if should_add_comma then (
144144
P.string f L.comma;
145145
P.space f
146146
);
@@ -166,7 +166,7 @@ let imports cxt f (modules : (Ident.t * string * bool * External_ffi_types.impor
166166
P.string f L.from;
167167
P.space f;
168168
Js_dump_string.pp_string f file;
169-
dumpImportAttributes f import_attributes)
169+
dump_import_attributes f import_attributes)
170170
else (
171171
P.string f L.star;
172172
P.space f;
@@ -178,7 +178,7 @@ let imports cxt f (modules : (Ident.t * string * bool * External_ffi_types.impor
178178
P.string f L.from;
179179
P.space f;
180180
Js_dump_string.pp_string f file;
181-
dumpImportAttributes f import_attributes);
181+
dump_import_attributes f import_attributes);
182182
P.string f L.semi;
183183
P.newline f);
184184
outer_cxt

jscomp/core/js_dump_lit.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let default = "default"
6666

6767
let length = "length"
6868

69-
let codePointAt = "codePointAt"
69+
let code_point_at = "codePointAt"
7070

7171
let new_ = "new"
7272

@@ -136,7 +136,7 @@ let undefined = "undefined"
136136

137137
let string_cap = "String"
138138

139-
let fromCharcode = "fromCharCode"
139+
let from_charcode = "fromCharCode"
140140

141141
let eq = "="
142142

0 commit comments

Comments
 (0)