Linux command
prettier 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Format a file
prettier --write [file.js]
Format multiple files
prettier --write "[**/*.js]"
Check formatting
prettier --check [file.js]
Format with specific parser
prettier --parser [typescript] [file]
List files that differ
prettier --list-different "[**/*.js]"
Format with no semicolons
prettier --write --no-semi --single-quote [file.js]
说明
prettier is an opinionated code formatter that enforces a consistent style by parsing code and reprinting it with its own rules. It supports JavaScript, TypeScript, CSS, HTML, JSON, Markdown, YAML, GraphQL, and many other languages through plugins. The tool deliberately limits configuration options to minimize style debates in teams. Files can be formatted in place with --write or checked for conformance with --check, making it suitable for both local development and CI pipelines.
参数
- --write
- Edit files in place.
- --check
- Check if formatted.
- --parser _NAME_
- Force parser.
- --config _FILE_
- Config file path.
- --single-quote
- Use single quotes.
- --tab-width _N_
- Spaces per indentation level (default: 2).
- --print-width _N_
- Line length to wrap at (default: 80).
- --trailing-comma _MODE_
- Trailing commas: all, es5, or none (default: all).
- --no-semi
- Do not print semicolons.
- --use-tabs
- Indent with tabs instead of spaces.
- --list-different, -l
- Print filenames of files that differ from formatting.
- --no-config
- Do not look for a configuration file.
- --ignore-unknown, -u
- Ignore unknown files matched by patterns.
- --prose-wrap _MODE_
- Wrapping in markdown: always, never, or preserve (default: preserve).
FAQ
What is the prettier command used for?
prettier is an opinionated code formatter that enforces a consistent style by parsing code and reprinting it with its own rules. It supports JavaScript, TypeScript, CSS, HTML, JSON, Markdown, YAML, GraphQL, and many other languages through plugins. The tool deliberately limits configuration options to minimize style debates in teams. Files can be formatted in place with --write or checked for conformance with --check, making it suitable for both local development and CI pipelines.
How do I run a basic prettier example?
Run `prettier --write [file.js]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --write do in prettier?
Edit files in place.