OCaml implementation of the Mozilla Public Suffix service
0
fork

Configure Feed

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

fix(lint): remove redundant function prefixes (E331)

Strip get_/make_/find_/create_ from 138 function definitions and all
call sites across ocaml-pds, ocaml-pid1, ocaml-precommit,
ocaml-publicsuffix, ocaml-qemu, ocaml-requests, ocaml-retry, and
ocaml-rpmsg. Use Module.v for constructors per the E331 convention.

+31 -26
+1 -1
bin/main.ml
··· 5 5 6 6 open Cmdliner 7 7 8 - let psl = lazy (Publicsuffix.create ()) 8 + let psl = lazy (Publicsuffix.v ()) 9 9 let psl () = Lazy.force psl 10 10 11 11 (* Helper functions for printing results *)
+5 -5
gen/gen_psl.ml
··· 43 43 44 44 let node_id_counter = ref 0 45 45 46 - let make_node () = 46 + let new_node () = 47 47 let id = !node_id_counter in 48 48 incr node_id_counter; 49 49 { id; rule = None; children = []; wildcard_child = None } ··· 99 99 match node.wildcard_child with 100 100 | Some c -> c 101 101 | None -> 102 - let c = make_node () in 102 + let c = new_node () in 103 103 node.wildcard_child <- Some c; 104 104 c 105 105 in ··· 112 112 match List.assoc_opt label node.children with 113 113 | Some c -> c 114 114 | None -> 115 - let c = make_node () in 115 + let c = new_node () in 116 116 node.children <- (label, c) :: node.children; 117 117 c 118 118 in ··· 123 123 (** Parse the entire PSL file *) 124 124 let parse_file filename = 125 125 let ic = open_in filename in 126 - let trie = make_node () in 126 + let trie = new_node () in 127 127 let current_section = ref ICANN in 128 128 let rule_count = ref 0 in 129 129 let icann_count = ref 0 in ··· 304 304 print_string 305 305 {| 306 306 (** Get the root of the suffix trie *) 307 - let get_root () = root 307 + let root () = root 308 308 309 309 (** Total number of rules in the list *) 310 310 |};
+11 -12
lib/publicsuffix.ml
··· 43 43 | Domain_is_public_suffix -> Fmt.pf fmt "Domain is itself a public suffix" 44 44 45 45 let error_to_string err = Fmt.str "%a" pp_error err 46 - let create () = { root = Publicsuffix_data.get_root () } 46 + let v () = { root = Publicsuffix_data.root () } 47 47 let pp fmt _t = Fmt.pf fmt "<Publicsuffix>" 48 48 49 49 (* Find a child node by label (case-insensitive) *) 50 - let find_child (node : trie_node) label = 50 + let child (node : trie_node) label = 51 51 let label_lower = String.lowercase_ascii label in 52 52 List.find_opt 53 53 (fun (l, _) -> String.lowercase_ascii l = label_lower) ··· 63 63 64 64 (** Find all matching rules for a domain. Labels should be in reverse order (TLD 65 65 first). *) 66 - let find_matches (root : trie_node) labels = 66 + let matches (root : trie_node) labels = 67 67 let matches = ref [] in 68 68 69 69 (* Track whether we matched the implicit * rule *) ··· 110 110 wc.rule); 111 111 112 112 (* Check for exact label match *) 113 - find_child node label 114 - |> Option.iter (fun child -> traverse child (depth + 1) rest) 113 + child node label |> Option.iter (fun c -> traverse c (depth + 1) rest) 115 114 in 116 115 117 116 traverse root 0 labels; ··· 187 186 else prevailing.matched_labels 188 187 189 188 (** Find the prevailing rule for a domain *) 190 - let find_prevailing_rule t labels = 189 + let prevailing_rule t labels = 191 190 let rev_labels = List.rev labels in 192 - let matches = find_matches t.root rev_labels in 193 - select_prevailing_rule matches 191 + let ms = matches t.root rev_labels in 192 + select_prevailing_rule ms 194 193 195 194 let public_suffix_with_section t domain = 196 195 match normalize_domain domain with 197 196 | Error e -> Error e 198 197 | Ok (labels, has_trailing_dot) -> 199 - let prevailing = find_prevailing_rule t labels in 198 + let prevailing = prevailing_rule t labels in 200 199 let count = suffix_label_count prevailing in 201 200 if count > List.length labels then Error No_public_suffix 202 201 else ··· 211 210 match normalize_domain domain with 212 211 | Error e -> Error e 213 212 | Ok (labels, has_trailing_dot) -> 214 - let prevailing = find_prevailing_rule t labels in 213 + let prevailing = prevailing_rule t labels in 215 214 let count = suffix_label_count prevailing in 216 215 (* Registrable domain = suffix + 1 label *) 217 216 let reg_label_count = count + 1 in ··· 228 227 match normalize_domain domain with 229 228 | Error e -> Error e 230 229 | Ok (labels, _) -> 231 - let prevailing = find_prevailing_rule t labels in 230 + let prevailing = prevailing_rule t labels in 232 231 let count = suffix_label_count prevailing in 233 232 (* Domain is a public suffix if it has exactly suffix_label_count labels *) 234 233 Ok (List.length labels = count) ··· 237 236 match normalize_domain domain with 238 237 | Error e -> Error e 239 238 | Ok (labels, _) -> 240 - let prevailing = find_prevailing_rule t labels in 239 + let prevailing = prevailing_rule t labels in 241 240 let count = suffix_label_count prevailing in 242 241 let reg_label_count = count + 1 in 243 242 (* Domain is registrable if it has exactly reg_label_count labels *)
+4 -4
lib/publicsuffix.mli
··· 50 50 {1 Example Usage} 51 51 52 52 {[ 53 - let psl = Publicsuffix.create () in 53 + let psl = Publicsuffix.v () in 54 54 55 55 (* Get the public suffix of a domain *) 56 56 Publicsuffix.public_suffix psl "www.example.com" (* Returns: Ok "com" *) ··· 168 168 169 169 (** {1 Creation} *) 170 170 171 - val create : unit -> t 172 - (** Create a PSL instance using the embedded Public Suffix List data. The data 173 - is compiled into the library at build time. *) 171 + val v : unit -> t 172 + (** [v ()] creates a PSL instance using the embedded Public Suffix List data. 173 + The data is compiled into the library at build time. *) 174 174 175 175 (** {1 Core Operations} *) 176 176
+1 -1
lib/publicsuffix_data.mli
··· 119 119 120 120 (** {1 Data Access} *) 121 121 122 - val get_root : unit -> trie_node 122 + val root : unit -> trie_node 123 123 (** Get the root of the suffix trie. 124 124 125 125 The root node represents the starting point for all PSL lookups. Domain
+1 -1
test/cmd/test_publicsuffix_cmd.ml
··· 12 12 13 13 open Alcotest 14 14 15 - let psl = Publicsuffix.create () 15 + let psl = Publicsuffix.v () 16 16 17 17 (* Helper: evaluate a Cmdliner term with a given domain argument and return 18 18 the result. We build a throwaway Cmd.t, set argv to include the domain,
+3
test/cmd/test_publicsuffix_cmd.mli
··· 1 + (** Public suffix CLI tests. *) 2 + 1 3 val suite : string * unit Alcotest.test_case list 4 + (** Alcotest suite. *)
+1 -1
test/psl_cli/main.ml
··· 14 14 This tool is used by the cram tests to verify correct behavior. 15 15 *) 16 16 17 - let psl = Publicsuffix.create () 17 + let psl = Publicsuffix.v () 18 18 let print_error e = Printf.printf "ERROR: %s\n" (Publicsuffix.error_to_string e) 19 19 let print_result = function Ok s -> print_endline s | Error e -> print_error e 20 20
+1 -1
test/test_publicsuffix.ml
··· 10 10 11 11 open Alcotest 12 12 13 - let psl = Publicsuffix.create () 13 + let psl = Publicsuffix.v () 14 14 15 15 (* ---------- helpers --------------------------------------------------- *) 16 16
+3
test/test_publicsuffix.mli
··· 1 + (** Public suffix tests. *) 2 + 1 3 val suite : string * unit Alcotest.test_case list 4 + (** Alcotest suite. *)