Skip to content

yx format ​

Format YaoXiang source code and unify code style.

Usage ​

yx format [OPTIONS] <PATH>

Arguments ​

ArgumentDescription
PATHSource file or directory to format

Options ​

OptionDescriptionDefault
-n, --dry-runDry run: show formatting diffs without writing backNo
-w, --writeWrite formatting result back in placeNo
--stdoutOutput to standard output (default behavior when -n/-w is not specified)--
--no-verifySkip post-format verification (performance optimization)No
--indent <N>Override indent widthConfig value
--line-width <N>Override maximum line widthConfig value
--use-tabsUse Tab for indentationConfig value
--single-quoteUse single quotes for stringsConfig value

Configuration Priority ​

Formatting options take effect in the following priority (higher takes precedence):

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

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

Exit Codes ​

CodeDescription
0Success (including when 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 back 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 CI Integration Guide.

See Also ​