mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 21:15:19 +00:00
Create PyFormatOptions
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary This PR adds a new `PyFormatOptions` struct that stores the python formatter options. The new options aren't used yet, with the exception of magical trailing commas and the options passed to the printer. I'll follow up with more PRs that use the new options (e.g. `QuoteStyle`). <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan `cargo test` I'll follow up with a new PR that adds support for overriding the options in our fixture tests.
This commit is contained in:
parent
a52cd47c7f
commit
dd0d1afb66
10 changed files with 170 additions and 88 deletions
|
@ -188,7 +188,8 @@ mod tests {
|
|||
use crate::comments::Comments;
|
||||
use crate::prelude::*;
|
||||
use crate::statement::suite::SuiteLevel;
|
||||
use ruff_formatter::{format, IndentStyle, SimpleFormatOptions};
|
||||
use crate::PyFormatOptions;
|
||||
use ruff_formatter::format;
|
||||
use rustpython_parser::ast::Suite;
|
||||
use rustpython_parser::Parse;
|
||||
|
||||
|
@ -216,14 +217,7 @@ def trailing_func():
|
|||
|
||||
let statements = Suite::parse(source, "test.py").unwrap();
|
||||
|
||||
let context = PyFormatContext::new(
|
||||
SimpleFormatOptions {
|
||||
indent_style: IndentStyle::Space(4),
|
||||
..SimpleFormatOptions::default()
|
||||
},
|
||||
source,
|
||||
Comments::default(),
|
||||
);
|
||||
let context = PyFormatContext::new(PyFormatOptions::default(), source, Comments::default());
|
||||
|
||||
let test_formatter =
|
||||
format_with(|f: &mut PyFormatter| statements.format().with_options(level).fmt(f));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue