Skip to content

Commit

Permalink
Error when else is used without @ (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-fairy authored Jan 7, 2025
1 parent 678d62b commit 1f76200
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions maud/tests/warnings/keyword-without-at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ use maud::html;
fn main() {
html! {
if {}
else {}
for {}
while {}
match {}
};
}
36 changes: 34 additions & 2 deletions maud/tests/warnings/keyword-without-at.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
error: found keyword `if`
--> $DIR/keyword-without-at.rs:5:9
--> tests/warnings/keyword-without-at.rs:5:9
|
5 | if {}
| ^^
|
= help: should this be a `@if`?
= help: should this be `@if`?

error: found keyword `else`
--> tests/warnings/keyword-without-at.rs:6:9
|
6 | else {}
| ^^^^
|
= help: should this be `@else`?

error: found keyword `for`
--> tests/warnings/keyword-without-at.rs:7:9
|
7 | for {}
| ^^^
|
= help: should this be `@for`?

error: found keyword `while`
--> tests/warnings/keyword-without-at.rs:8:9
|
8 | while {}
| ^^^^^
|
= help: should this be `@while`?

error: found keyword `match`
--> tests/warnings/keyword-without-at.rs:9:9
|
9 | match {}
| ^^^^^
|
= help: should this be `@match`?
3 changes: 2 additions & 1 deletion maud_macros/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl<E: MaybeElement> Markup<E> {
) -> syn::Result<Self> {
if input.peek(Let)
|| input.peek(If)
|| input.peek(Else)
|| input.peek(For)
|| input.peek(While)
|| input.peek(Match)
Expand All @@ -68,7 +69,7 @@ impl<E: MaybeElement> Markup<E> {
diagnostics.push(
kw.span()
.error(format!("found keyword `{kw}`"))
.help(format!("should this be a `@{kw}`?")),
.help(format!("should this be `@{kw}`?")),
);
}

Expand Down

0 comments on commit 1f76200

Please sign in to comment.