Prettier commands

Opinionated code formatter supporting multiple languages

104 commands

Formatting Files

  • prettier --write .

    Format all supported files in the current directory recursively

  • prettier --write src

    Format all supported files in the src directory recursively

  • prettier --write src/index.ts

    Format a single specific file in place

  • prettier --write "src/**/*.ts"

    Format all TypeScript files in src recursively

  • prettier --write "src/**/*.{ts,tsx}"

    Format all TypeScript and TSX files in src recursively

  • prettier --write "**/*.{js,jsx,ts,tsx}"

    Format all JS and TS files across the entire project

  • prettier --write "**/*.{js,ts,json,css,md}"

    Format JS, TS, JSON, CSS, and Markdown files across the project

  • prettier --write "src/**" "tests/**"

    Format all files in both src and tests directories

  • prettier --write . --ignore-path .gitignore

    Format all files using .gitignore as the ignore rule source

  • prettier --write . --ignore-path .prettierignore

    Format all files using a specific .prettierignore file

  • prettier --write . --ignore-unknown

    Format supported files, silently skipping unsupported file types

  • prettier --write . --no-error-on-unmatched-pattern

    Format files without erroring if a glob pattern matches nothing

  • prettier --write . --log-level=warn

    Format files showing only warnings and errors in output

  • prettier --write . --log-level=silent

    Format files suppressing all output

  • prettier --write . --log-level=debug

    Format files with verbose debug output for troubleshooting

Checking Files

  • prettier --check .

    Check if all supported files in the current directory are formatted

  • prettier --check src

    Check if all supported files in the src directory are formatted

  • prettier --check src/index.ts

    Check if a single specific file is formatted correctly

  • prettier --check "src/**/*.ts"

    Check if all TypeScript files in src are formatted

  • prettier --check "**/*.{js,ts,json,css,md}"

    Check formatting of JS, TS, JSON, CSS, and Markdown files

  • prettier --check . --ignore-path .gitignore

    Check formatting of files using .gitignore as the ignore source

  • prettier --check . --ignore-unknown

    Check formatting, silently skipping unsupported file types

  • prettier --check . --log-level=warn

    Check formatting showing only warnings and errors

Printing & Stdout

  • prettier src/index.ts

    Print the formatted output of a file to stdout without writing it

  • prettier --stdin-filepath src/index.ts

    Format stdin input treating it as the given file path and print to stdout

  • cat src/index.ts | prettier --stdin-filepath index.ts

    Pipe a file through prettier via stdin and print formatted output

  • prettier src/index.ts --write=false

    Explicitly print formatted output to stdout without writing to disk

Formatting Options

  • prettier --write . --print-width=100

    Format files with a line wrap width of 100 characters

  • prettier --write . --print-width=120

    Format files with a line wrap width of 120 characters

  • prettier --write . --tab-width=2

    Format files using 2 spaces per indentation level

  • prettier --write . --tab-width=4

    Format files using 4 spaces per indentation level

  • prettier --write . --use-tabs

    Format files indenting with tabs instead of spaces

  • prettier --write . --no-use-tabs

    Format files indenting with spaces instead of tabs

  • prettier --write . --single-quote

    Format files using single quotes instead of double quotes

  • prettier --write . --no-single-quote

    Format files using double quotes instead of single quotes

  • prettier --write . --jsx-single-quote

    Format JSX attributes using single quotes

  • prettier --write . --no-jsx-single-quote

    Format JSX attributes using double quotes

  • prettier --write . --trailing-comma=all

    Add trailing commas wherever valid in ES5 and function parameters

  • prettier --write . --trailing-comma=es5

    Add trailing commas only where valid in ES5 syntax

  • prettier --write . --trailing-comma=none

    Remove all trailing commas from formatted output

  • prettier --write . --no-semi

    Format files omitting semicolons at the end of statements

  • prettier --write . --semi

    Format files adding semicolons at the end of statements

  • prettier --write . --bracket-spacing

    Print spaces between brackets in object literals

  • prettier --write . --no-bracket-spacing

    Omit spaces between brackets in object literals

  • prettier --write . --bracket-same-line

    Put the closing bracket of multiline JSX elements on the last line

  • prettier --write . --no-bracket-same-line

    Put the closing bracket of multiline JSX elements on a new line

  • prettier --write . --arrow-parens=always

    Always include parentheses around arrow function arguments

  • prettier --write . --arrow-parens=avoid

    Omit parentheses around single arrow function arguments when possible

  • prettier --write . --prose-wrap=always

    Wrap prose in Markdown and similar files at the print width

  • prettier --write . --prose-wrap=never

    Do not wrap prose in Markdown files regardless of line length

  • prettier --write . --prose-wrap=preserve

    Preserve the original wrapping of prose in Markdown files

  • prettier --write . --html-whitespace-sensitivity=css

    Respect CSS display property for HTML whitespace handling

  • prettier --write . --html-whitespace-sensitivity=strict

    Treat all whitespace as significant in HTML formatting

  • prettier --write . --html-whitespace-sensitivity=ignore

    Ignore all whitespace sensitivity in HTML formatting

  • prettier --write . --vue-indent-script-and-style

    Indent script and style blocks inside Vue single-file components

  • prettier --write . --no-vue-indent-script-and-style

    Do not indent script and style blocks inside Vue single-file components

  • prettier --write . --end-of-line=lf

    Format files using LF line endings

  • prettier --write . --end-of-line=crlf

    Format files using CRLF line endings

  • prettier --write . --end-of-line=cr

    Format files using CR line endings

  • prettier --write . --end-of-line=auto

    Maintain existing line endings in each file

  • prettier --write . --embedded-language-formatting=auto

    Format embedded code blocks in supported languages automatically

  • prettier --write . --embedded-language-formatting=off

    Disable formatting of embedded code blocks

  • prettier --write . --single-attribute-per-line

    Enforce one HTML or JSX attribute per line in multiline elements

  • prettier --write . --experimental-ternaries

    Format ternary expressions using the experimental curious ternary style

Parser & Language

  • prettier --write src/index.ts --parser=typescript

    Format a file explicitly using the TypeScript parser

  • prettier --write src/index.js --parser=babel

    Format a file explicitly using the Babel JavaScript parser

  • prettier --write src/index.jsx --parser=babel

    Format a JSX file explicitly using the Babel parser

  • prettier --write src/index.tsx --parser=babel-ts

    Format a TSX file explicitly using the Babel TypeScript parser

  • prettier --write src/style.css --parser=css

    Format a file explicitly using the CSS parser

  • prettier --write src/style.scss --parser=scss

    Format a file explicitly using the SCSS parser

  • prettier --write src/style.less --parser=less

    Format a file explicitly using the Less parser

  • prettier --write data.json --parser=json

    Format a file explicitly using the JSON parser

  • prettier --write data.json --parser=json5

    Format a file explicitly using the JSON5 parser

  • prettier --write README.md --parser=markdown

    Format a file explicitly using the Markdown parser

  • prettier --write docs/page.mdx --parser=mdx

    Format a file explicitly using the MDX parser

  • prettier --write index.html --parser=html

    Format a file explicitly using the HTML parser

  • prettier --write schema.graphql --parser=graphql

    Format a file explicitly using the GraphQL parser

  • prettier --write .prettierrc --parser=json

    Format a config file without an extension using the JSON parser

  • prettier --write config.yaml --parser=yaml

    Format a file explicitly using the YAML parser

Configuration

  • prettier --write . --config .prettierrc

    Format files using a specific Prettier configuration file

  • prettier --write . --config prettier.config.js

    Format files using a JavaScript Prettier configuration file

  • prettier --write . --no-config

    Format files ignoring any discovered configuration files

  • prettier --write . --config-precedence=prefer-file

    Prefer config file options over CLI options when both are present

  • prettier --write . --config-precedence=cli-override

    Let CLI options override config file options when both are present

  • prettier --write . --config-precedence=file-override

    Let config file options override CLI options entirely

  • prettier --find-config-path src/index.ts

    Print the path to the configuration file resolved for a given file

  • prettier --write . --editorconfig

    Apply options from .editorconfig when formatting files

  • prettier --write . --no-editorconfig

    Ignore .editorconfig settings when formatting files

  • prettier --write . --plugin=prettier-plugin-tailwindcss

    Format files using a specific Prettier plugin

  • prettier --write . --plugin=@prettier/plugin-php

    Format files using the Prettier PHP plugin

  • prettier --write . --plugin=prettier-plugin-svelte

    Format files using the Prettier Svelte plugin

Info & Debugging

  • prettier --version

    Display the currently installed version of Prettier

  • prettier --help

    Display help information and all available CLI options

  • prettier --support-info

    Print a list of all languages and file types Prettier supports

  • prettier --support-info --json

    Print supported languages and file types as JSON

  • prettier --file-info src/index.ts

    Show the parser and config that Prettier would use for a given file

  • prettier --file-info src/index.ts --json

    Show file info for a given file in JSON format

  • prettier --file-info src/index.ts --ignore-path .prettierignore

    Show file info using a specific ignore file

  • prettier --check . --log-level=debug

    Check formatting with verbose debug output for troubleshooting

CI & Integration

  • prettier --check . --ignore-path .gitignore

    Check formatting in CI using .gitignore as the ignore source

  • prettier --check "src/**/*.{ts,tsx,js,jsx}" --log-level=warn

    Check formatting of source files in CI showing only warnings and errors

  • prettier --write . --ignore-unknown --log-level=warn

    Format all files in CI skipping unknown types and reducing noise

  • prettier --check . --no-error-on-unmatched-pattern

    Check formatting without failing if a glob pattern matches no files

  • prettier --write "**/*.{ts,tsx,js,jsx,json,css,md}" --ignore-path .gitignore --log-level=warn

    Format all common file types in CI using gitignore and minimal logging