mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 15:47:41 +00:00
Add formatter TOML configuration to the README (#7762)
## Summary This section is dated -- we now support configuration.
This commit is contained in:
parent
bdf285225d
commit
97c092a102
1 changed files with 18 additions and 9 deletions
|
@ -102,20 +102,29 @@ on-save by adding `"editor.formatOnSave": true` to your `settings.json`:
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
The Ruff formatter respects Ruff's [`line-length`](https://docs.astral.sh/ruff/settings/#line-length)
|
The Ruff formatter allows configuration of [indent style](https://docs.astral.sh/ruff/settings/#format-indent-style),
|
||||||
setting, which can be provided via a `pyproject.toml` or `ruff.toml` file, or on the CLI, as in:
|
[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
|
```console
|
||||||
ruff format --line-length 100 /path/to/file.py
|
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
|
### Excluding code from formatting
|
||||||
|
|
||||||
Ruff supports Black's `# fmt: off`, `# fmt: on`, and `# fmt: skip` pragmas, with a few caveats.
|
Ruff supports Black's `# fmt: off`, `# fmt: on`, and `# fmt: skip` pragmas, with a few caveats.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue