mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 12:25:10 +00:00
Use ast::PythonVersion internally in the formatter and linter (#16170)
## Summary This PR updates the formatter and linter to use the `PythonVersion` struct from the `ruff_python_ast` crate internally. While this doesn't remove the need for the `linter::PythonVersion` enum, it does remove the `formatter::PythonVersion` enum and limits the use in the linter to deserializing from CLI arguments and config files and moves most of the remaining methods to the `ast::PythonVersion` struct. ## Test Plan Existing tests, with some inputs and outputs updated to reflect the new (de)serialization format. I think these are test-specific and shouldn't affect any external (de)serialization. --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
0868e73d2c
commit
a9efdea113
153 changed files with 456 additions and 539 deletions
|
|
@ -26,8 +26,9 @@ fn black_compatibility() {
|
|||
|
||||
let options: PyFormatOptions = if let Ok(options_file) = fs::File::open(&options_path) {
|
||||
let reader = BufReader::new(options_file);
|
||||
serde_json::from_reader(reader)
|
||||
.unwrap_or_else(|_| panic!("Option file {options_path:?} to be a valid Json file"))
|
||||
serde_json::from_reader(reader).unwrap_or_else(|_| {
|
||||
panic!("Expected option file {options_path:?} to be a valid Json file")
|
||||
})
|
||||
} else {
|
||||
PyFormatOptions::from_extension(input_path)
|
||||
};
|
||||
|
|
@ -180,10 +181,12 @@ fn format() {
|
|||
let mut snapshot = format!("## Input\n{}", CodeFrame::new("python", &content));
|
||||
let options_path = input_path.with_extension("options.json");
|
||||
|
||||
if let Ok(options_file) = fs::File::open(options_path) {
|
||||
if let Ok(options_file) = fs::File::open(&options_path) {
|
||||
let reader = BufReader::new(options_file);
|
||||
let options: Vec<PyFormatOptions> =
|
||||
serde_json::from_reader(reader).expect("Options to be a valid Json file");
|
||||
serde_json::from_reader(reader).unwrap_or_else(|_| {
|
||||
panic!("Expected option file {options_path:?} to be a valid Json file")
|
||||
});
|
||||
|
||||
writeln!(snapshot, "## Outputs").unwrap();
|
||||
|
||||
|
|
@ -473,7 +476,7 @@ magic-trailing-comma = {magic_trailing_comma:?}
|
|||
docstring-code = {docstring_code:?}
|
||||
docstring-code-line-width = {docstring_code_line_width:?}
|
||||
preview = {preview:?}
|
||||
target_version = {target_version:?}
|
||||
target_version = {target_version}
|
||||
source_type = {source_type:?}"#,
|
||||
indent_style = self.0.indent_style(),
|
||||
indent_width = self.0.indent_width().value(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue