Installs pre-commit hooks for OCaml projects that run dune fmt automatically
1
fork

Configure Feed

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

fix(lint): replace Printf/Format with Fmt across remaining packages

Migrate Printf.sprintf to Fmt.str, Format.fprintf to Fmt.pf, and
Format.pp_print_string to Fmt.string across bundle, gpt, hap, homebrew,
jsonwt, matter, mbr, meross, paseto, precommit, publicsuffix, qemu,
retry, sdnv, slack, sle, space-packet, spake2, sqlite, squashfs, tar,
tc, tcf, tcpcl, tm, tomlt, tty, uslp, vlog, wal, wire, yamlrw, yamlt,
osrelease, space, xdge, and crypto test runner.

+16 -21
+2 -3
bin/main.ml
··· 54 54 (if h.Precommit.fmt then [ "fmt" ] else []) 55 55 @ if h.Precommit.ai then [ "ai" ] else [] 56 56 in 57 - Format.pp_print_string ppf (String.concat "," parts) 57 + Fmt.string ppf (String.concat "," parts) 58 58 in 59 59 Arg.conv (parse, print) 60 60 ··· 342 342 ~title:(Tty.Span.styled Tty.Style.(fg Tty.Color.yellow) "Warning") 343 343 [ 344 344 Tty.Span.text 345 - (Printf.sprintf "This will rewrite git history in %d repositor%s." 346 - n_repos 345 + (Fmt.str "This will rewrite git history in %d repositor%s." n_repos 347 346 (if n_repos = 1 then "y" else "ies")); 348 347 Tty.Span.text "Branches will be backed up before rewriting."; 349 348 ]
+1 -1
lib/dune
··· 1 1 (library 2 2 (name precommit) 3 3 (public_name precommit) 4 - (libraries eio unix re git)) 4 + (libraries eio fmt unix re git))
+13 -17
lib/precommit.ml
··· 153 153 let dune_project = Filename.concat dir "dune-project" in 154 154 let ocamlformat_path = Filename.concat dir ".ocamlformat" in 155 155 if (not force) && not (file_exists ~fs:ctx.cwd dune_project) then 156 - Error 157 - (Printf.sprintf "%s: No dune-project found (use --force to override)" dir) 156 + Error (Fmt.str "%s: No dune-project found (use --force to override)" dir) 158 157 else 159 158 match find_git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with 160 - | None -> Error (Printf.sprintf "%s: No .git directory found" dir) 159 + | None -> Error (Fmt.str "%s: No .git directory found" dir) 161 160 | Some git_root -> 162 161 let git_dir_path = Filename.concat git_root ".git" in 163 162 let git_dir = resolve_git_dir ~fs:ctx.fs git_dir_path in ··· 443 442 444 443 let backup_branch ctx dir = 445 444 match find_git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with 446 - | None -> failwith (Printf.sprintf "%s: No .git directory found" dir) 445 + | None -> failwith (Fmt.str "%s: No .git directory found" dir) 447 446 | Some git_root -> 448 447 let repo = Git.Repository.open_repo ~fs:ctx.fs (Fpath.v git_root) in 449 448 let branch = ··· 454 453 let now = Unix.gettimeofday () in 455 454 let tm = Unix.localtime now in 456 455 let timestamp = 457 - Printf.sprintf "%04d%02d%02d-%02d%02d%02d" (1900 + tm.tm_year) 458 - (tm.tm_mon + 1) tm.tm_mday tm.tm_hour tm.tm_min tm.tm_sec 459 - in 460 - let backup_name = 461 - Printf.sprintf "backup/%s-before-fix-%s" branch timestamp 456 + Fmt.str "%04d%02d%02d-%02d%02d%02d" (1900 + tm.tm_year) (tm.tm_mon + 1) 457 + tm.tm_mday tm.tm_hour tm.tm_min tm.tm_sec 462 458 in 459 + let backup_name = Fmt.str "backup/%s-before-fix-%s" branch timestamp in 463 460 (match Git.Repository.head repo with 464 461 | Some hash -> 465 462 Git.Repository.write_ref repo ("refs/heads/" ^ backup_name) hash ··· 468 465 469 466 let rewrite_ai_attribution ctx dir = 470 467 match find_git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with 471 - | None -> Error (Printf.sprintf "%s: No .git directory found" dir) 468 + | None -> Error (Fmt.str "%s: No .git directory found" dir) 472 469 | Some git_root -> ( 473 470 let repo = Git.Repository.open_repo ~fs:ctx.fs (Fpath.v git_root) in 474 471 let user_email = get_user_email ~fs:ctx.fs repo in ··· 556 553 557 554 let format_status_row dir status = 558 555 let name = Filename.basename dir in 559 - Printf.sprintf 560 - "%-20s %s pre-commit %s commit-msg %s ocamlformat %s fmt-enabled" name 556 + Fmt.str "%-20s %s pre-commit %s commit-msg %s ocamlformat %s fmt-enabled" 557 + name 561 558 (status_icon status.has_pre_commit) 562 559 (status_icon status.has_commit_msg) 563 560 (status_icon status.has_ocamlformat) 564 561 (status_icon (not status.formatting_disabled)) 565 562 566 563 let format_status_header () = 567 - Printf.sprintf "%-20s %-11s %-11s %-12s %-11s" "Directory" "pre-commit" 564 + Fmt.str "%-20s %-11s %-11s %-12s %-11s" "Directory" "pre-commit" 568 565 "commit-msg" "ocamlformat" "formatting" 569 566 570 567 let format_status_separator () = String.make 80 '-' 571 568 572 569 let pp_status_table ppf statuses = 573 - Format.fprintf ppf "%s@." (format_status_header ()); 574 - Format.fprintf ppf "%s@." (format_status_separator ()); 570 + Fmt.pf ppf "%s@." (format_status_header ()); 571 + Fmt.pf ppf "%s@." (format_status_separator ()); 575 572 List.iter 576 - (fun (dir, status) -> 577 - Format.fprintf ppf "%s@." (format_status_row dir status)) 573 + (fun (dir, status) -> Fmt.pf ppf "%s@." (format_status_row dir status)) 578 574 statuses 579 575 580 576 let check_all ctx dirs = List.map (fun dir -> (dir, status_in_dir ctx dir)) dirs