Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3
Opinionated code formatter for TypeScript and JavaScript
License
sane-fmt/sane-fmt
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Opinionated code formatter for TypeScript and JavaScript.
- 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.
Readexports/sane-fmt.typescript.json,src/rules.rs, andtests/rules.rs for more information.
Go tothe release page.
Fromcrates.io
cargo install sane-fmt
Links:
FromNPM
npm i -g @sane-fmt/wasm32-wasi
Links:
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:
FromDeno Registry
Links:
paru -S sane-fmt
Links:
paru -S sane-fmt-bin
Links:
Use withDprint
If you already have Dprint, you can skip installingsane-fmt binary. Create adprint.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
masterin the"extends"line above with appropriate sane-fmt version. - Replace
${DPRINT_TYPESCRIPT_VERSION}above with appropriatedprint-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.
sane-fmt --write
This command would reformat all TypeScript and JavaScript files.
sane-fmt
This command would check all TypeScript and JavaScript files.
sane-fmt --write foo.ts bar.js
This command would only reformatfoo.ts andbar.js.
sane-fmt --write src/
This command would reformat all TypeScript and JavaScript files withinsrc/ directory.
Each line oflist.txt is a path to a TypeScript/JavaScript file.
sane-fmt --include=list.txt
git ls-files| grep -Ei'\.(js|ts)$'| sane-fmt --include=-
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, andunchangedas outputs.
Recommendation: Thisaction will installsane-fmt and execute it for you.
sane-fmt --help
If you installed sane-fmtvia the AUR, completions for bash, fish, and zsh are already installed for you.
Shell completion files are located in./exports directory of this repo orthe Release Page with name in form ofcompletion.<extension> where<extension> is corresponding file extension of target language. Install them to appropriate locations in your filesystem to use.
sane-fmt is an opinionated code formatter for TypeScript and JavaScript powered bydprint. You can think of it as a portable Dprint config file that is always up-to-date.
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 upsane-fmt is simple: just download the binary.
Customization is antithetical to the purpose of this project, and as such, thesane-fmt command does not have customization capability.
However, if you still want a copy ofsane-fmt with your own customized rules, do one of the following:
About
Opinionated code formatter for TypeScript and JavaScript
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.