Skip to content

yx format ​

Format YaoXiang source code, unifying code style.

Usage ​

yx format [OPTIONS] <PATH>

Arguments ​

ArgumentDescription
PATHSource file or directory to format

Options ​

OptionDescriptionDefault
-n, --dry-runDry run: show formatting diff, do not write backNo
-w, --writeWrite formatting result in placeNo
--stdoutOutput to standard output (default when -n/-w not specified)--
--no-verifySkip verification after formatting (performance optimization)No
--indent <N>Override indent widthConfig value
--line-width <N>Override max line widthConfig value
--use-tabsUse Tab indentationConfig value
--single-quoteUse single quotes for stringsConfig value

Configuration Priority ​

Formatting options take effect in the following priority order (highest first):

  1. Command line flags
  2. Formatting configuration in project config yaoxiang.toml
  3. User-level configuration file

For configuration items and default values, see Formatter Configuration Design.

Exit Codes ​

Exit codeDescription
0Success (including cases where no formatting is needed)
2Files needing formatting found under --dry-run, or no .yx files found
1Other errors

Examples ​

bash
# Format and output to standard output (default)
yx format src/main.yx

# Write in place
yx format -w src/

# CI check: fail with exit code 2 when files need formatting
yx format -n .

# Temporarily override indent and line width
yx format --indent 4 --line-width 100 main.yx

CI Integration ​

yaml
# GitHub Actions
- name: Format check
  run: yx format --dry-run .

Exit code 2 indicates files that need formatting. For detailed CI configuration, see the CI Integration Guide.

See Also ​