Skip to content

Commit

Permalink
Use snake case for module names
Browse files Browse the repository at this point in the history
Summary:
no-op

Use snake case for module names:
- Our style guide says to use Jane Street style for anything not otherwise covered in the style guide. Jane Street style is to snake it up: `Let_syntax`, `Monad_infix`.
- For consistency: in OCaml, a module is a file. Our file names are typically snake case, including for the files edited in this diff. By being consistent, we avoid switching conventions three times in the same compound name: `Typing_warning.CastNonPrimitive.cast_hint`
- Ease of refactoring: it's an implementation detail whether a module lives in another file or corresponds directly to a file. Moving a module to/from a file shouldn't require painful, manual, global renames.

mnemonic: no "camel" in "OCaml"

Reviewed By: vassilmladenov

Differential Revision: D65134093

fbshipit-source-id: 7455ef7b32a5a876e6bc2c5d9c948675244b9ab1
  • Loading branch information
mheiber authored and facebook-github-bot committed Oct 30, 2024
1 parent ad24356 commit c3054ad
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 107 deletions.
2 changes: 1 addition & 1 deletion hphp/hack/src/typing/tast_check/cast_non_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let handler ~as_lint =
( pos,
Typing_warning.Cast_non_primitive,
{
Typing_warning.CastNonPrimitive.cast_hint =
Typing_warning.Cast_non_primitive.cast_hint =
Env.print_hint env hint;
ty = Env.print_ty env ty;
} )
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/src/typing/tast_check/disjoint_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let add_warning env p name ty1 ty2 ~dynamic ~as_lint =
( p,
warning_kind,
{
Typing_warning.NonDisjointCheck.name = Utils.strip_ns name;
Typing_warning.Non_disjoint_check.name = Utils.strip_ns name;
dynamic;
ty1 = Env.print_ty env ty1;
ty2 = Env.print_ty env ty2;
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/src/typing/tast_check/duplicate_properties.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let add_warning
( pos,
warning_kind,
{
Typing_warning.DuplicateProperties.class_name;
Typing_warning.Duplicate_properties.class_name;
prop_name;
class_names;
initialized_with_constant;
Expand Down
8 changes: 4 additions & 4 deletions hphp/hack/src/typing/tast_check/equality_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let add_warning env ~as_lint pos kind ty1 ty2 =
Some None
else
None)
(pos, warning_kind, { Typing_warning.EqualityCheck.kind; ty1; ty2 })
(pos, warning_kind, { Typing_warning.Equality_check.kind; ty1; ty2 })

let error_if_inequatable env ty1 ty2 err =
let expand_tydef =
Expand Down Expand Up @@ -100,21 +100,21 @@ let ensure_valid_equality_check env ~as_lint p bop e1 e2 =
env
~as_lint
p
(Typing_warning.EqualityCheck.Equality (equal_bop bop Diff2)))
(Typing_warning.Equality_check.Equality (equal_bop bop Diff2)))

let ensure_valid_contains_check env ~as_lint p trv_val_ty val_ty =
error_if_inequatable
env
trv_val_ty
val_ty
(add_warning env ~as_lint p Typing_warning.EqualityCheck.Contains)
(add_warning env ~as_lint p Typing_warning.Equality_check.Contains)

let ensure_valid_contains_key_check env ~as_lint p trv_key_ty key_ty =
error_if_inequatable
env
trv_key_ty
key_ty
(add_warning env ~as_lint p Typing_warning.EqualityCheck.Contains_key)
(add_warning env ~as_lint p Typing_warning.Equality_check.Contains_key)

let handler ~as_lint =
object
Expand Down
10 changes: 5 additions & 5 deletions hphp/hack/src/typing/tast_check/is_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let trivial_check ~as_lint pos env lhs_ty rhs_ty ~always_kind ~never_kind =
( pos,
warning_kind,
{
Typing_warning.IsAsAlways.kind;
Typing_warning.Is_as_always.kind;
lhs_ty = print_ty lhs_ty;
rhs_ty = print_ty rhs_ty;
} )
Expand All @@ -101,8 +101,8 @@ let handler ~as_lint =
env
lhs_ty
hint_ty
~always_kind:Typing_warning.IsAsAlways.Is_is_always_true
~never_kind:Typing_warning.IsAsAlways.Is_is_always_false
~always_kind:Typing_warning.Is_as_always.Is_is_always_true
~never_kind:Typing_warning.Is_as_always.Is_is_always_false
| ( _,
p,
As
Expand All @@ -120,13 +120,13 @@ let handler ~as_lint =
lhs_ty
hint_ty
~always_kind:
(Typing_warning.IsAsAlways.As_always_succeeds
(Typing_warning.Is_as_always.As_always_succeeds
{
Typing_warning.can_be_captured =
Aast_utils.can_be_captured lhs_expr;
original_pos = p;
replacement_pos = lhs_pos;
})
~never_kind:Typing_warning.IsAsAlways.As_always_fails
~never_kind:Typing_warning.Is_as_always.As_always_fails
| _ -> ()
end
14 changes: 7 additions & 7 deletions hphp/hack/src/typing/tast_check/sketchy_null_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let sketchy_null_check env ~as_lint (ty, p, e) kind =
( p,
warning_kind,
{
Typing_warning.SketchyNullCheck.name;
Typing_warning.Sketchy_null_check.name;
kind;
ty = Tast_env.print_ty env ty;
} )
Expand All @@ -75,16 +75,16 @@ let handler ~as_lint =
env
~as_lint
e
Typing_warning.SketchyNullCheck.Coalesce
Typing_warning.Sketchy_null_check.Coalesce
| Unop (Unot, e)
| Binop { bop = Eqeq; lhs = (_, _, Null); rhs = e }
| Binop { bop = Eqeq; lhs = e; rhs = (_, _, Null) } ->
sketchy_null_check env ~as_lint e Typing_warning.SketchyNullCheck.Eq
sketchy_null_check env ~as_lint e Typing_warning.Sketchy_null_check.Eq
| Eif (e, Some _, _) ->
sketchy_null_check env ~as_lint e Typing_warning.SketchyNullCheck.Neq
sketchy_null_check env ~as_lint e Typing_warning.Sketchy_null_check.Neq
| Binop { bop = Ampamp | Barbar; lhs = e1; rhs = e2 } ->
sketchy_null_check env ~as_lint e1 Typing_warning.SketchyNullCheck.Neq;
sketchy_null_check env ~as_lint e2 Typing_warning.SketchyNullCheck.Neq
sketchy_null_check env ~as_lint e1 Typing_warning.Sketchy_null_check.Neq;
sketchy_null_check env ~as_lint e2 Typing_warning.Sketchy_null_check.Neq
| _ -> ()

method! at_stmt env x =
Expand All @@ -93,6 +93,6 @@ let handler ~as_lint =
| Do (_, e)
| While (e, _)
| For (_, Some e, _, _) ->
sketchy_null_check env ~as_lint e Typing_warning.SketchyNullCheck.Neq
sketchy_null_check env ~as_lint e Typing_warning.Sketchy_null_check.Neq
| _ -> ()
end
32 changes: 23 additions & 9 deletions hphp/hack/src/typing/tast_check/truthiness_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,41 @@ let add_warning env ~as_lint pos kind ty e not =
None)
( pos,
Typing_warning.Truthiness_test,
{ Typing_warning.TruthinessTest.kind; ty; expr = get_lvar_name e; not } )
{ Typing_warning.Truthiness_test.kind; ty; expr = get_lvar_name e; not }
)

let truthiness_test env ~as_lint (ty, p, e) ~not : unit =
let module TruthinessTest = Typing_warning.TruthinessTest in
let prim_to_string prim =
Env.print_error_ty env (MakeType.prim_type (get_reason ty) prim)
in
List.iter (Tast_utils.find_sketchy_types env ty) ~f:(function
| Tast_utils.String ->
let tystr = prim_to_string Aast_defs.Tstring in
add_warning env ~as_lint p TruthinessTest.(Sketchy String) tystr e not
add_warning
env
~as_lint
p
Typing_warning.Truthiness_test.(Sketchy String)
tystr
e
not
| Tast_utils.Arraykey ->
let tystr = prim_to_string Aast_defs.Tarraykey in
add_warning env ~as_lint p TruthinessTest.(Sketchy Arraykey) tystr e not
add_warning
env
~as_lint
p
Typing_warning.Truthiness_test.(Sketchy Arraykey)
tystr
e
not
| Tast_utils.Stringish ->
let tystr = Utils.strip_ns SN.Classes.cStringish in
add_warning
env
~as_lint
p
TruthinessTest.(Sketchy Stringish)
Typing_warning.Truthiness_test.(Sketchy Stringish)
tystr
e
not
Expand All @@ -63,7 +77,7 @@ let truthiness_test env ~as_lint (ty, p, e) ~not : unit =
env
~as_lint
p
TruthinessTest.(Sketchy Xhp_child)
Typing_warning.Truthiness_test.(Sketchy Xhp_child)
tystr
e
not
Expand All @@ -72,7 +86,7 @@ let truthiness_test env ~as_lint (ty, p, e) ~not : unit =
env
~as_lint
p
TruthinessTest.(Sketchy Traversable)
Typing_warning.Truthiness_test.(Sketchy Traversable)
tystr
e
not);
Expand All @@ -82,7 +96,7 @@ let truthiness_test env ~as_lint (ty, p, e) ~not : unit =
env
~as_lint
p
TruthinessTest.(Invalid { truthy = true })
Typing_warning.Truthiness_test.(Invalid { truthy = true })
(Env.print_ty env ty)
e
not
Expand All @@ -91,7 +105,7 @@ let truthiness_test env ~as_lint (ty, p, e) ~not : unit =
env
~as_lint
p
TruthinessTest.(Invalid { truthy = false })
Typing_warning.Truthiness_test.(Invalid { truthy = false })
(Env.print_ty env ty)
e
not
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/src/typing/typing_equality_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let trivial_comparison_error
( pos,
Typing_warning.Sketchy_equality,
{
Typing_warning.SketchyEquality.result;
Typing_warning.Sketchy_equality.result;
left;
right;
left_trail;
Expand Down
32 changes: 16 additions & 16 deletions hphp/hack/src/typing/typing_warning.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type quickfix = {
replacement_pos: Pos.t;
}

module IsAsAlways = struct
module Is_as_always = struct
type kind =
| Is_is_always_true
| Is_is_always_false
Expand All @@ -30,7 +30,7 @@ module IsAsAlways = struct
}
end

module SketchyNullCheck = struct
module Sketchy_null_check = struct
type kind =
| Coalesce
| Eq
Expand All @@ -43,7 +43,7 @@ module SketchyNullCheck = struct
}
end

module NonDisjointCheck = struct
module Non_disjoint_check = struct
type t = {
name: string;
ty1: string;
Expand All @@ -52,7 +52,7 @@ module NonDisjointCheck = struct
}
end

module SketchyEquality = struct
module Sketchy_equality = struct
type t = {
result: bool;
left: Pos_or_decl.t Message.t list Lazy.t;
Expand All @@ -62,14 +62,14 @@ module SketchyEquality = struct
}
end

module CastNonPrimitive = struct
module Cast_non_primitive = struct
type t = {
cast_hint: string;
ty: string;
}
end

module TruthinessTest = struct
module Truthiness_test = struct
type sketchy_kind =
| String
| Arraykey
Expand All @@ -89,7 +89,7 @@ module TruthinessTest = struct
}
end

module EqualityCheck = struct
module Equality_check = struct
type kind =
| Equality of bool
| Contains
Expand All @@ -102,7 +102,7 @@ module EqualityCheck = struct
}
end

module DuplicateProperties = struct
module Duplicate_properties = struct
type t = {
class_name: string;
prop_name: string;
Expand All @@ -112,13 +112,13 @@ module DuplicateProperties = struct
end

type (_, _) kind =
| Sketchy_equality : (SketchyEquality.t, warn) kind
| Is_as_always : (IsAsAlways.t, migrated) kind
| Sketchy_null_check : (SketchyNullCheck.t, migrated) kind
| Non_disjoint_check : (NonDisjointCheck.t, migrated) kind
| Cast_non_primitive : (CastNonPrimitive.t, migrated) kind
| Truthiness_test : (TruthinessTest.t, migrated) kind
| Equality_check : (EqualityCheck.t, migrated) kind
| Duplicate_properties : (DuplicateProperties.t, migrated) kind
| Sketchy_equality : (Sketchy_equality.t, warn) kind
| Is_as_always : (Is_as_always.t, migrated) kind
| Sketchy_null_check : (Sketchy_null_check.t, migrated) kind
| Non_disjoint_check : (Non_disjoint_check.t, migrated) kind
| Cast_non_primitive : (Cast_non_primitive.t, migrated) kind
| Truthiness_test : (Truthiness_test.t, migrated) kind
| Equality_check : (Equality_check.t, migrated) kind
| Duplicate_properties : (Duplicate_properties.t, migrated) kind

type ('x, 'a) t = Pos.t * ('x, 'a) kind * 'x
Loading

0 comments on commit c3054ad

Please sign in to comment.