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

@ -10,7 +10,7 @@ use rustpython_parser::{parse_tokens, Mode};
use ruff_formatter::SourceCode;
use ruff_python_ast::source_code::CommentRangesBuilder;
use crate::format_node;
use crate::{format_node, PyFormatOptions};
#[derive(ValueEnum, Clone, Debug)]
pub enum Emit {
@ -57,7 +57,12 @@ pub fn format_and_debug_print(input: &str, cli: &Cli) -> Result<String> {
let python_ast = parse_tokens(tokens, Mode::Module, "<filename>")
.with_context(|| "Syntax error in input")?;
let formatted = format_node(&python_ast, &comment_ranges, input)?;
let formatted = format_node(
&python_ast,
&comment_ranges,
input,
PyFormatOptions::default(),
)?;
if cli.print_ir {
println!("{}", formatted.document().display(SourceCode::new(input)));
}