From 792369a357e0dc008bb1869c2066956aa3d5e4ad Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 2 Oct 2023 10:49:16 -0400 Subject: [PATCH] Add formatter TOML configuration to the README --- crates/ruff_python_formatter/README.md | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/crates/ruff_python_formatter/README.md b/crates/ruff_python_formatter/README.md index 4f5806a5d527a..b6cf97cc6e121 100644 --- a/crates/ruff_python_formatter/README.md +++ b/crates/ruff_python_formatter/README.md @@ -102,20 +102,29 @@ on-save by adding `"editor.formatOnSave": true` to your `settings.json`: ### Configuration -The Ruff formatter respects Ruff's [`line-length`](https://docs.astral.sh/ruff/settings/#line-length) -setting, which can be provided via a `pyproject.toml` or `ruff.toml` file, or on the CLI, as in: +The Ruff formatter allows configuration of [indent style](https://docs.astral.sh/ruff/settings/#format-indent-style), +[line ending](https://docs.astral.sh/ruff/settings/#format-line-ending), [quote style](https://docs.astral.sh/ruff/settings/#format-quote-style), +and [magic trailing comma behavior](https://docs.astral.sh/ruff/settings/#format-skip-magic-trailing-comma). +Like the linter, the Ruff formatter reads configuration via `pyproject.toml` or `ruff.toml` files, +as in: + +```toml +[tool.ruff.format] +# Use tabs instead of 4 space indentation +indent-style = "tab" + +# Prefer single quotes over double quotes +quote-style = "single" +``` + +The Ruff formatter also respects Ruff's [`line-length`](https://docs.astral.sh/ruff/settings/#line-length) +setting, which also can be provided via a `pyproject.toml` or `ruff.toml` file, or on the CLI, as +in: ```console ruff format --line-length 100 /path/to/file.py ``` -In future releases, the Ruff formatter will likely support configuration of: - -- Quote style (single vs. double). -- Line endings (LF vs. CRLF). -- Indentation (tabs vs. spaces). -- Tab width. - ### Excluding code from formatting Ruff supports Black's `# fmt: off`, `# fmt: on`, and `# fmt: skip` pragmas, with a few caveats.