fmt
The rs fmt command formats files or checks whether they are formatted. For detailed usage, see Formatting.
Usage
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:
rs format is an alias for rs fmt:
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:
--check cannot be combined with --write or --list-different.
The command uses the following exit codes:
-h, --help
Display usage and option information without formatting files:
--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:
If config/format.ignore contains this rule:
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:
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:
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:
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:
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-filepathcannot 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:
--write cannot be combined with --check or --list-different.