package ppx_enforce

  1. Overview
  2. Docs
PPX that enforces required function calls at compile time

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.0.tar.gz
md5=092a959c08fd1275987c2cc001b9c693
sha512=6f1d5c1e522160d35bb5fc61b0f21bf0e41e1b7a32602fe3aee47f9f878b2d9f8e01307d19c03b8e7da410ab073bbd0ac87a1a744eda56e04046e9e74fcd4888

doc/ppx_enforce/Ppx_enforce/index.html

Module Ppx_enforceSource

PPX rewriter that enforces the presence of specific function calls at compile time. The mirror of ppx_forbid: raises a compilation error when a required call is *absent* from a source file.

Usage: Add to dune file: (preprocess (pps ppx_enforce))

Suppression: Add [@@@enforce_exempt] at the top of a file to skip all enforcement checks for that file: @@@enforce_exempt (* this file is intentionally exempt *)

Or exempt a specific requirement: @@@enforce_exempt "Miaou_registry.register"

Configuration: Create a .ppx_enforce file in your project root with: # Enforce that Miaou_registry.register is called somewhere in the file call Miaou_registry.register "Widget must self-register via Miaou_registry.register ~name ~mli:%blob ..."

If no config file is found, no requirements are enforced.

Sourcetype required_item =
  1. | Call of string * string * string
    (*

    Call (module_name, function_name, message) — the file must contain at least one reference to Module_name.function_name.

    *)

A single enforcement requirement.

Sourceval config_path_override : string option ref

Config file path override (set via --config flag)

Sourceval parse_config_line : string -> required_item option

Parse a config line. Returns None for comments/empty lines.

Sourceval load_config_file : string -> required_item list

Load config from a file.

Sourceval find_config_file : string -> string option

Find config file by walking up directory tree.

Sourceval source_dir : string option ref
Sourceval load_config : unit -> required_item list
Sourceval required_items : required_item list option ref
Sourceval get_required : unit -> required_item list
Sourceval strip_build_prefix : string -> string option

Strip dune sandbox/build prefix to get source path.

Sourceval collect_exemptions : Ppxlib.structure_item list -> [> `All | `Named of string ] list

Check for @@@enforce_exempt or @@@enforce_exempt "Mod.fn" attributes at the structure level. Returns:

  • `All → file is fully exempt
  • `Some s → only the named requirement is exempt Returns a list of exemptions.
Sourceval contains_call : Ppxlib__.Import.Ast.structure -> String.t -> String.t -> bool

Search the structure for any occurrence of Modname.fname.

Sourceval impl : Ppxlib__.Import.Ast.structure -> Ppxlib__.Import.Ast.structure

The PPX implementation: check that each required call is present.