Skip to content

Commit a76109c

Browse files
authored
cli: display syntax errors as errors, not warnings part 2 (#502)
We were showing warning for everything and then using the error level for highlighting the error. Now we set the level correctly!
1 parent 300a5c2 commit a76109c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

crates/squawk/src/reporter.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,16 @@ fn render_lint_error<W: std::io::Write>(
8686

8787
let title = &err.message;
8888

89-
let mut message = Level::Warning.title(title).id(error_name).snippet(
89+
let level = match err.level {
90+
ViolationLevel::Warning => Level::Warning,
91+
ViolationLevel::Error => Level::Error,
92+
};
93+
94+
let mut message = level.title(title).id(error_name).snippet(
9095
Snippet::source(sql)
9196
.origin(filename)
9297
.fold(true)
93-
.annotation(Level::Error.span(err.range.into())),
98+
.annotation(level.span(err.range.into())),
9499
);
95100
if let Some(help) = &err.help {
96101
message = message.footer(Level::Help.title(help));

crates/squawk/src/snapshots/squawk__reporter__test_reporter__display_violations_tty.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
---
2-
source: crates/cli/src/reporter.rs
2+
source: crates/squawk/src/reporter.rs
33
expression: "strip_ansi_codes(&String::from_utf8_lossy(&buff))"
44
---
55
warning[adding-required-field]: Adding a new column that is `NOT NULL` and has no default value to an existing table effectively makes it required.
66
--> main.sql:2:30
77
|
88
2 | ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
9-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9+
| ---------------------------------
1010
|
1111
= help: Make the field nullable or add a non-VOLATILE DEFAULT
1212
warning[prefer-robust-stmts]: Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.
1313
--> main.sql:2:30
1414
|
1515
2 | ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
| ---------------------------------
1717
|
1818
warning[prefer-bigint-over-int]: Using 32-bit integer fields can result in hitting the max `int` limit.
1919
--> main.sql:2:47
2020
|
2121
2 | ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
22-
| ^^^^^^^
22+
| -------
2323
|
2424
= help: Use 64-bit integer values instead to prevent hitting this limit.
2525
warning[adding-required-field]: Adding a new column that is `NOT NULL` and has no default value to an existing table effectively makes it required.
2626
--> main.sql:3:24
2727
|
2828
3 | ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
| ---------------------------------
3030
|
3131
= help: Make the field nullable or add a non-VOLATILE DEFAULT
3232
warning[prefer-robust-stmts]: Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.
3333
--> main.sql:3:24
3434
|
3535
3 | ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
36-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
| ---------------------------------
3737
|
3838
warning[prefer-bigint-over-int]: Using 32-bit integer fields can result in hitting the max `int` limit.
3939
--> main.sql:3:41
4040
|
4141
3 | ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
42-
| ^^^^^^^
42+
| -------
4343
|
4444
= help: Use 64-bit integer values instead to prevent hitting this limit.
4545

0 commit comments

Comments
 (0)