Crate biome_formatter

source ·
Expand description

Infrastructure for code formatting

This module defines FormatElement, an IR to format code documents and provides a mean to print such a document to a string. Objects that know how to format themselves implement the Format trait.

§Formatting Traits

  • Format: Implemented by objects that can be formatted.
  • FormatRule: Rule that knows how to format an object of another type. Necessary in the situation where it’s necessary to implement Format on an object from another crate. This module defines the FormatRefWithRule and FormatOwnedWithRule structs to pass an item with its corresponding rule.
  • FormatWithRule implemented by objects that know how to format another type. Useful for implementing some reusable formatting logic inside of this module if the type itself doesn’t implement Format

§Formatting Macros

This crate defines two macros to construct the IR. These are inspired by Rust’s fmt macros

  • format!: Formats a formatable object
  • format_args!: Concatenates a sequence of Format objects.
  • write!: Writes a sequence of formatable objects into an output buffer.

Re-exports§

Modules§

Macros§

  • Provides multiple different alternatives and the printer picks the first one that fits. Use this as last resort because it requires that the printer must try all variants in the worst case. The passed variants must be in the following order:
  • Writes formatted data into the given buffer and prints all written elements for a quick and dirty debugging.
  • Creates the Format IR for a value.
  • Constructs the parameters for other formatting macros.
  • Writes formatted data into a buffer.

Structs§

Enums§

Traits§

Functions§

  • The format function takes an Arguments struct and returns the resulting formatting IR.
  • Formats a syntax node file based on its features.
  • Formats a range within a file, supported by Biome
  • Formats a single node within a file, supported by Biome.
  • The write function takes a target buffer and an Arguments struct that can be precompiled with the format_args! macro.

Type Aliases§