Skip to content

Commit

Permalink
Avoid depth counting when detecting indentation (#11947)
Browse files Browse the repository at this point in the history
## 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`
  • Loading branch information
dhruvmanila committed Jun 20, 2024
1 parent b617d90 commit a26bd01
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions crates/ruff_python_codegen/src/stylist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,16 @@ fn detect_indention(tokens: &[Token], locator: &Locator) -> Indentation {
// cos,
// )
// ```
let mut depth = 0usize;
for token in tokens {
match token.kind() {
TokenKind::Lpar | TokenKind::Lbrace | TokenKind::Lsqb => {
depth = depth.saturating_add(1);
}
TokenKind::Rpar | TokenKind::Rbrace | TokenKind::Rsqb => {
depth = depth.saturating_sub(1);
}
TokenKind::NonLogicalNewline => {
let line = locator.line(token.end());
let indent_index = line.find(|c: char| !c.is_whitespace());
if let Some(indent_index) = indent_index {
if indent_index > 0 {
let whitespace = &line[..indent_index];
return Indentation(whitespace.to_string());
}
if token.kind() == TokenKind::NonLogicalNewline {
let line = locator.line(token.end());
let indent_index = line.find(|c: char| !c.is_whitespace());
if let Some(indent_index) = indent_index {
if indent_index > 0 {
let whitespace = &line[..indent_index];
return Indentation(whitespace.to_string());
}
}
_ => {}
}
}

Expand Down

0 comments on commit a26bd01

Please sign in to comment.