README
sane-fmt
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.
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.
crates.io
Fromcargo install sane-fmt
Links:
NPM
FromWASM (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:
Deno Registry
FromLinks:
Arch User Repository
FromDownload source and compile
paru -S sane-fmt
Links:
Download prebuilt binary
paru -S sane-fmt-bin
Links:
Dprint
Use withIf 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:
- sane-fmt.dprint.json: Dprint configuration with rules of sane-fmt.
- sane-fmt.typescript.json: Configuration of dprint-plugin-typescript with rules of sane-fmt.
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)