A formatter for the leptos view! macro

Overview

leptosfmt

crates.io build security discord

A formatter for the leptos view! macro

All notable changes are documented in: CHANGELOG.md

Install

cargo install leptosfmt

or for trying out unreleased features:

cargo install --git https://github.com/bram209/leptosfmt.git

Usage

Usage: leptosfmt [OPTIONS] <INPUT_PATTERN>

Arguments:
  <INPUT_PATTERN>  A file, directory or glob

Options:
  -m, --max-width <MAX_WIDTH>    [default: 100]
  -t, --tab-spaces <TAB_SPACES>  [default: 4]
  -h, --help                     Print help
  -V, --version                  Print version

Examples

Single file

Format a specific file by name

leptosfmt ./examples/counter/src/lib.rs

Current directory

Format all .rs files within the current directory

leptosfmt .

Directory

Format all .rs files within the examples directory

leptosfmt ./examples

Glob

Format all .rs files ending with _test.rs within the examples directory

leptosfmt ./examples/**/*_test.rs

Pretty-printer algorithm

The 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. This algorithm's implementation is taken from prettyplease which is adapted from rustc_ast_pretty.

The 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). The 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 communicate 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.

Comments
  • Feature request: support Tailwind automatic class sorting

    Feature request: support Tailwind automatic class sorting

    Tailwind supports automatic class sorting with Prettier. It would be nice if this formatter could somehow incorporate that functionality. Perhaps it could be an optional feature, that if enabled, would check if a class attribute was a string literal, and if so, it would sort the class names in that string similarly to how prettier-plugin-tailwindcss does it.

    enhancement 
    opened by elliotwaite 4
  • Feature request: preserve comments

    Feature request: preserve comments

    The formatter currently removes comments. It would be nice to have the option to preserve comments (or perhaps this could be made the default behavior).

    opened by elliotwaite 3
  • feat: attribute value brace style

    feat: attribute value brace style

    attr_value_brace_style

    Whether or not to add braces around single expression attribute values.

    • Default value: "WhenRequired"
    • Possible values: "Always", "AlwaysUnlessLit", "WhenRequired", "Preserve"

    Examples

    "AlwaysUnlessLiteral":

    <div on:click=move |_| set_value(0) disabled=is_disabled />
    <img width=100 height={200} class="banner" alt={"test"} />
    
    // BECOMES
    
    <div on:click={move |_| set_value(0)} disabled={is_disabled} />
    <img width=100 height=200 class="banner" alt="test" />
    

    "Always":

    <div on:click=move |_| set_value(0) disabled=is_disabled />
    <img width=100 height={200} class="banner" alt={"test"}>
    
    // BECOMES
    
    <div on:click={move |_| set_value(0)} disabled={is_disabled} />
    <img width={100} height={200} class={"banner"} alt={"test"} />
    

    "WhenRequired": (default)

    <div on:click={move |_| set_value(0)} disabled={is_disabled} />
    <img width=100 height={200} class="banner" alt={"test"} />
    
    // BECOMES
    
    <div on:click=move |_| set_value(0) disabled=is_disabled />
    <img width=100 height=200 class="banner" alt="test" />
    

    "Preserve":

    <div on:click=move |_| set_value(0) />                              // stays untouched
    <div on:click={move |_| set_value(0)} />                            // stays untouched
    <img width=100 height={200} class="banner" src={"./banner.jpg"} />    // stays untouched
    
    
    opened by bram209 0
  • Wrapping &str indented repeatedly

    Wrapping &str indented repeatedly

    It seems as though paragraphs that wrap and are indented are repeatedly indented upon re-running LeptosFmt, so they creep further to the right each time.

    (This is inside a view! macro):

                    <p class="mb-4">
                            "At Houski Inc, we are committed to protecting the privacy of our
                                          users. This privacy policy explains how we collect, use, and share
                                          information when you use our website, property data system, and APIs
                                          (collectively, the \"Services\"). By using our Services, you agree to
                                          the collection, use, and sharing of your information as described in
                                          this privacy policy. If you do not agree with our policies and
                                          practices, do not use our Services."
                        </p>
    

    If this isn't easily reproduced I can supply more code.

    bug 
    opened by Houski 0
  • feat: `--check` mode

    feat: `--check` mode

    Implements https://github.com/bram209/leptosfmt/issues/12

    Now, by adding a --check flag, the program will exit unsuccessfully if it should have made changes to the files. If it didn't need to make any changes, then it will exit successfully, as usual.

    This main check happens within the source_file::format_file_source function, however similar logic seems to be in source_file::format_expr_source. Do we need to copy this logic into that function as well?

    opened by roboteng 2
  • Allow a `--check` mode, to verify formatting is correct

    Allow a `--check` mode, to verify formatting is correct

    Similar to cargo fmt where if --check is passed, then if anything needs to be formatted, the program exits with a non-zero exit code, indicating that the formatting was not correct.

    enhancement 
    opened by roboteng 2
  • feat: non-doc comments within rsx

    feat: non-doc comments within rsx

    Resolves #3

    Note: Currently inserts the doc comments before a node. Inline (at end of a statement) comments are not yet supported (and will end up in the line above).

    Note2: This does not preserve comments in code blocks yet, I plan to add this to https://github.com/bram209/prettyplease later.

    opened by bram209 2
  • Support non-doc comments

    Support non-doc comments

    the issue is that syn interpreters non-doc comments as white space: https://doc.rust-lang.org/reference/comments.html#non-doc-comments

    workaround involves extracting the comments from the source text directly.

    enhancement 
    opened by bram209 0
Releases(0.1.4)
Owner
Bram
Bram
A Faster(⚡) formatter, linter, bundler, and more for JavaScript, TypeScript, JSON, HTML, Markdown, and CSS Lapce Plugin

Lapce Plugin for Rome Lapce-rome is a Lapce plugin for rome, The Rome is faster ⚡ , A formatter, linter, compiler, bundler, and more for JavaScript, T

xiaoxin 7 Dec 16, 2022
Configurable, smart and fast CSS/SCSS/Sass/Less formatter.

?? Malva Malva is a configurable, smart and fast CSS/SCSS/Sass/Less formatter. Why? Configurable Malva is configurable. It provides several configurat

Pig Fang 20 Oct 27, 2023
Configurable HTML/Vue/Svelte/Jinja/Twig formatter, with dprint integration.

markup_fmt markup_fmt is a configurable HTML/Vue/Svelte/Jinja/Twig formatter. Notes for Vue and Svelte Users This formatter provides some options such

Pig Fang 17 Nov 15, 2023
A small command-line application to view images from the terminal written in Rust.

A small command-line application to view images from the terminal written in Rust. It is basically the front-end of viuer

Atanas Yankov 1.9k Jan 3, 2023
❗️ Small script to view GitHub notifications in the terminal

github-notifications Small script to view GitHub notifications in the terminal Shows and color-codes the notification source, eg if you're the owner o

Brian Shaginaw 1 Jan 10, 2022
A discord bot to view & monitor OpenSea collections, written in Rust

Titan What is this This is a discord bot to monitor OpenSea collections and get info about them, including: Floor Price Activity Sales per Hour And mo

theldb 3 Oct 11, 2022
View your github contribution calander in unicode.

View your github contribution calander in the terminal Now in rust! gh-cal 0.1.0 marshmallow View your github contribution calander in unicode USAGE:

marshmallow 54 Sep 12, 2022
A simple tui to view & control docker containers

oxker A simple tui to view & control docker containers Built in Rust, making heavy use of tui-rs & Bollard Download & install See releases download &

Jack Wills 119 Dec 28, 2022
A git sub-command to view your git repository in the web browser

git-view A git sub-command to view your git repository in the web browser! About Are you also frustrated from moving your hands away from the keyboard

Hamothy 5 Sep 26, 2022
Introducing Inlyne, a GPU powered yet browsless tool to help you quickly view markdown files in the blink of an eye.

Inlyne - a GPU powered, browserless, markdown + html viewer inlyne README.md --theme dark/light About Markdown files are a wonderful tool to get forma

null 308 Jan 1, 2023
A simple solution for scoped styles in Leptos

Styled: Easy Styling for Leptos Components If you're looking for an easy way to apply scoped styles to your Leptos components, Styled is the Leptos ma

Eran Boodnero 8 Mar 5, 2023
View Source, but for terminal escape sequences

Escape Artist Escape Artist is a tool for seeing ANSI escape codes in terminal applications. You interact with your shell just like you normally would

Reilly Wood 8 Apr 16, 2023
A website for the Leptos Web Framework!

Leptos Website A Repo for the public facing Leptos website. Still a WIP. Client Side Rendering This example cannot be built as a trunk standalone CSR-

Leptos 7 May 2, 2023
A terminal ASCII media player. View images, gifs, videos, webcam, YouTube, etc.. directly in the terminal as ASCII art.

Terminal Media Player View images, videos (files or YouTube links), webcam, etc directly in the terminal as ASCII. All images you see below are just m

Max Curzi 36 May 8, 2023
A Nix template for full-stack web apps in Rust using Leptos

leptos-fullstack A Nix template for full-stack web apps in Rust using Leptos. Tech used: Leptos full-stack framework server functions ssr + hydration

Sridhar Ratnakumar 6 Aug 4, 2023
A zero-config leptos component to display markdown

A port of yew-markdown using leptos ! Usage You can use this component to render both static and dynamic markdown. Static markdown use leptos::*; {

Antonin Peronnet 4 Aug 4, 2023
Terminal UI for leetcode. Lets you browse questions through different topics. View, solve, run and submit questions from TUI.

Leetcode TUI Use Leetcode in your terminal. Why this TUI: My motivation for creating leetcode-tui stemmed from my preference for tools that are lightw

Akarsh 8 Aug 10, 2023
Experimental integration of `fedimint-client` with the Leptos web frontend framework

CAUTION: highly experimental, the Database implementation is likely horribly broken Fedimint Client built with Leptos This repo contains a proof-of-co

null 3 Aug 27, 2023
A filesystem driver that allows you to view your Blackboard course contents as if they were normal files and folders on your system!

BlackboardFS Blackboard: noun A website so bad that it might as well be a network drive. BlackboardFS is a filesystem driver that allows you to view y

null 22 Sep 4, 2023