mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 04:55:09 +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
|
@ -255,6 +255,7 @@ mod tests {
|
|||
use ruff_python_index::CommentRangesBuilder;
|
||||
use ruff_python_parser::lexer::lex;
|
||||
use ruff_python_parser::{parse_tokens, Mode};
|
||||
use std::path::Path;
|
||||
|
||||
/// Very basic test intentionally kept very similar to the CLI
|
||||
#[test]
|
||||
|
@ -321,15 +322,10 @@ with [
|
|||
let comment_ranges = comment_ranges.finish();
|
||||
|
||||
// Parse the AST.
|
||||
let python_ast = parse_tokens(tokens, Mode::Module, "<filename>").unwrap();
|
||||
|
||||
let formatted = format_node(
|
||||
&python_ast,
|
||||
&comment_ranges,
|
||||
src,
|
||||
PyFormatOptions::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let source_path = "code_inline.py";
|
||||
let python_ast = parse_tokens(tokens, Mode::Module, source_path).unwrap();
|
||||
let options = PyFormatOptions::from_extension(Path::new(source_path));
|
||||
let formatted = format_node(&python_ast, &comment_ranges, src, options).unwrap();
|
||||
|
||||
// Uncomment the `dbg` to print the IR.
|
||||
// Use `dbg_write!(f, []) instead of `write!(f, [])` in your formatting code to print some IR
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue