{"id":13597284,"url":"https://github.com/bram209/leptosfmt","last_synced_at":"2025-10-22T06:29:28.755Z","repository":{"id":144854194,"uuid":"616434510","full_name":"bram209/leptosfmt","owner":"bram209","description":"A formatter for the leptos view! macro","archived":false,"fork":false,"pushed_at":"2024-05-09T08:17:38.000Z","size":254,"stargazers_count":202,"open_issues_count":16,"forks_count":23,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-09T09:32:35.997Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bram209.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-20T11:38:30.000Z","updated_at":"2024-06-10T08:47:10.111Z","dependencies_parsed_at":null,"dependency_job_id":"74edb0c5-ce9b-451e-a527-34328f329c51","html_url":"https://github.com/bram209/leptosfmt","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bram209%2Fleptosfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bram209%2Fleptosfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bram209%2Fleptosfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bram209%2Fleptosfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bram209","download_url":"https://codeload.github.com/bram209/leptosfmt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223418971,"owners_count":17142242,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T17:00:29.427Z","updated_at":"2025-10-22T06:29:23.709Z","avatar_url":"https://github.com/bram209.png","language":"Rust","funding_links":[],"categories":["Tools","Rust"],"sub_categories":[],"readme":"# leptosfmt\n\n[![crates.io](https://img.shields.io/crates/v/leptosfmt.svg)](https://crates.io/crates/leptosfmt)\n[![build](https://img.shields.io/github/actions/workflow/status/bram209/leptosfmt/ci.yml)](https://github.com/bram209/leptosfmt/actions/workflows/ci.yml?query=branch%3Amain)\n[![security](https://img.shields.io/github/actions/workflow/status/bram209/leptosfmt/security-audit.yml?label=%F0%9F%9B%A1%EF%B8%8F%20security%20audit)](https://github.com/bram209/leptosfmt/actions/workflows/security-audit.yml?query=branch%3Amain)\n[![discord](https://img.shields.io/discord/1031524867910148188?color=%237289DA\u0026label=discord%20%23leptosfmt)](https://discord.gg/YdRAhS7eQB)\n\nA formatter for the leptos view! macro\n\nAll notable changes are documented in: [CHANGELOG.md](./CHANGELOG.md)\n\n## Install\n\n`cargo install leptosfmt`\n\nor for trying out unreleased features:\n\n`cargo install --git https://github.com/bram209/leptosfmt.git`\n\n## Usage\n\n```\nUsage: leptosfmt [OPTIONS] [INPUT_PATTERNS]...\n\nArguments:\n  [INPUT_PATTERNS]...  A space separated list of file, directory or glob\n\nOptions:\n  -m, --max-width \u003cMAX_WIDTH\u003e\n          Maximum width of each line\n  -t, --tab-spaces \u003cTAB_SPACES\u003e\n          Number of spaces per tab\n  -x, --excludes \u003cEXCLUDE_PATTERNS\u003e\n          A space separated list of file, directory or glob\n  -c, --config-file \u003cCONFIG_FILE\u003e\n          Configuration file\n  -s, --stdin\n          Format stdin and write to stdout\n  -r, --rustfmt\n          Format with rustfmt after formatting with leptosfmt (requires stdin)\n      --rustfmt-args \"\u003cRUSTFMT_ARGS\u003e...\"\n          Pass additional arguments to `rustfmt` (requires `rustfmt`)\n      --override-macro-names \u003cOVERRIDE_MACRO_NAMES\u003e...\n          Override formatted macro names\n  -e, --experimental-tailwind\n          Format attributes with tailwind\n      --tailwind-attr-names \u003cTAILWIND_ATTR_NAMES\u003e...\n          Override attributes to be formatted with tailwind [default: class]\n  -q, --quiet\n\n      --check\n          Check if the file is correctly formatted. Exit with code 1 if not\n  -h, --help\n          Print help\n  -V, --version\n          Print version\n```\n\n## Using with Rust Analyzer\n\nYou have to do two things:\n- configure edition in `rustfmt.toml`\n- configure RA by setting the `rust-analyzer.rustfmt.overrideCommand` setting\n\n### Configure `rustfmt` edition\n**You must** configure `rustfmt` to use the correct edition, place a `rustfmt.toml` file in the root of your project:\n\n```toml\nedition = \"2021\"\n# (optional) other config...\n```\n\n### Configure RA\n\u003cdetails\u003e\n  \u003csummary\u003eOption 1: Using `rust-analyzer.toml` (Recommended)\u003c/summary\u003e \u003cbr /\u003e\n  A new way to configure `rust-analyzer` to use `leptosfmt` is to use directory based `rust-analyzer` configuration.\n\n  To do this, create a file named `rust-analyzer.toml` in the root of your project with the following content:\n  ```toml\n  [rustfmt]\n  overrideCommand = [\"leptosfmt\", \"--stdin\", \"--rustfmt\"]\n  # (optional) other config...\n  ```\n\n  This method of setting up rust-analyzer is editor agnostic to any editor that uses `rust-analyzer` for formatting rust code.\n\n  \u003e Note: This feature of `rust-analyzer` is currently unstable and no guarantees are made that this will continue to work across versions. You have to use a recent version of `rust-analyzer` ([2024-06-10](https://github.com/rust-lang/rust-analyzer/releases/tag/2024-06-10) or newer).\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eOption 2: Editor specific config\u003c/summary\u003e \u003cbr /\u003e\n\n  **VSCode**:\n\n  For VSCode users, I recommend to use workpsace settings (CMD + shift + p -\u003e Open workspace settings), so that you can only configure `leptosfmt` for workspaces that are using leptos.\n\n  Open your workspace settings and add the following configuration:\n  ```json\n  {\n    \"rust-analyzer.rustfmt.overrideCommand\": [\"leptosfmt\", \"--stdin\", \"--rustfmt\"]\n  }\n  ```\n\n  **Neovim**:\n\n  For Neovim users, I recommend using [neoconf.nvim](https://github.com/folke/neoconf.nvim) for managing project-local LSP configuration, so that you can only configure `leptosfmt` for workspaces that are using leptos.\n\n  Alternatively, you may directly configure [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) by appending the following to your `.setup{}` table:\n  ```lua\n  lspconfig[\"rust_analyzer\"].setup {\n    settings = {\n      [\"rust-analyzer\"] = {\n        rustfmt = {\n          overrideCommand = { \"leptosfmt\", \"--stdin\", \"--rustfmt\" },\n        },\n      },\n    },\n  }\n  ```\n\n  **Emacs**:\n\n  For Emacs users, see the relevant [configuration option](https://emacs-lsp.github.io/lsp-mode/page/lsp-rust-analyzer/#lsp-rust-analyzer-rustfmt-override-command) for LSP Mode.\n\u003c/details\u003e\n\n## Configuration\n\nYou can configure all settings through a `leptosfmt.toml` file.\n\n```toml\nmax_width = 100 # Maximum width of each line\ntab_spaces = 4 # Number of spaces per tab\nindentation_style = \"Auto\" # \"Tabs\", \"Spaces\" or \"Auto\"\nnewline_style = \"Auto\" # \"Unix\", \"Windows\" or \"Auto\"\nattr_value_brace_style = \"WhenRequired\" # \"Always\", \"AlwaysUnlessLit\", \"WhenRequired\" or \"Preserve\"\nmacro_names = [ \"leptos::view\", \"view\" ] # Macro names which will be formatted\nclosing_tag_style = \"Preserve\" # \"Preserve\", \"SelfClosing\" or \"NonSelfClosing\"\n\n# Attribute values can be formatted by custom formatters\n# Every attribute name may only select one formatter (this might change later on)\n[attr_values]\nclass = \"Tailwind\" # \"Tailwind\" is the only attribute value formatter available for now\n```\n\nTo see what each setting does, the see [configuration docs](./docs/configuration.md)\n\n## Examples\n\n**Single file**\n\nFormat a specific file by name\n\n`leptosfmt ./examples/counter/src/lib.rs`\n\n**Current directory**\n\nFormat all .rs files within the current directory\n\n`leptosfmt .`\n\n**Directory**\n\nFormat all .rs files within the examples directory\n\n`leptosfmt ./examples`\n\n**Glob**\n\nFormat all .rs files ending with `_test.rs` within the examples directory\n\n`leptosfmt ./examples/**/*_test.rs`\n\n## A note on non-doc comments\n\nCurrently this formatter does not support non-doc comments in code blocks. It uses a fork of prettyplease for formatting rust code, and `prettyplease` does not support this. I would like to not diverge this fork too much (so I can easily keep in sync with upstream), therefore I didn't add non-doc comment support in my prettyplease fork for now.\nThis means that you _can_ use non-doc comments throughout your view macro, as long as they don't reside within code blocks.\n\n\u003e A bit more context: `prettyplease` uses `syn` to parse rust syntax. According to https://doc.rust-lang.org/reference/comments.html#non-doc-comments non-doc comments _are interpreted as a form of whitespace_ by the parser; `syn` basically ignores/skips these comments and does not include them in the syntax tree.\n\n## Pretty-printer algorithm\n\nThe pretty-printer is based on Philip Karlton’s Mesa pretty-printer, as described in the appendix to Derek C. Oppen, “Pretty Printing” (1979), Stanford Computer Science Department STAN-CS-79-770, http://i.stanford.edu/pub/cstr/reports/cs/tr/79/770/CS-TR-79-770.pdf.\nThis algorithm's implementation is taken from `prettyplease` which is adapted from `rustc_ast_pretty`.\n\nThe algorithm takes from an input stream of length `n` and an output device with margin width `m`, the algorithm requires time `O(n)` and space `O(m)`.\nThe algorithm is described in terms of two parallel processes; the first scans the input stream to determine the space required to print logical blocks of tokens; the second uses this information to decide where to break lines of text; the two processes\ncommunicate by means of a buffer of size `o(m)`. The algorithm does not wait for the entire stream to be input, but begins printing as soon as it has received a linefull of input.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbram209%2Fleptosfmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbram209%2Fleptosfmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbram209%2Fleptosfmt/lists"}