Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the LinterSettings's tab size when expanding indent #9506

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/ruff_linter/src/checkers/logical_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ use crate::rules::pycodestyle::rules::logical_lines::{
use crate::settings::LinterSettings;

/// Return the amount of indentation, expanding tabs to the next multiple of 8.
hoel-bagard marked this conversation as resolved.
Show resolved Hide resolved
fn expand_indent(line: &str) -> usize {
fn expand_indent(line: &str, settings: &LinterSettings) -> usize {
let line = line.trim_end_matches(['\n', '\r']);

let mut indent = 0;
let tab_size = settings.tab_size.as_usize();
for c in line.bytes() {
match c {
b'\t' => indent = (indent / 8) * 8 + 8,
b'\t' => indent = (indent / tab_size) * tab_size + tab_size,
b' ' => indent += 1,
_ => break,
}
Expand Down Expand Up @@ -84,7 +85,7 @@ pub(crate) fn check_logical_lines(
TextRange::new(locator.line_start(first_token.start()), first_token.start())
};

let indent_level = expand_indent(locator.slice(range));
let indent_level = expand_indent(locator.slice(range), settings);

let indent_size = 4;

Expand Down
Loading