0.18.1 • Published 2 months ago

@sane-fmt/x86_64-pc-windows-msvc v0.18.1

Weekly downloads
588
License
-
Repository
github
Last release
2 months ago

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 exports/sane-fmt.typescript.json, src/rules.rs, and tests/rules.rs for more information.

Installation

Download prebuilt binaries

Go to the release page.

From crates.io

cargo install sane-fmt

Links:

From NPM

WASM (all platform)

npm i -g @sane-fmt/wasm32-wasi

Links:

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 Deno Registry

Links:

From Arch User Repository

Download source and compile

paru -S sane-fmt

Links:

Download prebuilt binary

paru -S sane-fmt-bin

Links:

Use with Dprint

If you already have Dprint, you can skip installing sane-fmt binary. Create a dprint.json file with the following content:

{
  "$schema": "https://dprint.dev/schemas/v0.json",
  "projectType": "openSource",
  "extends": "https://github.com/sane-fmt/sane-fmt/raw/master/exports/sane-fmt.dprint.json",
  "includes": [
    "**/*.js",
    "**/*.ts"
  ],
  "excludes": [
    ".git",
    "node_modules"
  ],
  "plugins": [
    "https://plugins.dprint.dev/typescript-${DPRINT_TYPESCRIPT_VERSION}.wasm"
  ]
}

Notes:

  • Replace master in the "extends" line above with appropriate sane-fmt version.
  • Replace ${DPRINT_TYPESCRIPT_VERSION} above with appropriate dprint-plugin-typescript version.

See also:

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.

Check all TypeScript and JavaScript files in a list

Each line of list.txt is a path to a TypeScript/JavaScript file.

sane-fmt --include=list.txt

Check all TypeScript and JavaScript files from a Git repo

git ls-files | grep -Ei '\.(js|ts)$' | sane-fmt --include=-

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

Shell Completions

If you installed sane-fmt via the AUR, completions for bash, fish, and zsh are already installed for you.

Shell completion files are located in ./exports directory of this repo or the Release Page with name in form of completion.<extension> where <extension> is corresponding file extension of target language. Install them to appropriate locations in your filesystem to use.

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, and as such, the sane-fmt command does not have customization capability.

However, if you still want a copy of sane-fmt with your own customized rules, do one of the following:

License

MIT © Hoàng Văn Khải

0.18.1

2 months ago

0.18.0

2 months ago

0.17.0

2 years ago

0.15.2

2 years ago

0.16.0

2 years ago

0.16.1

2 years ago

0.14.0

2 years ago

0.13.0

2 years ago

0.11.0

3 years ago

0.10.1

3 years ago

0.10.0

3 years ago

0.9.11

3 years ago

0.9.10

3 years ago

0.9.8

3 years ago

0.9.7

3 years ago

0.9.9

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.0

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.8.7

3 years ago

0.8.5

3 years ago

0.8.4

3 years ago

0.8.6

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.6

3 years ago

0.7.5

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.5

3 years ago

0.6.4

3 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.5.14

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.13

4 years ago

0.5.12

4 years ago

0.5.11

4 years ago

0.5.10

4 years ago

0.5.9

4 years ago

0.5.7

4 years ago

0.5.6

4 years ago

0.5.4

4 years ago

0.5.3

4 years ago

0.5.5

4 years ago

0.5.0

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.4.10

4 years ago

0.4.9

4 years ago

0.4.8

4 years ago

0.4.7

4 years ago

0.4.6

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.2.30

4 years ago

0.2.33

4 years ago

0.2.32

4 years ago

0.2.31

4 years ago

0.2.29

4 years ago

0.2.27

4 years ago

0.2.26

4 years ago

0.2.25

4 years ago

0.2.24

4 years ago

0.2.23

4 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.20

4 years ago

0.2.16

4 years ago

0.2.15

4 years ago

0.2.11

4 years ago

0.2.19

4 years ago

0.2.18

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago