Skip to content

Commit f815858

Browse files
committed
Use correct offset when unindenting code block
When using hard tabs, we should only remove '\t'.
1 parent 526367a commit f815858

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,12 @@ pub fn format_code_block(code_snippet: &str, config: &Config) -> Option<String>
571571
let indent_str =
572572
Indent::from_width(config, config.tab_spaces()).to_string(config);
573573
if line.starts_with(indent_str.as_ref()) {
574-
&line[config.tab_spaces()..]
574+
let offset = if config.hard_tabs() {
575+
1
576+
} else {
577+
config.tab_spaces()
578+
};
579+
&line[offset..]
575580
} else {
576581
line
577582
}

tests/target/issue-2401.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// rustfmt-hard_tabs = true
2+
// rustfmt-normalize_comments = true
3+
4+
/// ```
5+
/// println!("Hello, World!");
6+
/// ```
7+
fn main() {}

0 commit comments

Comments
 (0)