Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error message for nested match, fix style and comments #89

Merged
merged 4 commits into from
Aug 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/style/verbose.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
12 changes: 12 additions & 0 deletions test/examples/verbose.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Comment on lines +28 to +39
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this test case here, which ended up adjusting the line numbers of the violations in test/test.ml.

(* Nested matched bad as well *)

let f () =
Expand Down
32 changes: 16 additions & 16 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -275,9 +275,9 @@ 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 more than three layers deep
using nested match statements three or more layers deep
You wrote:
match l with
| [] ->
Expand Down Expand Up @@ -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:
Expand Down