From 7a38952205ce28e174d2b81bc4a45f5c92f0c37e Mon Sep 17 00:00:00 2001 From: Jeffrey Xiao Date: Tue, 18 Oct 2022 13:18:14 -0400 Subject: [PATCH 1/4] update err message, clean style in camelot --- lib/style/verbose.ml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/style/verbose.ml b/lib/style/verbose.ml index 555b771..aceaae7 100644 --- a/lib/style/verbose.ml +++ b/lib/style/verbose.ml @@ -35,7 +35,7 @@ module TupleProj : EXPRCHECK = struct let name = "TupleProj", check end -(** ----------------------- Checks rules: Nesting if >= 3 levels ------------- *) +(** ----------------------- Checks rules: Nesting if > 3 levels ------------- *) module NestedIf : EXPRCHECK = struct type ctxt = Parsetree.expression_desc Pctxt.pctxt let fix = "using let statements or helper methods / rethinking logic" @@ -45,9 +45,9 @@ module NestedIf : EXPRCHECK = struct depth = 0 || begin match p with | Pexp_ifthenelse (_, bthen, Some belse) -> - if depth = 1 then true else - find_nesting ((skip_seq_let bthen).pexp_desc) (depth - 1) || - find_nesting ((skip_seq_let belse).pexp_desc) (depth - 1) + depth = 1 + || find_nesting ((skip_seq_let bthen).pexp_desc) (depth - 1) + || find_nesting ((skip_seq_let belse).pexp_desc) (depth - 1) | _ -> false end in @@ -59,7 +59,7 @@ end module NestedMatch : EXPRCHECK = struct type ctxt = Parsetree.expression_desc Pctxt.pctxt let fix = "using let statements or helper methods / rethinking logic" - let violation = "using nested match statements more than three layers deep" + let violation = "using nested match statements three or more layers deep" let check st (E {location; source; pattern} : ctxt) = begin match pattern with (* Layer one *) From 34c4bc65d1432e213985326c9d75dd1179a2822a Mon Sep 17 00:00:00 2001 From: Jeffrey Xiao Date: Tue, 18 Oct 2022 13:33:51 -0400 Subject: [PATCH 2/4] update test case :( --- test/test.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.ml b/test/test.ml index ef66380..a3abfa8 100644 --- a/test/test.ml +++ b/test/test.ml @@ -277,7 +277,7 @@ let%expect_test _ = (* ------------------------------------------------------------------------ *) File ./examples/verbose.ml, lines 32-43, columns: 2-5 Warning: - using nested match statements more than three layers deep + using nested match statements three or more layers deep You wrote: match l with | [] -> From 08172b06606cb258ae915a3fa016fb915d6a6d8a Mon Sep 17 00:00:00 2001 From: Jeffrey Xiao Date: Mon, 14 Aug 2023 20:23:28 -0400 Subject: [PATCH 3/4] add OK match at 2 levels, remove NestedIf changes --- lib/style/verbose.ml | 8 ++++---- test/examples/verbose.ml | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/style/verbose.ml b/lib/style/verbose.ml index aceaae7..261f09e 100644 --- a/lib/style/verbose.ml +++ b/lib/style/verbose.ml @@ -35,7 +35,7 @@ module TupleProj : EXPRCHECK = struct let name = "TupleProj", check end -(** ----------------------- Checks rules: Nesting if > 3 levels ------------- *) +(** ----------------------- Checks rules: Nesting if >= 3 levels ------------- *) module NestedIf : EXPRCHECK = struct type ctxt = Parsetree.expression_desc Pctxt.pctxt let fix = "using let statements or helper methods / rethinking logic" @@ -45,9 +45,9 @@ module NestedIf : EXPRCHECK = struct depth = 0 || begin match p with | Pexp_ifthenelse (_, bthen, Some belse) -> - depth = 1 - || find_nesting ((skip_seq_let bthen).pexp_desc) (depth - 1) - || find_nesting ((skip_seq_let belse).pexp_desc) (depth - 1) + if depth = 1 then true else + find_nesting ((skip_seq_let bthen).pexp_desc) (depth - 1) || + find_nesting ((skip_seq_let belse).pexp_desc) (depth - 1) | _ -> false end in diff --git a/test/examples/verbose.ml b/test/examples/verbose.ml index e569d78..19ff1af 100644 --- a/test/examples/verbose.ml +++ b/test/examples/verbose.ml @@ -25,6 +25,18 @@ let f () = if x then else y +(* No Flagging here - only 2 match levels deep *) +let f () = + let l = [] in + begin match l with + | [] -> + begin match l with + | [] -> true + | _ -> false + end + | _ -> true + end + (* Nested matched bad as well *) let f () = From 764eebb5f069eccf3069fcb6c2bd5d4908493cee Mon Sep 17 00:00:00 2001 From: Jeffrey Xiao Date: Mon, 14 Aug 2023 20:49:00 -0400 Subject: [PATCH 4/4] fix line numbers --- test/test.ml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/test.ml b/test/test.ml index a3abfa8..4c84b38 100644 --- a/test/test.ml +++ b/test/test.ml @@ -158,7 +158,7 @@ let%expect_test _ = lint_and_hint to_lint; [%expect{| (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 75, columns: 8-57 + File ./examples/verbose.ml, line 87, columns: 8-57 Warning: Usage of the `&&` is redundant You wrote: @@ -167,7 +167,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 74, columns: 8-57 + File ./examples/verbose.ml, line 86, columns: 8-57 Warning: Usage of the `&&` is redundant You wrote: @@ -176,7 +176,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 73, columns: 8-40 + File ./examples/verbose.ml, line 85, columns: 8-40 Warning: Usage of the `&&` is redundant You wrote: @@ -185,7 +185,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 72, columns: 8-24 + File ./examples/verbose.ml, line 84, columns: 8-24 Warning: Usage of the `&&` is redundant You wrote: @@ -194,7 +194,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 71, columns: 8-30 + File ./examples/verbose.ml, line 83, columns: 8-30 Warning: Usage of the `&&` is redundant You wrote: @@ -203,7 +203,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 70, columns: 8-26 + File ./examples/verbose.ml, line 82, columns: 8-26 Warning: Usage of the `&&` is redundant You wrote: @@ -212,7 +212,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 69, columns: 8-57 + File ./examples/verbose.ml, line 81, columns: 8-57 Warning: Usage of the `||` is redundant You wrote: @@ -221,7 +221,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 68, columns: 8-57 + File ./examples/verbose.ml, line 80, columns: 8-57 Warning: Usage of the `||` is redundant You wrote: @@ -230,7 +230,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 67, columns: 8-40 + File ./examples/verbose.ml, line 79, columns: 8-40 Warning: Usage of the `||` is redundant You wrote: @@ -239,7 +239,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 66, columns: 8-24 + File ./examples/verbose.ml, line 78, columns: 8-24 Warning: Usage of the `||` is redundant You wrote: @@ -248,7 +248,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 65, columns: 8-30 + File ./examples/verbose.ml, line 77, columns: 8-30 Warning: Usage of the `||` is redundant You wrote: @@ -257,7 +257,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 64, columns: 8-26 + File ./examples/verbose.ml, line 76, columns: 8-26 Warning: Usage of the `||` is redundant You wrote: @@ -266,7 +266,7 @@ let%expect_test _ = simplifying further (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 50, columns: 8-85 + File ./examples/verbose.ml, line 62, columns: 8-85 Warning: using nested if statements more than three layers deep You wrote: @@ -275,7 +275,7 @@ let%expect_test _ = using let statements or helper methods / rethinking logic (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, lines 32-43, columns: 2-5 + File ./examples/verbose.ml, lines 44-55, columns: 2-5 Warning: using nested match statements three or more layers deep You wrote: @@ -325,7 +325,7 @@ let%expect_test _ = using `::` instead (* ------------------------------------------------------------------------ *) - File ./examples/verbose.ml, line 50, columns: 0-80 + File ./examples/verbose.ml, line 62, columns: 0-80 Warning: exceeding the 80 character line limit You wrote: