From a26bd01be2b673f13cb6c88f4150dd12e5873f55 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Thu, 20 Jun 2024 10:42:35 +0530 Subject: [PATCH] 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` --- crates/ruff_python_codegen/src/stylist.rs | 24 +++++++---------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/crates/ruff_python_codegen/src/stylist.rs b/crates/ruff_python_codegen/src/stylist.rs index d5a1ea53cd..c2d4701fa7 100644 --- a/crates/ruff_python_codegen/src/stylist.rs +++ b/crates/ruff_python_codegen/src/stylist.rs @@ -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()); } } - _ => {} } }