Skip to content

Commit a26bd01

Browse files
authored
Avoid depth counting when detecting indentation (#11947)
## Summary This PR avoids the `depth` counter when detecting indentation from non-logical lines because it seems to never be used. It might have been a leftover when the logic was added originally in #11608. ## Test Plan `cargo insta test`
1 parent b617d90 commit a26bd01

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

crates/ruff_python_codegen/src/stylist.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,16 @@ fn detect_indention(tokens: &[Token], locator: &Locator) -> Indentation {
9797
// cos,
9898
// )
9999
// ```
100-
let mut depth = 0usize;
101100
for token in tokens {
102-
match token.kind() {
103-
TokenKind::Lpar | TokenKind::Lbrace | TokenKind::Lsqb => {
104-
depth = depth.saturating_add(1);
105-
}
106-
TokenKind::Rpar | TokenKind::Rbrace | TokenKind::Rsqb => {
107-
depth = depth.saturating_sub(1);
108-
}
109-
TokenKind::NonLogicalNewline => {
110-
let line = locator.line(token.end());
111-
let indent_index = line.find(|c: char| !c.is_whitespace());
112-
if let Some(indent_index) = indent_index {
113-
if indent_index > 0 {
114-
let whitespace = &line[..indent_index];
115-
return Indentation(whitespace.to_string());
116-
}
101+
if token.kind() == TokenKind::NonLogicalNewline {
102+
let line = locator.line(token.end());
103+
let indent_index = line.find(|c: char| !c.is_whitespace());
104+
if let Some(indent_index) = indent_index {
105+
if indent_index > 0 {
106+
let whitespace = &line[..indent_index];
107+
return Indentation(whitespace.to_string());
117108
}
118109
}
119-
_ => {}
120110
}
121111
}
122112

0 commit comments

Comments
 (0)