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

@ -11,7 +11,7 @@ use ruff::resolver::python_files_in_path;
use ruff::settings::types::{FilePattern, FilePatternSet};
use ruff_cli::args::CheckArgs;
use ruff_cli::resolve::resolve;
use ruff_python_formatter::format_module;
use ruff_python_formatter::{format_module, PyFormatOptions};
use similar::{ChangeTag, TextDiff};
use std::io::Write;
use std::panic::catch_unwind;
@ -276,7 +276,7 @@ impl From<anyhow::Error> for FormatterStabilityError {
/// Run the formatter twice on the given file. Does not write back to the file
fn check_file(input_path: &Path) -> Result<(), FormatterStabilityError> {
let content = fs::read_to_string(input_path).context("Failed to read file")?;
let printed = match format_module(&content) {
let printed = match format_module(&content, PyFormatOptions::default()) {
Ok(printed) => printed,
Err(err) => {
return if err
@ -296,7 +296,7 @@ fn check_file(input_path: &Path) -> Result<(), FormatterStabilityError> {
};
let formatted = printed.as_code();
let reformatted = match format_module(formatted) {
let reformatted = match format_module(formatted, PyFormatOptions::default()) {
Ok(reformatted) => reformatted,
Err(err) => {
return Err(FormatterStabilityError::InvalidSyntax {