mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Formatter: Add SourceType to context to enable special formatting for stub files (#6331)
**Summary** This adds the information whether we're in a .py python source file or in a .pyi stub file to enable people working on #5822 and related issues. I'm not completely happy with `Default` for something that depends on the input. **Test Plan** None, this is currently unused, i'm leaving this to first implementation of stub file specific formatting. --------- Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
fe97a2a302
commit
1031bb6550
12 changed files with 137 additions and 97 deletions
|
@ -17,7 +17,7 @@ fn black_compatibility() {
|
|||
let reader = BufReader::new(options_file);
|
||||
serde_json::from_reader(reader).expect("Options to be a valid Json file")
|
||||
} else {
|
||||
PyFormatOptions::default()
|
||||
PyFormatOptions::from_extension(input_path)
|
||||
};
|
||||
|
||||
let printed = format_module(&content, options.clone()).unwrap_or_else(|err| {
|
||||
|
@ -106,11 +106,11 @@ fn format() {
|
|||
let test_file = |input_path: &Path| {
|
||||
let content = fs::read_to_string(input_path).unwrap();
|
||||
|
||||
let options = PyFormatOptions::default();
|
||||
let options = PyFormatOptions::from_extension(input_path);
|
||||
let printed = format_module(&content, options.clone()).expect("Formatting to succeed");
|
||||
let formatted_code = printed.as_code();
|
||||
|
||||
ensure_stability_when_formatting_twice(formatted_code, options, input_path);
|
||||
ensure_stability_when_formatting_twice(formatted_code, options.clone(), input_path);
|
||||
|
||||
let mut snapshot = format!("## Input\n{}", CodeFrame::new("py", &content));
|
||||
|
||||
|
@ -139,7 +139,6 @@ fn format() {
|
|||
.unwrap();
|
||||
}
|
||||
} else {
|
||||
let options = PyFormatOptions::default();
|
||||
let printed = format_module(&content, options.clone()).expect("Formatting to succeed");
|
||||
let formatted_code = printed.as_code();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue