Skip to content

Commit 034d98b

Browse files
authored
cli: upgrade annotate-snippets to latest (#654)
unicode characters now
1 parent 122fdee commit 034d98b

8 files changed

+103
-109
lines changed

β€ŽCargo.lockβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€ŽCargo.tomlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ wasm-bindgen-test = "0.3.34"
4343
web-sys = "0.3.77"
4444
console_error_panic_hook = "0.1.7"
4545
console_log = "1.0.0"
46-
annotate-snippets = "0.11.5"
46+
annotate-snippets = "0.12.4"
4747
anyhow = "1.0.94"
4848
convert_case = "0.7.1"
4949
clap = { version = "4.5.8", features = ["derive", "env"] }

β€Žcrates/squawk/src/debug.rsβ€Ž

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::{io, path::PathBuf};
22

3-
use annotate_snippets::{Level, Message, Renderer, Snippet};
3+
use annotate_snippets::{
4+
Annotation, AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle,
5+
};
46
use anyhow::Result;
57
use serde_json::json;
68
use squawk_syntax::{ast::AstNode, syntax_error::SyntaxError};
@@ -55,11 +57,8 @@ pub(crate) fn debug<W: io::Write>(
5557
}
5658
}
5759
writeln!(f, "{snap}")?;
58-
let renderer = Renderer::styled();
59-
render_syntax_errors(&errors, filename, sql, |message| {
60-
writeln!(f, "{}", renderer.render(message))?;
61-
Ok(())
62-
})?;
60+
let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
61+
render_syntax_errors(&errors, filename, sql, &renderer, f)?;
6362
}
6463
}
6564
DebugOption::Ast => {
@@ -109,18 +108,19 @@ fn render_syntax_errors(
109108
errors: &[SyntaxError],
110109
filename: &str,
111110
sql: &str,
112-
mut render: impl FnMut(Message<'_>) -> Result<()>,
111+
renderer: &Renderer,
112+
f: &mut dyn std::io::Write,
113113
) -> Result<()> {
114114
for err in errors {
115115
let text = err.message();
116116
let span = err.range().into();
117-
let message = Level::Error.title(text).id("syntax-error").snippet(
117+
let report = &[Level::ERROR.primary_title(text).id("syntax-error").element(
118118
Snippet::source(sql)
119-
.origin(filename)
119+
.path(filename)
120120
.fold(true)
121-
.annotation(Level::Error.span(span)),
122-
);
123-
render(message)?;
121+
.annotation(AnnotationKind::Primary.span(span)),
122+
)];
123+
writeln!(f, "{}", renderer.render(report))?;
124124
}
125125
Ok(())
126126
}

β€Žcrates/squawk/src/github.rsβ€Ž

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -381,21 +381,18 @@ mod test_github_comment {
381381
fn generating_comment_multiple_files() {
382382
let violations = vec![CheckReport {
383383
filename: "alpha.sql".into(),
384-
sql: r"
385-
SELECT 1;
386-
"
387-
.into(),
384+
sql: "SELECT 1;".into(),
388385
violations: vec![ReportViolation {
389386
file: "alpha.sql".into(),
390387
line: 1,
391-
column: 0,
388+
column: 8,
392389
level: ViolationLevel::Warning,
393390
rule_name: "adding-not-nullable-field".to_string(),
394-
range: TextRange::new(TextSize::new(0), TextSize::new(0)),
391+
range: TextRange::new(TextSize::new(7), TextSize::new(8)),
395392
message: "Adding a NOT NULL field requires exclusive locks and table rewrites."
396393
.to_string(),
397394
help: Some("Make the field nullable.".to_string()),
398-
column_end: 0,
395+
column_end: 9,
399396
line_end: 1,
400397
}],
401398
}];

β€Žcrates/squawk/src/reporter.rsβ€Ž

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use annotate_snippets::Level;
2-
use annotate_snippets::Renderer;
3-
use annotate_snippets::Snippet;
1+
use annotate_snippets::{
2+
Annotation, AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle,
3+
};
44
use anyhow::Result;
55
use console::style;
66
use line_index::LineIndex;
@@ -92,27 +92,28 @@ fn render_lint_error<W: std::io::Write>(
9292
filename: &str,
9393
sql: &str,
9494
) -> Result<()> {
95-
let renderer = Renderer::styled();
95+
let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
9696
let error_name = &err.rule_name;
9797

9898
let title = &err.message;
9999

100100
let level = match err.level {
101-
ViolationLevel::Warning => Level::Warning,
102-
ViolationLevel::Error => Level::Error,
101+
ViolationLevel::Warning => Level::WARNING,
102+
ViolationLevel::Error => Level::ERROR,
103103
};
104104

105-
let mut message = level.title(title).id(error_name).snippet(
105+
let mut group = level.primary_title(title).id(error_name).element(
106106
Snippet::source(sql)
107-
.origin(filename)
107+
.path(filename)
108108
.fold(true)
109-
.annotation(level.span(err.range.into())),
109+
.annotation(AnnotationKind::Primary.span(err.range.into())),
110110
);
111+
111112
if let Some(help) = &err.help {
112-
message = message.footer(Level::Help.title(help));
113+
group = group.element(Level::HELP.message(help));
113114
}
114115

115-
writeln!(f, "{}", renderer.render(message))?;
116+
writeln!(f, "{}", renderer.render(&[group]))?;
116117
Ok(())
117118
}
118119

β€Žcrates/squawk/src/snapshots/squawk__github__test_github_comment__generating_comment_multiple_files.snapβ€Ž

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ expression: body
1010
<h3><code>alpha.sql</code></h3>
1111

1212
```sql
13-
1413
SELECT 1;
15-
1614
```
1715

1816
<h4>πŸš’ Rule Violations (1)</h4>
1917

2018

2119
```
2220
warning[adding-not-nullable-field]: Adding a NOT NULL field requires exclusive locks and table rewrites.
23-
--> alpha.sql:1:1
24-
|
25-
|
26-
= help: Make the field nullable.
21+
β•­β–Έ alpha.sql:1:8
22+
β”‚
23+
1 β”‚ SELECT 1;
24+
β”‚ ━
25+
β”‚
26+
β•° help: Make the field nullable.
2727
```
2828

2929
---

β€Žcrates/squawk/src/snapshots/squawk__reporter__test_reporter__display_violations_tty.snapβ€Ž

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,43 @@ 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.
6-
--> main.sql:2:30
7-
|
8-
2 | ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
9-
| ---------------------------------
10-
|
11-
= help: Make the field nullable or add a non-VOLATILE DEFAULT
6+
β•­β–Έ main.sql:2:30
7+
β”‚
8+
2 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
9+
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
10+
β”‚
11+
β•° 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.
13-
--> main.sql:2:30
14-
|
15-
2 | ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
16-
| ---------------------------------
17-
|
13+
β•­β–Έ main.sql:2:30
14+
β”‚
15+
2 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
16+
β•°β•΄ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1817
warning[prefer-bigint-over-int]: Using 32-bit integer fields can result in hitting the max `int` limit.
19-
--> main.sql:2:47
20-
|
21-
2 | ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
22-
| -------
23-
|
24-
= help: Use 64-bit integer values instead to prevent hitting this limit.
18+
β•­β–Έ main.sql:2:47
19+
β”‚
20+
2 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
21+
β”‚ ━━━━━━━
22+
β”‚
23+
β•° help: Use 64-bit integer values instead to prevent hitting this limit.
2524
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.
26-
--> main.sql:3:24
27-
|
28-
3 | ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
29-
| ---------------------------------
30-
|
31-
= help: Make the field nullable or add a non-VOLATILE DEFAULT
25+
β•­β–Έ main.sql:3:24
26+
β”‚
27+
3 β”‚ ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
28+
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
29+
β”‚
30+
β•° help: Make the field nullable or add a non-VOLATILE DEFAULT
3231
warning[prefer-robust-stmts]: Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.
33-
--> main.sql:3:24
34-
|
35-
3 | ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
36-
| ---------------------------------
37-
|
32+
β•­β–Έ main.sql:3:24
33+
β”‚
34+
3 β”‚ ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
35+
β•°β•΄ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
3836
warning[prefer-bigint-over-int]: Using 32-bit integer fields can result in hitting the max `int` limit.
39-
--> main.sql:3:41
40-
|
41-
3 | ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
42-
| -------
43-
|
44-
= help: Use 64-bit integer values instead to prevent hitting this limit.
37+
β•­β–Έ main.sql:3:41
38+
β”‚
39+
3 β”‚ ALTER TABLE "core_foo" ADD COLUMN "bar" integer NOT NULL;
40+
β”‚ ━━━━━━━
41+
β”‚
42+
β•° help: Use 64-bit integer values instead to prevent hitting this limit.
4543

4644
Find detailed examples and solutions for each rule at https://squawkhq.com/docs/rules
4745
Found 6 issues in 1 file (checked 1 source file)

β€Žcrates/squawk/src/snapshots/squawk__reporter__test_reporter__display_violations_tty_and_github_annotations.snapβ€Ž

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,45 @@ expression: "strip_ansi_codes(&String::from_utf8_lossy(&buff))"
99
::warning file=main.sql,line=5,col=2,endLine=6,endColumn=20,title=prefer-robust-stmts::Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.
1010
::warning file=main.sql,line=6,col=4,endLine=6,endColumn=11,title=prefer-bigint-over-int::Using 32-bit integer fields can result in hitting the max `int` limit.
1111
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.
12-
--> main.sql:2:30
13-
|
14-
2 | ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
15-
| ---------------------------------
16-
|
17-
= help: Make the field nullable or add a non-VOLATILE DEFAULT
12+
β•­β–Έ main.sql:2:30
13+
β”‚
14+
2 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
15+
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
16+
β”‚
17+
β•° help: Make the field nullable or add a non-VOLATILE DEFAULT
1818
warning[prefer-robust-stmts]: Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.
19-
--> main.sql:2:30
20-
|
21-
2 | ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
22-
| ---------------------------------
23-
|
19+
β•­β–Έ main.sql:2:30
20+
β”‚
21+
2 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
22+
β•°β•΄ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
2423
warning[prefer-bigint-over-int]: Using 32-bit integer fields can result in hitting the max `int` limit.
25-
--> main.sql:2:47
26-
|
27-
2 | ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
28-
| -------
29-
|
30-
= help: Use 64-bit integer values instead to prevent hitting this limit.
24+
β•­β–Έ main.sql:2:47
25+
β”‚
26+
2 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer NOT NULL;
27+
β”‚ ━━━━━━━
28+
β”‚
29+
β•° help: Use 64-bit integer values instead to prevent hitting this limit.
3130
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.
32-
--> main.sql:5:3
33-
|
34-
5 | / ADD COLUMN "bar"
35-
6 | | integer NOT NULL;
36-
| |____________________-
37-
|
38-
= help: Make the field nullable or add a non-VOLATILE DEFAULT
31+
β•­β–Έ main.sql:5:3
32+
β”‚
33+
5 β”‚ ┏ ADD COLUMN "bar"
34+
6 β”‚ ┃ integer NOT NULL;
35+
β”‚ ┗━━━━━━━━━━━━━━━━━━━━┛
36+
β”‚
37+
β•° help: Make the field nullable or add a non-VOLATILE DEFAULT
3938
warning[prefer-robust-stmts]: Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.
40-
--> main.sql:5:3
41-
|
42-
5 | / ADD COLUMN "bar"
43-
6 | | integer NOT NULL;
44-
| |____________________-
45-
|
39+
β•­β–Έ main.sql:5:3
40+
β”‚
41+
5 β”‚ ┏ ADD COLUMN "bar"
42+
6 β”‚ ┃ integer NOT NULL;
43+
╰╴┗━━━━━━━━━━━━━━━━━━━━┛
4644
warning[prefer-bigint-over-int]: Using 32-bit integer fields can result in hitting the max `int` limit.
47-
--> main.sql:6:5
48-
|
49-
6 | integer NOT NULL;
50-
| -------
51-
|
52-
= help: Use 64-bit integer values instead to prevent hitting this limit.
45+
β•­β–Έ main.sql:6:5
46+
β”‚
47+
6 β”‚ integer NOT NULL;
48+
β”‚ ━━━━━━━
49+
β”‚
50+
β•° help: Use 64-bit integer values instead to prevent hitting this limit.
5351

5452
Find detailed examples and solutions for each rule at https://squawkhq.com/docs/rules
5553
Found 6 issues in 1 file (checked 1 source file)

0 commit comments

Comments
Β (0)