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:
Micha Reiser 2023-06-26 14:02:17 +02:00 committed by GitHub
parent a52cd47c7f
commit dd0d1afb66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 170 additions and 88 deletions

View file

@ -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));