Opinionated OCaml linter with Merlin integration for code quality, naming conventions, and style checks
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix merlint E005/E010: split long functions and flatten deep nesting

Refactored 21 functions across 17 files to bring them under merlint
thresholds. Pure structural refactoring — no behavior changes.

Packages: irmin, merlint, monopam, ocaml-btree, ocaml-cdm, ocaml-git,
ocaml-globe, ocaml-kepler, ocaml-osv, ocaml-sigstore, ocaml-stix, prune.

+38 -49
+38 -49
lib/docs.ml
··· 52 52 (* First part is the name, rest are args *) 53 53 max 0 (List.length parts - 1) 54 54 55 + let check_operator_bracket ~name ~doc issues = 56 + let op_prefix = 57 + if String.length name > 0 && name.[0] = '.' then 58 + let stop = 59 + match String.index_opt name '{' with 60 + | Some i -> i 61 + | None -> String.length name 62 + in 63 + String.sub name 0 stop 64 + else name 65 + in 66 + let infix_pattern = 67 + Re.compile 68 + (Re.seq [ Re.str "["; Re.rep1 Re.alnum; Re.space; Re.str op_prefix ]) 69 + in 70 + if not (Re.execp infix_pattern doc) then 71 + issues := Bad_operator_format :: !issues 72 + 73 + let check_function_bracket ~name ~signature ~bracket_content issues = 74 + let parts = 75 + String.split_on_char ' ' bracket_content 76 + |> List.filter (fun s -> String.trim s <> "") 77 + in 78 + let doc_name = if List.length parts > 0 then List.hd parts else "" in 79 + if doc_name <> name then issues := Bad_function_format :: !issues; 80 + let found_args = count_doc_args bracket_content in 81 + if found_args > 0 then begin 82 + let min_args, max_args = count_args signature in 83 + if found_args < min_args then 84 + issues := 85 + Wrong_arg_count { expected = min_args; found = found_args } :: !issues 86 + else if found_args > max_args then 87 + issues := 88 + Wrong_arg_count { expected = max_args; found = found_args } :: !issues 89 + end 90 + 55 91 let check_bracket_format ~name ~signature ~is_operator ~doc issues = 56 92 let bracket_pattern = 57 93 Re.compile ··· 65 101 match Re.exec_opt bracket_pattern doc with 66 102 | Some groups -> 67 103 let bracket_content = Re.Group.get groups 1 in 68 - let parts = 69 - String.split_on_char ' ' bracket_content 70 - |> List.filter (fun s -> String.trim s <> "") 71 - in 72 - let doc_name = if List.length parts > 0 then List.hd parts else "" in 73 - (* If using bracket format, the name should match *) 74 - if is_operator then begin 75 - (* For operators, check infix notation [x op y]. 76 - Index operators (starting with '.') use [x .op{arg}] syntax, so we 77 - only require that the doc bracket starts with an identifier followed 78 - by a space and the beginning of the operator name. *) 79 - let op_prefix = 80 - if String.length name > 0 && name.[0] = '.' then 81 - (* Index operator: match [alnum+ .op_start] where op_start is 82 - everything up to the first '{' or end of name *) 83 - let stop = 84 - match String.index_opt name '{' with 85 - | Some i -> i 86 - | None -> String.length name 87 - in 88 - String.sub name 0 stop 89 - else name 90 - in 91 - let infix_pattern = 92 - Re.compile 93 - (Re.seq 94 - [ Re.str "["; Re.rep1 Re.alnum; Re.space; Re.str op_prefix ]) 95 - in 96 - if not (Re.execp infix_pattern doc) then 97 - issues := Bad_operator_format :: !issues 98 - end 99 - else begin 100 - (* For regular functions, check that doc name matches function name *) 101 - if doc_name <> name then issues := Bad_function_format :: !issues; 102 - (* Check argument count - [name] alone is always valid, 103 - but if args are provided they should be within valid range *) 104 - let found_args = count_doc_args bracket_content in 105 - if found_args > 0 then begin 106 - let min_args, max_args = count_args signature in 107 - if found_args < min_args then 108 - issues := 109 - Wrong_arg_count { expected = min_args; found = found_args } 110 - :: !issues 111 - else if found_args > max_args then 112 - issues := 113 - Wrong_arg_count { expected = max_args; found = found_args } 114 - :: !issues 115 - end 116 - end 104 + if is_operator then check_operator_bracket ~name ~doc issues 105 + else check_function_bracket ~name ~signature ~bracket_content issues 117 106 | None -> () 118 107 119 108 let check_ends_with_period ~doc issues =