Skip to content

Commit d6297af

Browse files
authored
syntax: use annotate-snippets in tests (#753)
1 parent 0aa56e5 commit d6297af

File tree

88 files changed

+311
-195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+311
-195
lines changed

β€ŽCargo.lockβ€Ž

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

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ fn render_lint_error<W: std::io::Write>(
9191
sql: &str,
9292
) -> Result<()> {
9393
let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
94-
let error_name = &err.rule_name;
95-
96-
let title = &err.message;
97-
9894
let level = match err.level {
9995
ViolationLevel::Warning => Level::WARNING,
10096
ViolationLevel::Error => Level::ERROR,
@@ -105,7 +101,10 @@ fn render_lint_error<W: std::io::Write>(
105101
.fold(true)
106102
.annotation(AnnotationKind::Primary.span(err.range.into()));
107103

108-
let mut group = level.primary_title(title).id(error_name).element(snippet);
104+
let mut group = level
105+
.primary_title(&err.message)
106+
.id(&err.rule_name)
107+
.element(snippet);
109108

110109
if let Some(help) = &err.help {
111110
group = group.element(Level::HELP.message(help));

β€Žcrates/squawk_linter/src/rules/ban_uncommitted_transaction.rsβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ BEGIN;
5353
CREATE TABLE users (id bigint);
5454
"#;
5555
assert_snapshot!(lint_errors(sql, Rule::BanUncommittedTransaction), @r"
56-
error[BanUncommittedTransaction]: Transaction never committed or rolled back.
56+
warning[ban-uncommitted-transaction]: Transaction never committed or rolled back.
5757
β•­β–Έ
5858
2 β”‚ BEGIN;
5959
β”‚ ━━━━━
@@ -105,7 +105,7 @@ BEGIN;
105105
CREATE TABLE posts (id bigint);
106106
"#;
107107
assert_snapshot!(lint_errors(sql, Rule::BanUncommittedTransaction), @r"
108-
error[BanUncommittedTransaction]: Transaction never committed or rolled back.
108+
warning[ban-uncommitted-transaction]: Transaction never committed or rolled back.
109109
β•­β–Έ
110110
6 β”‚ BEGIN;
111111
β”‚ ━━━━━
@@ -125,7 +125,7 @@ START TRANSACTION;
125125
CREATE TABLE users (id bigint);
126126
"#;
127127
assert_snapshot!(lint_errors(sql, Rule::BanUncommittedTransaction), @r"
128-
error[BanUncommittedTransaction]: Transaction never committed or rolled back.
128+
warning[ban-uncommitted-transaction]: Transaction never committed or rolled back.
129129
β•­β–Έ
130130
2 β”‚ START TRANSACTION;
131131
β”‚ ━━━━━━━━━━━━━━━━━
@@ -155,7 +155,7 @@ BEGIN WORK;
155155
CREATE TABLE users (id bigint);
156156
"#;
157157
assert_snapshot!(lint_errors(sql, Rule::BanUncommittedTransaction), @r"
158-
error[BanUncommittedTransaction]: Transaction never committed or rolled back.
158+
warning[ban-uncommitted-transaction]: Transaction never committed or rolled back.
159159
β•­β–Έ
160160
2 β”‚ BEGIN WORK;
161161
β”‚ ━━━━━━━━━━

β€Žcrates/squawk_linter/src/rules/require_timeout_settings.rsβ€Ž

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ mod test {
123123
ALTER TABLE t ADD COLUMN c BOOLEAN;
124124
"#;
125125
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
126-
error[RequireTimeoutSettings]: Missing `set lock_timeout` before potentially slow operations
126+
warning[require-timeout-settings]: Missing `set lock_timeout` before potentially slow operations
127127
β•­β–Έ
128128
2 β”‚ ALTER TABLE t ADD COLUMN c BOOLEAN;
129129
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -132,7 +132,7 @@ ALTER TABLE t ADD COLUMN c BOOLEAN;
132132
β•­β•΄
133133
2 + set lock_timeout = '1s';
134134
β•°β•΄
135-
error[RequireTimeoutSettings]: Missing `set statement_timeout` before potentially slow operations
135+
warning[require-timeout-settings]: Missing `set statement_timeout` before potentially slow operations
136136
β•­β–Έ
137137
2 β”‚ ALTER TABLE t ADD COLUMN c BOOLEAN;
138138
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -151,7 +151,7 @@ SET statement_timeout = '5s';
151151
ALTER TABLE t ADD COLUMN c BOOLEAN;
152152
"#;
153153
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
154-
error[RequireTimeoutSettings]: Missing `set lock_timeout` before potentially slow operations
154+
warning[require-timeout-settings]: Missing `set lock_timeout` before potentially slow operations
155155
β•­β–Έ
156156
3 β”‚ ALTER TABLE t ADD COLUMN c BOOLEAN;
157157
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -170,7 +170,7 @@ SET lock_timeout = '1s';
170170
ALTER TABLE t ADD COLUMN c BOOLEAN;
171171
"#;
172172
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
173-
error[RequireTimeoutSettings]: Missing `set statement_timeout` before potentially slow operations
173+
warning[require-timeout-settings]: Missing `set statement_timeout` before potentially slow operations
174174
β•­β–Έ
175175
3 β”‚ ALTER TABLE t ADD COLUMN c BOOLEAN;
176176
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -218,7 +218,7 @@ SET foo.statement_timeout = '5s';
218218
ALTER TABLE t ADD COLUMN c BOOLEAN;
219219
"#;
220220
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
221-
error[RequireTimeoutSettings]: Missing `set lock_timeout` before potentially slow operations
221+
warning[require-timeout-settings]: Missing `set lock_timeout` before potentially slow operations
222222
β•­β–Έ
223223
4 β”‚ ALTER TABLE t ADD COLUMN c BOOLEAN;
224224
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -227,7 +227,7 @@ ALTER TABLE t ADD COLUMN c BOOLEAN;
227227
β•­β•΄
228228
2 + set lock_timeout = '1s';
229229
β•°β•΄
230-
error[RequireTimeoutSettings]: Missing `set statement_timeout` before potentially slow operations
230+
warning[require-timeout-settings]: Missing `set statement_timeout` before potentially slow operations
231231
β•­β–Έ
232232
4 β”‚ ALTER TABLE t ADD COLUMN c BOOLEAN;
233233
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -246,7 +246,7 @@ SET lock_timeout = '1s';
246246
SET statement_timeout = '5s';
247247
"#;
248248
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
249-
error[RequireTimeoutSettings]: Missing `set lock_timeout` before potentially slow operations
249+
warning[require-timeout-settings]: Missing `set lock_timeout` before potentially slow operations
250250
β•­β–Έ
251251
2 β”‚ ALTER TABLE t ADD COLUMN c BOOLEAN;
252252
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -255,7 +255,7 @@ SET statement_timeout = '5s';
255255
β•­β•΄
256256
2 + set lock_timeout = '1s';
257257
β•°β•΄
258-
error[RequireTimeoutSettings]: Missing `set statement_timeout` before potentially slow operations
258+
warning[require-timeout-settings]: Missing `set statement_timeout` before potentially slow operations
259259
β•­β–Έ
260260
2 β”‚ ALTER TABLE t ADD COLUMN c BOOLEAN;
261261
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -273,7 +273,7 @@ SET statement_timeout = '5s';
273273
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
274274
"#;
275275
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
276-
error[RequireTimeoutSettings]: Missing `set lock_timeout` before potentially slow operations
276+
warning[require-timeout-settings]: Missing `set lock_timeout` before potentially slow operations
277277
β•­β–Έ
278278
2 β”‚ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
279279
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -282,7 +282,7 @@ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
282282
β•­β•΄
283283
2 + set lock_timeout = '1s';
284284
β•°β•΄
285-
error[RequireTimeoutSettings]: Missing `set statement_timeout` before potentially slow operations
285+
warning[require-timeout-settings]: Missing `set statement_timeout` before potentially slow operations
286286
β•­β–Έ
287287
2 β”‚ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
288288
β”‚ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

β€Žcrates/squawk_linter/src/rules/snapshots/squawk_linter__rules__adding_field_with_default__test__arbitrary_func_err.snapβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
33
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
44
---
5-
error[AddingFieldWithDefault]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
5+
warning[adding-field-with-default]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
66
β•­β–Έ
77
3 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb();
88
β”‚ ━━━━━━━━━

β€Žcrates/squawk_linter/src/rules/snapshots/squawk_linter__rules__adding_field_with_default__test__default_random_with_args_err.snapβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
33
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
44
---
5-
error[AddingFieldWithDefault]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
5+
warning[adding-field-with-default]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
66
β•­β–Έ
77
3 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123);
88
β”‚ ━━━━━━━━

β€Žcrates/squawk_linter/src/rules/snapshots/squawk_linter__rules__adding_field_with_default__test__default_uuid_error.snapβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
33
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
44
---
5-
error[AddingFieldWithDefault]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
5+
warning[adding-field-with-default]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
66
β•­β–Έ
77
2 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid();
88
β”‚ ━━━━━━

β€Žcrates/squawk_linter/src/rules/snapshots/squawk_linter__rules__adding_field_with_default__test__default_uuid_error_multi_stmt.snapβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
33
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
44
---
5-
error[AddingFieldWithDefault]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
5+
warning[adding-field-with-default]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
66
β•­β–Έ
77
2 β”‚ alter table t set logged, add column c integer default uuid();
88
β”‚ ━━━━━━

β€Žcrates/squawk_linter/src/rules/snapshots/squawk_linter__rules__adding_field_with_default__test__default_volatile_func_err.snapβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
33
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
44
---
5-
error[AddingFieldWithDefault]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
5+
warning[adding-field-with-default]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
66
β•­β–Έ
77
3 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random();
88
β”‚ ━━━━━━━━

β€Žcrates/squawk_linter/src/rules/snapshots/squawk_linter__rules__adding_field_with_default__test__docs_example_error_on_pg_11.snapβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
33
expression: "lint_errors_with(sql, LinterSettings\n{\n pg_version: \"11\".parse().expect(\"Invalid PostgreSQL version\"),\n ..Default::default()\n},)"
44
---
5-
error[AddingFieldWithDefault]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
5+
warning[adding-field-with-default]: Adding a generated column requires a table rewrite with an `ACCESS EXCLUSIVE` lock. In Postgres versions 11+, non-VOLATILE DEFAULTs can be added without a rewrite.
66
β•­β–Έ
77
3 β”‚ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
88
β”‚ ━━

0 commit comments

Comments
Β (0)