#formatter #linter #parser

biome_formatter

Biome's formatter shared infrastructure

7 releases (4 breaking)

0.5.7 Mar 12, 2024
0.5.5 Mar 12, 2024
0.4.0 Jan 9, 2024
0.3.1 Nov 26, 2023
0.0.2 Sep 28, 2023

#2248 in Development tools

Download history 1701/week @ 2024-08-08 1750/week @ 2024-08-15 1597/week @ 2024-08-22 1676/week @ 2024-08-29 1756/week @ 2024-09-05 1681/week @ 2024-09-12 1640/week @ 2024-09-19 2062/week @ 2024-09-26 1678/week @ 2024-10-03 1791/week @ 2024-10-10 1403/week @ 2024-10-17 2277/week @ 2024-10-24 2940/week @ 2024-10-31 3522/week @ 2024-11-07 4830/week @ 2024-11-14 3477/week @ 2024-11-21

15,525 downloads per month
Used in 5 crates

MIT/Apache

1.5MB
27K SLoC

Biome - Toolchain of the web

Discord chat CI cargo version

biome_formatter

Biome's formatter implementation. Follow the documentation.


lib.rs:

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.

Dependencies

~10–19MB
~256K SLoC