Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ruff-format"
version = "0.5.0"
version = "0.5.1"
edition = "2024"
license = "MIT"
readme = "README.md"
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,26 @@ pip install ruff-format
## Usage

```python
from ruff_format import format_string, is_valid_syntax
from ruff_format import format_string, is_valid_syntax, parse_code

code = """
def hello( x,y, z ):
print( x+y+z )
"""

# Check if code has valid syntax
assert is_valid_syntax(code)

# Parse code (raises RuntimeError on syntax errors)
parse_code(code)

# Format code (default line width: 80)
formatted = format_string(code)
print(formatted)

# Format with a custom line width
formatted = format_string(code, line_width=120)
print(formatted)
```

## Development
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build-backend = "maturin"

[project]
name = "ruff-format"
description = "Python bindings for the Ruff code formatter, built with Rust and PyO3."
requires-python = ">=3.8"
license = { text = "MIT" }
classifiers = [
Expand Down
2 changes: 1 addition & 1 deletion ruff_format.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def is_valid_syntax(code: str) -> bool:
True if the code has valid syntax, False otherwise.
"""

def format_string(code: str, *, line_width: int) -> str:
def format_string(code: str, *, line_width: int = 80) -> str:
"""Format a Python code string using Ruff.

Args:
Expand Down
Loading