For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/cli/fmt.md.
  • English
  • fmt

    The rs fmt command formats files or checks whether they are formatted. For detailed usage, see Formatting.

    Usage

    rs fmt [options] [files/globs...]

    Pass files, directories, or glob patterns to choose what to format. When no paths are provided, rs fmt formats the current directory. See Formatting scope for path resolution and ignore rules.

    Examples:

    # Format files in the current directory
    rs fmt
    
    # Format specific files and directories
    rs fmt src package.json
    
    # Check formatting in CI
    rs fmt --check

    rs format is an alias for rs fmt:

    rs format

    Options

    --check

    Check whether files are formatted without changing them. The output lists files with formatting issues and includes a human-friendly summary, making this option useful in CI:

    rs fmt . --check

    --check cannot be combined with --write or --list-different.

    The command uses the following exit codes:

    CodeMeaning
    0All matched files are formatted.
    1One or more matched files have formatting issues.
    2rs fmt could not run or encountered a formatting error.

    -h, --help

    Display usage and option information without formatting files:

    rs fmt --help

    --ignore-path <path>

    Use --ignore-path to load additional Gitignore-compatible rules from a file.

    Relative ignore-file paths are resolved from the current working directory. Rules inside a file are resolved from the directory containing that file.

    For example, run the following command from the project root:

    rs fmt --ignore-path config/format.ignore

    If config/format.ignore contains this rule:

    config/format.ignore
    generated/**

    Here, config/format.ignore is located relative to the project root. The generated/** rule is relative to config/. It therefore ignores config/generated/** instead of generated/** in the project root.

    Loaded rules apply to scanned paths, explicitly passed files, and --stdin-filepath.

    To load multiple ignore files, repeat the option:

    rs fmt --ignore-path .prettierignore --ignore-path config/format.ignore

    Each file acts as a separate ignore source. See Ignore order for how these sources combine with .gitignore, default ignore rules, and ignorePatterns.

    --list-different

    Print the paths of unformatted files without the summary produced by --check. This is useful when another command needs to consume the output:

    rs fmt . --list-different

    The option uses the same exit codes as --check and cannot be combined with --write or --check.

    --parallel-workers <count>

    Set the maximum number of formatting workers to a positive integer:

    rs fmt . --parallel-workers 4

    When this option is omitted, rs fmt automatically chooses up to eight workers based on the available CPU parallelism and the number of matched files. Set a lower value to limit CPU or memory usage in constrained environments.

    --stdin-filepath <path>

    Format content received from stdin as if it were saved at <path>, for example when integrating with an editor. The path determines the parser and matching configuration overrides, but it does not need to exist on disk:

    cat src/index.ts | rs fmt --stdin-filepath src/index.ts

    Formatted output is written to stdout and diagnostics to stderr. If the input path is ignored, rs fmt skips formatting and writes the input unchanged. If it cannot infer a parser from the path or parse the content, it reports an error and exits with code 2.

    --stdin-filepath cannot be combined with file arguments or with --write, --check, or --list-different.

    --write

    Write formatted files in place. This is the default mode, so specifying --write is optional:

    rs fmt src --write

    --write cannot be combined with --check or --list-different.