Rollup merge of #154213 - scrabsha:push-znnnnwtwxntz, r=WaffleLapkin

tidy-alphabetical: fix line number in error message
This commit is contained in:
Jonathan Brouwer
2026-04-02 22:13:53 +02:00
committed by GitHub
2 changed files with 15 additions and 11 deletions
+5 -1
View File
@@ -215,7 +215,11 @@ fn check_lines<'a>(path: &Path, content: &'a str, tidy_ctx: &TidyCtx, check: &mu
// oh nyooo :(
if sorted != section {
if !tidy_ctx.is_bless_enabled() {
let base_line_number = content[..offset + start_nl_end].lines().count();
let pre = &content[..offset + start_nl_end];
assert_eq!(pre.chars().rev().next(), Some('\n'));
// start_nl_end spans right after the ␤, so it gets ignored by `lines()`,
// but we do want to count it! so we add 1 to the result.
let base_line_number = pre.lines().count() + 1;
let line_offset = sorted
.lines()
.zip(section.lines())
+10 -10
View File
@@ -115,7 +115,7 @@ fn test_rust_bad() {
def
// tidy-alphabetical-end
";
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
}
#[test]
@@ -127,7 +127,7 @@ fn test_toml_bad() {
def
# tidy-alphabetical-end
";
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
}
#[test]
@@ -141,7 +141,7 @@ fn test_features_bad() {
#![feature(def)]
tidy-alphabetical-end
";
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
}
#[test]
@@ -154,7 +154,7 @@ fn test_indent_bad() {
def
$ tidy-alphabetical-end
";
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
}
#[test]
@@ -170,7 +170,7 @@ fn test_split_bad() {
)
&& tidy-alphabetical-end
";
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:4: line not in alphabetical order (tip: use --bless to sort this list)");
}
#[test]
@@ -339,7 +339,7 @@ fn test_numeric_bad() {
item2
# tidy-alphabetical-end
";
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:3: line not in alphabetical order (tip: use --bless to sort this list)");
let lines = "\
# tidy-alphabetical-start
@@ -347,7 +347,7 @@ fn test_numeric_bad() {
zve64d
# tidy-alphabetical-end
";
bad(lines, "bad:1: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
let lines = "\
# tidy-alphabetical-start
@@ -355,7 +355,7 @@ fn test_numeric_bad() {
00
# tidy-alphabetical-end
";
bad(lines, "bad:1: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
}
#[test]
@@ -394,7 +394,7 @@ fn multiline() {
);
tidy-alphabetical-end
";
bad(lines, "bad:1: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
let lines = "\
tidy-alphabetical-start
@@ -406,7 +406,7 @@ fn multiline() {
a);
tidy-alphabetical-end
";
bad(lines, "bad:1: line not in alphabetical order (tip: use --bless to sort this list)");
bad(lines, "bad:2: line not in alphabetical order (tip: use --bless to sort this list)");
let lines = "\
force_unwind_tables: Option<bool> = (None, parse_opt_bool, [TRACKED],