mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:45:24 +00:00
Introduce FormatterSettings
(#7545)
This commit is contained in:
parent
87a0cd219f
commit
f8f1cd5016
16 changed files with 159 additions and 75 deletions
|
@ -1,12 +1,10 @@
|
|||
use std::io::{stdout, Write};
|
||||
use std::num::NonZeroU16;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
use log::warn;
|
||||
use ruff_formatter::LineWidth;
|
||||
use ruff_linter::settings::types::PreviewMode;
|
||||
|
||||
use ruff_python_ast::PySourceType;
|
||||
use ruff_python_formatter::{format_module, PyFormatOptions};
|
||||
use ruff_workspace::resolver::python_file_at_path;
|
||||
|
||||
|
@ -39,18 +37,10 @@ pub(crate) fn format_stdin(cli: &FormatArguments, overrides: &CliOverrides) -> R
|
|||
// Format the file.
|
||||
let path = cli.stdin_filename.as_deref();
|
||||
|
||||
// TODO(micha): Use Formatter settings
|
||||
let preview = match pyproject_config.settings.linter.preview {
|
||||
PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled,
|
||||
PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled,
|
||||
};
|
||||
let line_length = pyproject_config.settings.linter.line_length;
|
||||
|
||||
let options = path
|
||||
.map(PyFormatOptions::from_extension)
|
||||
.unwrap_or_default()
|
||||
.with_line_width(LineWidth::from(NonZeroU16::from(line_length)))
|
||||
.with_preview(preview);
|
||||
let options = pyproject_config
|
||||
.settings
|
||||
.formatter
|
||||
.to_format_options(path.map(PySourceType::from).unwrap_or_default());
|
||||
|
||||
match format_source(path, options, mode) {
|
||||
Ok(result) => match mode {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue