Skip to content

Commit

Permalink
Use the LinterSettings's tab size when expanding indent (#9506)
Browse files Browse the repository at this point in the history
## Summary
In the `logical_lines`'s `expand_indent` , respect the
`LinterSettings::tab_size` setting instead of hardcoding the size of
tabs to 8.

Also see [this
conversation](#9266 (comment))

## Test Plan

Tested by running `cargo test`
  • Loading branch information
hoel-bagard authored Jan 14, 2024
1 parent ef2798f commit e8d7a6d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions crates/ruff_linter/src/checkers/logical_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ use crate::rules::pycodestyle::rules::logical_lines::{
};
use crate::settings::LinterSettings;

/// Return the amount of indentation, expanding tabs to the next multiple of 8.
fn expand_indent(line: &str) -> usize {
/// Return the amount of indentation, expanding tabs to the next multiple of the settings' tab size.
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

0 comments on commit e8d7a6d

Please # to comment.