Skip to content

Latest commit

 

History

History
43 lines (26 loc) · 1.21 KB

File metadata and controls

43 lines (26 loc) · 1.21 KB

Ruff-formatter Extension For Quarto

A Quarto filter to format the Python code using ruff

Installing

quarto add PythonCharmers/ruff-formatter

This will install the extension under the _extensions subdirectory. If you're using version control, you will want to check in this directory.

Make sure ruff is installed. See here for installation instructions.

Using

Add the filter in your Quarto document like this:

---
filters:
  - ruff-formatter
---

It is possible to configure ruff via a pyproject.toml or ruff.toml file: see here.

For example, suppose you want to use 80 characters per line i.e. --line-length=80. (Ruff defaults to 88 character per line.) You can specify the following in the pyproject.toml file under [tool.ruff],

[tool.ruff]
line-length = 80

And then place this toml file in the same directory as the qmd file of the Python code chunks you want to format.

Credits

Thanks to Shafayet Shafee for his Black formatter for Quarto for inspiration!