Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ impl<'src> Lexer<'src> {
return Ok(());
}

let body_whitespace = &whitespace[..whitespace
let indentation = whitespace
.char_indices()
.take(self.indentation().chars().count())
.map(|(i, _c)| i)
.next()
.unwrap_or(0)];
.nth(self.indentation().chars().count())
.map_or(whitespace.len(), |(i, _c)| i);

let body_whitespace = &whitespace[..indentation];

let spaces = whitespace.chars().any(|c| c == ' ');
let tabs = whitespace.chars().any(|c| c == '\t');
Expand Down Expand Up @@ -2300,8 +2300,8 @@ mod tests {
offset: 12,
line: 3,
column: 0,
width: 3,
kind: InconsistentLeadingWhitespace{expected: "\t\t", found: "\t "},
width: 2,
kind: MixedLeadingWhitespace{whitespace: "\t "},
}

error! {
Expand Down
24 changes: 20 additions & 4 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,14 +861,14 @@ fn extra_leading_whitespace() {
#[test]
fn inconsistent_leading_whitespace() {
Test::new()
.justfile("bar:\n\t\techo hello\n\t echo goodbye")
.justfile("bar:\n\t\techo hello\n\techo goodbye")
.stderr(
"error: recipe line has inconsistent leading whitespace, \
started with `␉␉` but found line with `␉`
started with `␉␉` but found line with `␉`
——▶ justfile:3:1
3 │ echo goodbye
│ ^^^^^
3 │ echo goodbye
│ ^^^^
",
)
.failure();
Expand Down Expand Up @@ -2667,3 +2667,19 @@ fn windows_interpreter_path_no_base() {
)
.success();
}

#[test]
fn mixed_whitespace_in_recipe_body() {
Test::new()
.justfile("bar:\n echo a\n \techo b")
.stderr(
"error: found a mix of tabs and spaces in leading whitespace: `␠␉`
leading whitespace may consist of tabs or spaces, but not both
——▶ justfile:3:1
3 │ echo b
│ ^^^^^
",
)
.failure();
}
Loading