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.

monopam/merlint: read x-quality from .opam files

+21 -23
+21 -23
lib/rules/e910.ml
··· 1 1 (** E910: Package quality policy enforcement. 2 2 3 3 Reads quality policy from [*.opam.template] files: 4 - {[ x-quality: ["build" "test" "fuzz" "doc"] ]} 4 + {[ 5 + x-quality: ["build" "test" "fuzz" "doc"] 6 + ]} 5 7 6 8 Checks that declared quality features actually exist in the package. 7 9 Reports: 8 10 - Missing: declared in policy but not present (error) 9 11 - Undeclared: present but not in policy (suggestion) *) 10 12 11 - type finding = 12 - | Missing of string 13 - | Undeclared of string 14 - 13 + type finding = Missing of string | Undeclared of string 15 14 type payload = { package : string; findings : finding list } 16 15 17 - let dir_exists path = 18 - try Sys.is_directory path with Sys_error _ -> false 16 + let dir_exists path = try Sys.is_directory path with Sys_error _ -> false 19 17 20 18 let has_files dir suffix = 21 19 try ··· 37 35 if dir_exists test_dir && has_files test_dir ".ml" then add "test"; 38 36 if dir_exists fuzz_dir && has_files fuzz_dir ".ml" then add "fuzz"; 39 37 if dir_exists interop_dir then add "interop"; 40 - if dir_exists test_dir then 41 - (try 38 + (if dir_exists test_dir then 39 + try 42 40 Sys.readdir test_dir |> Array.to_list 43 41 |> List.iter (fun f -> 44 - if 45 - Filename.check_suffix f ".t" 46 - && dir_exists (Filename.concat test_dir f) 47 - then add "cram") 42 + if 43 + Filename.check_suffix f ".t" 44 + && dir_exists (Filename.concat test_dir f) 45 + then add "cram") 48 46 with Sys_error _ -> ()); 49 47 List.sort_uniq String.compare !features 50 48 51 - (** Read quality policy from [*.opam.template] files. *) 49 + (** Read quality policy from [*.opam] files. *) 52 50 let read_policy pkg_dir = 53 51 try 54 52 let files = Sys.readdir pkg_dir |> Array.to_list in 55 - let templates = 56 - List.filter (fun f -> Filename.check_suffix f ".opam.template") files 53 + let opam_files = 54 + List.filter (fun f -> Filename.check_suffix f ".opam") files 57 55 in 58 56 List.concat_map 59 57 (fun f -> ··· 72 70 let rest = String.sub t plen (String.length t - plen) in 73 71 String.split_on_char '"' rest 74 72 |> List.filter (fun s -> 75 - let s = String.trim s in 76 - s <> "" && s <> "[" && s <> "]" && s <> " ") 73 + let s = String.trim s in 74 + s <> "" && s <> "[" && s <> "]" && s <> " ") 77 75 else []) 78 76 lines 79 77 with Sys_error _ -> []) 80 - templates 78 + opam_files 81 79 with Sys_error _ -> [] 82 80 83 81 let check (ctx : Context.project) = ··· 94 92 dir_exists pkg_dir && pkg <> "_build" && pkg <> ".git" && pkg <> "_opam" 95 93 then 96 94 let policy = read_policy pkg_dir in 97 - if policy <> [] then 95 + if policy <> [] then ( 98 96 let detected = detect_features pkg_dir in 99 97 let findings = ref [] in 100 98 (* Policy violations: declared but missing *) ··· 110 108 findings := Undeclared feature :: !findings) 111 109 detected; 112 110 if !findings <> [] then 113 - issues := 114 - Issue.v { package = pkg; findings = !findings } :: !issues) 111 + issues := Issue.v { package = pkg; findings = !findings } :: !issues)) 115 112 packages; 116 113 !issues 117 114 ··· 121 118 (List.map 122 119 (function 123 120 | Missing f -> Fmt.str "%s required by x-quality but missing" f 124 - | Undeclared f -> Fmt.str "%s present, consider adding to x-quality" f) 121 + | Undeclared f -> 122 + Fmt.str "%s present, consider adding to x-quality" f) 125 123 findings)) 126 124 127 125 let rule =