Crates.io | typstfmt |
lib.rs | typstfmt |
version | 0.1.0 |
source | src |
created_at | 2023-07-15 13:40:48.601474 |
updated_at | 2023-07-15 13:40:48.601474 |
description | A soon to be formatter for the typst lang |
homepage | |
repository | https://github.com/astrale-sharp/typstfmt |
max_upload_size | |
id | 917229 |
size | 64,637 |
The crate was published with empty Typst to crates.io mostly to reserve the name for the typst dev if they wanted it later (and they can have the name anytime). This means that this formatter will likely change it's name (typfmt) at some point (or become the official one but I likely won't be the main dev then)
In progress formatter for the Typst language!
Currently, the output shouldn't be always trusted and isn't perfect but should be lossless.
cargo install --git https://github.com/astrale-sharp/typstfmt.git
This will put the compiled binary in ~/.cargo/bin/
. To use it without prefixing path to the binary you must add this directory to your PATH
. You can check if it was already added with echo "$PATH"
.
If you haven't added ~/.cargo/bin
to you PATH
, you should add next line in your .bashrc
, .zshrc
etc.:
export PATH="$HOME/.cargo/bin:$PATH"
New instances of your shell (bash, zsh) will have an updated PATH
.
Or you can add this to your .profile
or .zshenv
to update your PATH
when the OS is booted. This will require a restart of the machine.
Since we're visiting a AST (which is a tree) we have a recursive function
visit(node: &LinkedNode, ctx: &mut Ctx)
that meets all the nodes in the tree.
It formats the children first (bottom up), the the parent decide what to do with their children.
Children have access to arbitrary context (they can know the kind of their parents, who are their siblings etc).
We use insta! If you don't have it installed take a look here (I advise installing with cargo binstall since I have a small computer and don't like waiting for things to compile)
one liner for cargo binstall : curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
then cargo binstall cargo-insta
to see how it currently formats all the snippets
cargo test
, a failing test indicates one of the snippets displayed in the next step is not formatted like this anymore.show_all.sh
Of course not! We have tracing enabled during tests!
If you're contributing tests you should add a test case under src/tests
for instance: make_test!(call_func_empty, "#f()");
then running your tests: cargo test && cargo insta review
if the info log isn't enough, run DEBUG=true cargo test
.
if you wish to pipe to a file run NO_COLOR=true cargo test
you may also set the NOLOG
env variable if you wish to disable logging entirely.