tidy v0.0.0

CLI

Every flag of the tidy command, what it does, and the exit codes it returns.

Shell
$ tidy [paths...] [options]          # print the formatted file
$ tidy up [paths...] [options]       # rewrite files in place
$ tidy check [paths...] [options]    # list what isn't formatted
Shell
# print one file, formatted
$ tidy index.html

# list the files that aren't formatted; exits 1 if any
$ tidy check src

# rewrite everything in place
$ tidy up .

# a different width for one run
$ tidy up . --width 100

Commands

Command What it does
tidy Print the formatted result to stdout.
tidy up Rewrite each file in place, and print what it rewrote. Files already formatted are not touched.
tidy check Print the paths that are not formatted. Changes nothing. Exits 1 if any.

Bare tidy reads stdin when it gets no paths, and takes one file otherwise. up and check take as many paths as you like, and the current folder when you give none.

Shell
$ tidy check          # the same as: tidy check .
$ cat a.ts | tidy --stdin-filepath a.ts

A folder named up or check is read as the command, not as a path. Write ./up to mean the folder.

Only what git says changed

Instead of naming paths, let git name them. Both work with up and check, and not with bare tidy.

Flag What it does
--staged Only files staged in the index. tidy up stages what it rewrote, so the commit holds the formatted version.
--changed[=<ref>] Only files that differ from a branch or commit. Without a value, the default branch.
Shell
# a pre-commit hook, in one line
$ tidy up --staged

# everything this branch touched
$ tidy check --changed

# against a named branch or commit
$ tidy check --changed=main
$ tidy check --changed=HEAD~3

--changed compares the working tree against the merge base of the ref and HEAD, so it covers what you committed on this branch and what you have not committed yet. New files that git does not track yet are included; files a .gitignore covers are not.

The default branch is origin/HEAD where that is set, else main, else master. If none of those exist, name the ref yourself.

A path narrows what git named, rather than adding to it:

Shell
# only the changed files under src/
$ tidy check --changed=main src

When git names no file tidy can format, the run succeeds and prints nothing — a commit that touches no formattable file is not a failure.

--changed takes its value with =, because --changed main cannot be told apart from --changed followed by the path main.

Choosing files

Flag What it does
--parser <name> Force a language instead of guessing from the file name.
--stdin-filepath <path> The path the text on stdin would have, which decides its language and which config files apply.
--threads <n> How many files to format at once. Defaults to one per core; 1 uses a single thread.

--parser takes html, vue, mjml, handlebars, tempura, css, scss, less, json, jsonc, json5, json-stringify, yaml, toml, dockerfile, ini, gitconfig, graphql, babel, typescript, babel-ts, xml or markdown. The names are Prettier's.

When tidy walks a folder it skips node_modules and every folder whose name starts with .. It does not read .gitignore. To leave other paths out, pass the paths you do want, or see Ignoring code.

Config

Flag What it does
--config <path> Use this config for every file, instead of the nearest one.
--no-config Read no config files, and no .editorconfig.

Without either, each file takes the nearest tidy.json, tidy.jsonc or tidy.toml, on top of any .editorconfig that applies. Options given on the command line override both. See Configuration file.

Style

Every one of these has a config equivalent, documented in Options.

Flag Default What it does
--width <n> 80 The line width the printer fits to. 120 for Dockerfiles.
--indent <n> 2 The width of one indent.
--tabs off Indent with tabs.
--eol <eol> lf Line endings: lf, crlf or cr.
--whitespace <how> auto HTML whitespace sensitivity: strict, auto or ignore. strict for XML.
--quote <quote> double Quotes in Handlebars, style sheets, JSON5, YAML and JS.
--no-trailing-comma No trailing commas in SCSS, JSONC, JSON5, YAML, TOML and JS.
--no-bracket-spacing No spaces inside the braces of JSON and JS objects, and YAML flow mappings.
--single-attribute-per-line off Put each attribute on its own line.
--bracket-same-line off Keep the > of a multi-line tag on the last line.
--ignore <name> prettier-ignore The name of the ignore directive.
--no-embedded Leave code of other languages inside a file as it is written.

Other

Flag What it does
-v, --version Print the version.
-h, --help Print help.

Exit codes

Code Means
0 Success. With check, every file is formatted.
1 With check, at least one file is not formatted.
2 Something failed: a file would not parse, a path could not be read, or an option was wrong.

A check run that cannot parse a file exits 2, not 1, so a broken file is never reported as merely unformatted.

stdin

Shell
$ cat index.html | tidy --stdin-filepath index.html
$ echo '{"a":1}' | tidy --parser json

Without --stdin-filepath or --parser, tidy treats stdin as HTML. --stdin-filepath is the better of the two, because it also decides which config files apply.

Edit this page on GitHub MIT · tidy v0.0.0
Esc