Add target_version to formatter options (#9220)

This commit is contained in:
Micha Reiser 2023-12-21 13:05:58 +09:00 committed by GitHub
parent ef4bd8d5ff
commit 8cb7950102
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 103 additions and 10 deletions

View file

@ -175,6 +175,14 @@ impl Configuration {
let formatter = FormatterSettings {
exclude: FilePatternSet::try_from_iter(format.exclude.unwrap_or_default())?,
preview: format_preview,
target_version: match target_version {
PythonVersion::Py37 => ruff_python_formatter::PythonVersion::Py37,
PythonVersion::Py38 => ruff_python_formatter::PythonVersion::Py38,
PythonVersion::Py39 => ruff_python_formatter::PythonVersion::Py39,
PythonVersion::Py310 => ruff_python_formatter::PythonVersion::Py310,
PythonVersion::Py311 => ruff_python_formatter::PythonVersion::Py311,
PythonVersion::Py312 => ruff_python_formatter::PythonVersion::Py312,
},
line_width: self
.line_length
.map_or(format_defaults.line_width, |length| {

View file

@ -117,6 +117,7 @@ impl FileResolverSettings {
pub struct FormatterSettings {
pub exclude: FilePatternSet,
pub preview: PreviewMode,
pub target_version: ruff_python_formatter::PythonVersion,
pub line_width: LineWidth,
@ -157,6 +158,7 @@ impl FormatterSettings {
};
PyFormatOptions::from_source_type(source_type)
.with_target_version(self.target_version)
.with_indent_style(self.indent_style)
.with_indent_width(self.indent_width)
.with_quote_style(self.quote_style)
@ -175,6 +177,7 @@ impl Default for FormatterSettings {
Self {
exclude: FilePatternSet::default(),
target_version: default_options.target_version(),
preview: PreviewMode::Disabled,
line_width: default_options.line_width(),
line_ending: LineEnding::Auto,