Find and remove dead code and unused APIs in OCaml projects
1(** {1 Prune}
2
3 Find and report unused exports from OCaml [.mli] interface files in dune
4 projects. Uses merlin to analyze symbol usage across the entire project.
5
6 This library is organized into several sub-modules:
7 - Types: Core types and utilities (included in this module)
8 - {!System}: System utilities (TTY, dune, merlin)
9 - {!Analysis}: Symbol discovery and occurrence analysis
10 - {!Removal}: File modification functions *)
11
12(** {2 Types} *)
13
14include module type of Types
15(** Re-export core types for convenience *)
16
17(** {2 Main interface functions} *)
18
19type mode = [ `Dry_run | `Single_pass | `Iterative ]
20(** Analysis mode:
21 - [`Dry_run]: Only report what would be removed, don't modify files
22 - [`Single_pass]: Remove unused exports once (no iterative cleanup)
23 - [`Iterative]: Alternate between cleaning .mli and .ml files until fixpoint
24*)
25
26val analyze :
27 ?yes:bool ->
28 ?exclude_dirs:string list ->
29 ?public_files:string list ->
30 mode ->
31 string ->
32 string list ->
33 (stats, error) result
34(** [analyze ?yes ?exclude_dirs ?public_files mode root_dir mli_files] analyzes
35 and optionally removes unused exports based on the specified mode. Returns
36 statistics about the run. The [yes] parameter only affects confirmation
37 prompts when removing code, not the analysis behavior. The [exclude_dirs]
38 parameter specifies directories whose occurrences should be ignored when
39 counting usage. The [public_files] parameter marks .mli files as public APIs
40 whose exports should never be removed. *)
41
42(** {2 Internal modules exposed for testing} *)
43
44module System = System
45(** Internal system module exposed for main.ml *)
46
47module Removal = Removal
48(** Internal removal module exposed for testing *)
49
50module Cache = Cache
51(** Internal cache module exposed for testing *)
52
53module Analysis = Analysis
54(** Internal analysis module exposed for testing *)
55
56module Module_alias = Module_alias
57(** Internal module_alias module exposed for testing *)
58
59module Warning = Warning
60(** Internal warning module exposed for testing *)
61
62module Locate = Locate
63(** Internal locate module exposed for testing *)
64
65module Doctor = Doctor
66(** Diagnostic tool for debugging merlin and build issues *)
67
68module Show = Show
69(** Symbol occurrence reporting tool *)
70
71module Output = Output
72(** Output system with different modes *)