Skip to main content

fatou_formatter/
lib.rs

1//! Deterministic, rule-based formatter for the Julia language.
2//!
3//! This crate is the formatting engine of the [fatou](https://fatou.dev) CLI,
4//! extracted so embedders (such as a dprint Wasm plugin) can use it without
5//! the CLI's filesystem and process machinery. It formats a source string or
6//! an already-parsed [`fatou_parser`] CST; batch file walking, caching, and
7//! config discovery stay host-side.
8//!
9//! # Main entry points
10//!
11//! - [`format()`] / [`format_with_style`] — format a source string.
12//! - [`format_verified()`] / [`format_verified_with_style`] — format and prove
13//!   that the result preserves the parsed program and comments.
14//! - [`format_node`] / [`format_range`] — format an already-parsed
15//!   [`fatou_parser::syntax::SyntaxNode`], whole or a byte range of it.
16//! - [`FormatStyle`] — the layout knobs, with [`Default`] matching the fatou
17//!   CLI's defaults.
18//! - [`verify::verify_format`] — verify two source strings directly.
19//! - [`verify::ast_shape`] — the formatting-invariant shape of a source string,
20//!   for checking that formatting preserved the program (`ast(x) == ast(format(x))`).
21//!
22//! The crate is `wasm32-unknown-unknown`-compatible: no filesystem, process,
23//! thread, or clock use.
24//!
25//! # Features
26//!
27//! - `serde` — `Serialize`/`Deserialize` for [`FormatStyle`] and
28//!   [`LineEnding`], spelled like their `fatou.toml` counterparts.
29//! - `schema` — additionally derives `schemars::JsonSchema`, so an embedder
30//!   (e.g. a dprint plugin) can generate a config schema.
31
32pub mod formatter;
33
34pub mod parser;
35pub mod syntax;
36pub mod verify;
37
38/// The `rowan` version this crate's CST types are built on.
39///
40/// [`format_range`] takes a `rowan::TextRange`, so an embedder has to be able
41/// to name it. Re-exporting the dependency keeps that caller version-matched
42/// with us instead of making them guess a compatible `rowan` in their own
43/// `Cargo.toml`.
44pub use rowan;
45
46pub use formatter::{
47    FormatError, FormatOptions, FormatStyle, LineEnding, RangeFormatted, VerifiedFormatError,
48    format, format_node, format_node_with_options, format_range, format_range_with_options,
49    format_verified, format_verified_with_options, format_verified_with_style, format_with_options,
50    format_with_style, print_document,
51};
52pub use verify::VerificationError;