sane-fmt 0.2.21

Opinionated code formatter for TypeScript and JavaScript
sane-fmt-0.2.21 is not a library.
Visit the last successful build: sane-fmt-0.18.1

sane-fmt

GitHub Actions Status Travis Build Status

Opinionated code formatter for TypeScript and JavaScript.

Rules

  • Prefer single quotes.
  • No semicolons.
  • Trailing commas for multi-line.
  • No function parentheses for arrow function with single argument.
  • Multi-line union and intersection use consistent leading separator.

Preview.

Read rules/mod.rs and tests/rules.rs for more information.

Installation

Download prebuilt binaries

Go to the release page.

From crates.io

From NPM

WASM (all platform)

Native binaries

The WASM package while work on all platform, it is slow to start. For better speed, install one of the following packages instead:

For Linux:

For macOS:

For Windows:

From Arch User Repository

Download source and compile

Download prebuilt binary

Usage

Format all TypeScript and JavaScript files

sane-fmt --write

This command would reformat all TypeScript and JavaScript files.

Check for all TypeScript and JavaScript files

sane-fmt

This command would check all TypeScript and JavaScript files.

Format only some files

sane-fmt --write foo.ts bar.js

This command would only reformat foo.ts and bar.js.

Format all TypeScript and JavaScript files in a directory

sane-fmt --write src/

This command would reformat all TypeScript and JavaScript files within src/ directory.

GitHub Actions

sane-fmt also provides a convenient way to integrate with GitHub Actions. To use it, simply add --log-format=github-actions, like so:

sane-fmt --log-format=github-actions --details=diff

When this command is executed within a GitHub Actions runner, it will:

  • Annotates unformatted files.
  • Group diffs by file names (if --details=diff).
  • Export total, changed, and unchanged as outputs.

Recommendation: This action will install sane-fmt and execute it for you.

Print help message

sane-fmt --help

Become a Patron

My Patreon Page.

Frequently Asked Questions

What is this program?

sane-fmt is an opinionated code formatter for TypeScript and JavaScript powered by dprint. You can think of it as a portable Dprint config file that is always up-to-date.

What is the point of this program?

I want to apply a single, consistent formatting for all my codes regardless of environment without complex tooling.

I have considered using Prettier or Dprint, but that would mean having to set up Node.js even in non-Node.js environments. I also don't like copying my config files back-and-forth to update them.

On the other hand, setting up sane-fmt is simple: just download the binary.

How to customize the rules?

Customization is antithetical to the purpose of this project. Just fork this project if you want your own version of sane-fmt, or just use Dprint if you want convenient customization.

I plan to divide this package into multiple reusable crates in the future, this would allow crate user to provide their own rules to create their own version of sane-fmt. However, I will never make the rule configurable for the end-user.

License

MIT © Hoàng Văn Khải