mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-24 20:34:53 +00:00
Parenthesize numbers during attribute accesses (#3189)
This commit is contained in:
parent
32d165b7ad
commit
bda2a0007a
6 changed files with 60 additions and 153 deletions
|
@ -22,6 +22,9 @@ pub mod shared_traits;
|
|||
pub mod trivia;
|
||||
|
||||
pub fn fmt(contents: &str) -> Result<Formatted<ASTFormatContext>> {
|
||||
// Create a reusable locator.
|
||||
let locator = Locator::new(contents);
|
||||
|
||||
// Tokenize once.
|
||||
let tokens: Vec<LexResult> = ruff_rustpython::tokenize(contents);
|
||||
|
||||
|
@ -37,7 +40,7 @@ pub fn fmt(contents: &str) -> Result<Formatted<ASTFormatContext>> {
|
|||
// Attach trivia.
|
||||
attach(&mut python_cst, trivia);
|
||||
normalize_newlines(&mut python_cst);
|
||||
normalize_parentheses(&mut python_cst);
|
||||
normalize_parentheses(&mut python_cst, &locator);
|
||||
|
||||
format!(
|
||||
ASTFormatContext::new(
|
||||
|
@ -45,7 +48,7 @@ pub fn fmt(contents: &str) -> Result<Formatted<ASTFormatContext>> {
|
|||
indent_style: IndentStyle::Space(4),
|
||||
line_width: 88.try_into().unwrap(),
|
||||
},
|
||||
Locator::new(contents)
|
||||
locator,
|
||||
),
|
||||
[format::builders::block(&python_cst)]
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue