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): use Fmt instead of Printf/Format (E205)

Replace Printf.sprintf/printf and Format.asprintf/fprintf with
Fmt.str/pr/pf across publicsuffix, punycode, rate-limit, requests,
and openamp packages. Add fmt dependency to gen_corpus executables.

+28 -29
+1 -1
gen/dune
··· 1 1 (executable 2 2 (name gen_psl) 3 3 (modules gen_psl) 4 - (libraries re punycode)) 4 + (libraries re punycode fmt)) 5 5 6 6 (rule 7 7 (targets publicsuffix_data.ml)
+18 -19
gen/gen_psl.ml
··· 204 204 } 205 205 206 206 |}; 207 - Printf.printf "(* Statistics: %d total rules (%d ICANN, %d private) *)\n" 208 - rule_count icann_count private_count; 209 - Printf.printf "(* Version: %s *)\n" version; 210 - Printf.printf "(* Commit: %s *)\n" commit; 207 + Fmt.pr "(* Statistics: %d total rules (%d ICANN, %d private) *)\n" rule_count 208 + icann_count private_count; 209 + Fmt.pr "(* Version: %s *)\n" version; 210 + Fmt.pr "(* Commit: %s *)\n" commit; 211 211 print_string "\n" 212 212 213 213 let print_generated_footer rule_count icann_count private_count version commit 214 214 root_name = 215 - Printf.printf "let root = %s\n" root_name; 215 + Fmt.pr "let root = %s\n" root_name; 216 216 print_string 217 217 {| 218 218 (** Get the root of the suffix trie *) ··· 220 220 221 221 (** Total number of rules in the list *) 222 222 |}; 223 - Printf.printf "let rule_count = %d\n\n" rule_count; 224 - Printf.printf "let icann_rule_count = %d\n\n" icann_count; 225 - Printf.printf "let private_rule_count = %d\n\n" private_count; 226 - Printf.printf "let version = %S\n\n" version; 227 - Printf.printf "let commit = %S\n" commit 223 + Fmt.pr "let rule_count = %d\n\n" rule_count; 224 + Fmt.pr "let icann_rule_count = %d\n\n" icann_count; 225 + Fmt.pr "let private_rule_count = %d\n\n" private_count; 226 + Fmt.pr "let version = %S\n\n" version; 227 + Fmt.pr "let commit = %S\n" commit 228 228 229 229 let assign_node_names node_counter node_names = 230 230 let rec go node = 231 - let name = Printf.sprintf "n%d" !node_counter in 231 + let name = Fmt.str "n%d" !node_counter in 232 232 incr node_counter; 233 233 Hashtbl.add node_names node.id name; 234 234 List.iter (fun (_, child) -> go child) node.children; ··· 251 251 (fun child -> ignore (generate_node child)) 252 252 node.wildcard_child; 253 253 let name = Hashtbl.find node_names node_id in 254 - Buffer.add_string output_buffer (Printf.sprintf "let %s = {\n" name); 254 + Buffer.add_string output_buffer (Fmt.str "let %s = {\n" name); 255 255 (match node.rule with 256 256 | None -> Buffer.add_string output_buffer " rule = None;\n" 257 257 | Some (rt, sec) -> ··· 265 265 match sec with ICANN -> "ICANN" | Private -> "Private" 266 266 in 267 267 Buffer.add_string output_buffer 268 - (Printf.sprintf " rule = Some (%s, %s);\n" rt_str sec_str)); 268 + (Fmt.str " rule = Some (%s, %s);\n" rt_str sec_str)); 269 269 if node.children = [] then 270 270 Buffer.add_string output_buffer " children = [];\n" 271 271 else begin ··· 274 274 (fun (label, child) -> 275 275 let child_name = Hashtbl.find node_names child.id in 276 276 Buffer.add_string output_buffer 277 - (Printf.sprintf " (\"%s\", %s);\n" (escape_string label) 278 - child_name)) 277 + (Fmt.str " (\"%s\", %s);\n" (escape_string label) child_name)) 279 278 node.children; 280 279 Buffer.add_string output_buffer " ];\n" 281 280 end; ··· 284 283 | Some child -> 285 284 let child_name = Hashtbl.find node_names child.id in 286 285 Buffer.add_string output_buffer 287 - (Printf.sprintf " wildcard_child = Some %s;\n" child_name)); 286 + (Fmt.str " wildcard_child = Some %s;\n" child_name)); 288 287 Buffer.add_string output_buffer "}\n\n"; 289 288 Hashtbl.add generated node_id true; 290 289 name ··· 303 302 304 303 let () = 305 304 if Array.length Sys.argv < 2 then begin 306 - Printf.eprintf "Usage: %s <public_suffix_list.dat>\n" Sys.argv.(0); 305 + Fmt.epr "Usage: %s <public_suffix_list.dat>\n" Sys.argv.(0); 307 306 exit 1 308 307 end; 309 308 let filename = Sys.argv.(1) in ··· 315 314 match version with 316 315 | Some v -> v 317 316 | None -> 318 - Printf.eprintf "ERROR: VERSION not found in %s\n" filename; 317 + Fmt.epr "ERROR: VERSION not found in %s\n" filename; 319 318 exit 1 320 319 in 321 320 let commit = 322 321 match commit with 323 322 | Some c -> c 324 323 | None -> 325 - Printf.eprintf "ERROR: COMMIT not found in %s\n" filename; 324 + Fmt.epr "ERROR: COMMIT not found in %s\n" filename; 326 325 exit 1 327 326 in 328 327 generate_code trie rule_count icann_count private_count version commit
+1 -1
test/cmd/test_publicsuffix_cmd.ml
··· 46 46 let term = Publicsuffix_cmd.registrable_term psl in 47 47 match eval_term_with_domain term "com" with 48 48 | Some (Error Publicsuffix.Domain_is_public_suffix) -> () 49 - | Some (Ok v) -> fail (Printf.sprintf "expected error, got Ok %S" v) 49 + | Some (Ok v) -> fail (Fmt.str "expected error, got Ok %S" v) 50 50 | Some (Error e) -> fail (Publicsuffix.error_to_string e) 51 51 | None -> fail "term evaluation failed" 52 52
+6 -6
test/psl_cli/main.ml
··· 15 15 *) 16 16 17 17 let psl = Publicsuffix.v () 18 - let print_error e = Printf.printf "ERROR: %s\n" (Publicsuffix.error_to_string e) 18 + let print_error e = Fmt.pr "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 21 21 let print_bool_result = function ··· 29 29 | Publicsuffix.ICANN -> "ICANN" 30 30 | Publicsuffix.Private -> "PRIVATE" 31 31 in 32 - Printf.printf "%s (%s)\n" s sec_str 32 + Fmt.pr "%s (%s)\n" s sec_str 33 33 | Error e -> print_error e 34 34 35 35 let () = ··· 64 64 print_result_with_section 65 65 (Publicsuffix.public_suffix_with_section psl Sys.argv.(2)) 66 66 | "stats" -> 67 - Printf.printf "Total rules: %d\n" (Publicsuffix.rule_count psl); 68 - Printf.printf "ICANN rules: %d\n" (Publicsuffix.icann_rule_count psl); 69 - Printf.printf "Private rules: %d\n" (Publicsuffix.private_rule_count psl) 67 + Fmt.pr "Total rules: %d\n" (Publicsuffix.rule_count psl); 68 + Fmt.pr "ICANN rules: %d\n" (Publicsuffix.icann_rule_count psl); 69 + Fmt.pr "Private rules: %d\n" (Publicsuffix.private_rule_count psl) 70 70 | cmd -> 71 - Printf.eprintf "Unknown command or missing arguments: %s\n" cmd; 71 + Fmt.epr "Unknown command or missing arguments: %s\n" cmd; 72 72 exit 1
+2 -2
test/test_publicsuffix.ml
··· 26 26 27 27 let check_err msg expected_err f = 28 28 match f () with 29 - | Ok v -> fail (Printf.sprintf "%s: expected error, got Ok %S" msg v) 29 + | Ok v -> fail (Fmt.str "%s: expected error, got Ok %S" msg v) 30 30 | Error e -> 31 31 check string msg 32 32 (Publicsuffix.error_to_string expected_err) ··· 34 34 35 35 let check_err_bool msg expected_err f = 36 36 match f () with 37 - | Ok v -> fail (Printf.sprintf "%s: expected error, got Ok %b" msg v) 37 + | Ok v -> fail (Fmt.str "%s: expected error, got Ok %b" msg v) 38 38 | Error e -> 39 39 check string msg 40 40 (Publicsuffix.error_to_string expected_err)