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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions crates/squawk/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ fn render_lint_error<W: std::io::Write>(
sql: &str,
) -> Result<()> {
let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
let error_name = &err.rule_name;

let title = &err.message;

let level = match err.level {
ViolationLevel::Warning => Level::WARNING,
ViolationLevel::Error => Level::ERROR,
Expand All @@ -105,7 +101,10 @@ fn render_lint_error<W: std::io::Write>(
.fold(true)
.annotation(AnnotationKind::Primary.span(err.range.into()));

let mut group = level.primary_title(title).id(error_name).element(snippet);
let mut group = level
.primary_title(&err.message)
.id(&err.rule_name)
.element(snippet);

if let Some(help) = &err.help {
group = group.element(Level::HELP.message(help));
Expand Down
8 changes: 4 additions & 4 deletions crates/squawk_linter/src/rules/ban_uncommitted_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ BEGIN;
CREATE TABLE users (id bigint);
"#;
assert_snapshot!(lint_errors(sql, Rule::BanUncommittedTransaction), @r"
error[BanUncommittedTransaction]: Transaction never committed or rolled back.
warning[ban-uncommitted-transaction]: Transaction never committed or rolled back.
╭▸
2 │ BEGIN;
│ ━━━━━
Expand Down Expand Up @@ -105,7 +105,7 @@ BEGIN;
CREATE TABLE posts (id bigint);
"#;
assert_snapshot!(lint_errors(sql, Rule::BanUncommittedTransaction), @r"
error[BanUncommittedTransaction]: Transaction never committed or rolled back.
warning[ban-uncommitted-transaction]: Transaction never committed or rolled back.
╭▸
6 │ BEGIN;
│ ━━━━━
Expand All @@ -125,7 +125,7 @@ START TRANSACTION;
CREATE TABLE users (id bigint);
"#;
assert_snapshot!(lint_errors(sql, Rule::BanUncommittedTransaction), @r"
error[BanUncommittedTransaction]: Transaction never committed or rolled back.
warning[ban-uncommitted-transaction]: Transaction never committed or rolled back.
╭▸
2 │ START TRANSACTION;
│ ━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -155,7 +155,7 @@ BEGIN WORK;
CREATE TABLE users (id bigint);
"#;
assert_snapshot!(lint_errors(sql, Rule::BanUncommittedTransaction), @r"
error[BanUncommittedTransaction]: Transaction never committed or rolled back.
warning[ban-uncommitted-transaction]: Transaction never committed or rolled back.
╭▸
2 │ BEGIN WORK;
│ ━━━━━━━━━━
Expand Down
20 changes: 10 additions & 10 deletions crates/squawk_linter/src/rules/require_timeout_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ mod test {
ALTER TABLE t ADD COLUMN c BOOLEAN;
"#;
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
error[RequireTimeoutSettings]: Missing `set lock_timeout` before potentially slow operations
warning[require-timeout-settings]: Missing `set lock_timeout` before potentially slow operations
╭▸
2 │ ALTER TABLE t ADD COLUMN c BOOLEAN;
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -132,7 +132,7 @@ ALTER TABLE t ADD COLUMN c BOOLEAN;
╭╴
2 + set lock_timeout = '1s';
╰╴
error[RequireTimeoutSettings]: Missing `set statement_timeout` before potentially slow operations
warning[require-timeout-settings]: Missing `set statement_timeout` before potentially slow operations
╭▸
2 │ ALTER TABLE t ADD COLUMN c BOOLEAN;
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -151,7 +151,7 @@ SET statement_timeout = '5s';
ALTER TABLE t ADD COLUMN c BOOLEAN;
"#;
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
error[RequireTimeoutSettings]: Missing `set lock_timeout` before potentially slow operations
warning[require-timeout-settings]: Missing `set lock_timeout` before potentially slow operations
╭▸
3 │ ALTER TABLE t ADD COLUMN c BOOLEAN;
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -170,7 +170,7 @@ SET lock_timeout = '1s';
ALTER TABLE t ADD COLUMN c BOOLEAN;
"#;
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
error[RequireTimeoutSettings]: Missing `set statement_timeout` before potentially slow operations
warning[require-timeout-settings]: Missing `set statement_timeout` before potentially slow operations
╭▸
3 │ ALTER TABLE t ADD COLUMN c BOOLEAN;
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -218,7 +218,7 @@ SET foo.statement_timeout = '5s';
ALTER TABLE t ADD COLUMN c BOOLEAN;
"#;
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
error[RequireTimeoutSettings]: Missing `set lock_timeout` before potentially slow operations
warning[require-timeout-settings]: Missing `set lock_timeout` before potentially slow operations
╭▸
4 │ ALTER TABLE t ADD COLUMN c BOOLEAN;
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -227,7 +227,7 @@ ALTER TABLE t ADD COLUMN c BOOLEAN;
╭╴
2 + set lock_timeout = '1s';
╰╴
error[RequireTimeoutSettings]: Missing `set statement_timeout` before potentially slow operations
warning[require-timeout-settings]: Missing `set statement_timeout` before potentially slow operations
╭▸
4 │ ALTER TABLE t ADD COLUMN c BOOLEAN;
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -246,7 +246,7 @@ SET lock_timeout = '1s';
SET statement_timeout = '5s';
"#;
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
error[RequireTimeoutSettings]: Missing `set lock_timeout` before potentially slow operations
warning[require-timeout-settings]: Missing `set lock_timeout` before potentially slow operations
╭▸
2 │ ALTER TABLE t ADD COLUMN c BOOLEAN;
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -255,7 +255,7 @@ SET statement_timeout = '5s';
╭╴
2 + set lock_timeout = '1s';
╰╴
error[RequireTimeoutSettings]: Missing `set statement_timeout` before potentially slow operations
warning[require-timeout-settings]: Missing `set statement_timeout` before potentially slow operations
╭▸
2 │ ALTER TABLE t ADD COLUMN c BOOLEAN;
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -273,7 +273,7 @@ SET statement_timeout = '5s';
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
"#;
assert_snapshot!(lint_errors(sql, Rule::RequireTimeoutSettings), @r"
error[RequireTimeoutSettings]: Missing `set lock_timeout` before potentially slow operations
warning[require-timeout-settings]: Missing `set lock_timeout` before potentially slow operations
╭▸
2 │ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -282,7 +282,7 @@ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
╭╴
2 + set lock_timeout = '1s';
╰╴
error[RequireTimeoutSettings]: Missing `set statement_timeout` before potentially slow operations
warning[require-timeout-settings]: Missing `set statement_timeout` before potentially slow operations
╭▸
2 │ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
---
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.
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.
╭▸
3 │ ALTER TABLE "core_recipe" ADD COLUMN "foo" jsonb DEFAULT myjsonb();
│ ━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
---
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.
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.
╭▸
3 │ ALTER TABLE "core_recipe" ADD COLUMN "foo" timestamptz DEFAULT now(123);
│ ━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
---
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.
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.
╭▸
2 │ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT uuid();
│ ━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
---
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.
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.
╭▸
2 │ alter table t set logged, add column c integer default uuid();
│ ━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
---
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.
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.
╭▸
3 │ ALTER TABLE "core_recipe" ADD COLUMN "foo" boolean DEFAULT random();
│ ━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
expression: "lint_errors_with(sql, LinterSettings\n{\n pg_version: \"11\".parse().expect(\"Invalid PostgreSQL version\"),\n ..Default::default()\n},)"
---
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.
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.
╭▸
3 │ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
│ ━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_field_with_default.rs
expression: "lint_errors(sql, Rule::AddingFieldWithDefault)"
---
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.
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.
╭▸
3 │ ADD COLUMN bar numeric GENERATED ALWAYS AS (bar + baz) STORED;
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_foreign_key_constraint.rs
expression: "lint_errors(sql, Rule::AddingForeignKeyConstraint)"
---
error[AddingForeignKeyConstraint]: Adding a foreign key constraint requires a table scan and a `SHARE ROW EXCLUSIVE` lock on both tables, which blocks writes to each table.
warning[adding-foreign-key-constraint]: Adding a foreign key constraint requires a table scan and a `SHARE ROW EXCLUSIVE` lock on both tables, which blocks writes to each table.
╭▸
3 │ ALTER TABLE "emails" ADD COLUMN "user_id" INT REFERENCES "user" ("id");
│ ━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_foreign_key_constraint.rs
expression: "lint_errors(sql, Rule::AddingForeignKeyConstraint)"
---
error[AddingForeignKeyConstraint]: Adding a foreign key constraint requires a table scan and a `SHARE ROW EXCLUSIVE` lock on both tables, which blocks writes to each table.
warning[adding-foreign-key-constraint]: Adding a foreign key constraint requires a table scan and a `SHARE ROW EXCLUSIVE` lock on both tables, which blocks writes to each table.
╭▸
4 │ ALTER TABLE "email" ADD CONSTRAINT "fk_user" FOREIGN KEY ("user_id") REFERENCES "user" ("id");
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_not_null_field.rs
expression: "lint_errors(sql, Rule::AddingNotNullableField)"
---
error[AddingNotNullableField]: Setting a column `NOT NULL` blocks reads while the table is scanned.
warning[adding-not-nullable-field]: Setting a column `NOT NULL` blocks reads while the table is scanned.
╭▸
4 │ ALTER TABLE my_table ALTER COLUMN my_column SET NOT NULL;
│ ━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_not_null_field.rs
expression: "lint_errors(sql, Rule::AddingNotNullableField)"
---
error[AddingNotNullableField]: Setting a column `NOT NULL` blocks reads while the table is scanned.
warning[adding-not-nullable-field]: Setting a column `NOT NULL` blocks reads while the table is scanned.
╭▸
2 │ ALTER TABLE "core_recipe" ALTER COLUMN "foo" SET NOT NULL;
│ ━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_primary_key_constraint.rs
expression: "lint_errors(sql, Rule::AddingSerialPrimaryKeyField)"
---
error[AddingSerialPrimaryKeyField]: Adding a primary key constraint requires an `ACCESS EXCLUSIVE` lock that will block all reads and writes to the table while the primary key index is built.
warning[adding-serial-primary-key-field]: Adding a primary key constraint requires an `ACCESS EXCLUSIVE` lock that will block all reads and writes to the table while the primary key index is built.
╭▸
2 │ ALTER TABLE items ADD PRIMARY KEY (id);
│ ━━━━━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_primary_key_constraint.rs
expression: "lint_errors(sql, Rule::AddingSerialPrimaryKeyField)"
---
error[AddingSerialPrimaryKeyField]: Adding a primary key constraint requires an `ACCESS EXCLUSIVE` lock that will block all reads and writes to the table while the primary key index is built.
warning[adding-serial-primary-key-field]: Adding a primary key constraint requires an `ACCESS EXCLUSIVE` lock that will block all reads and writes to the table while the primary key index is built.
╭▸
2 │ ALTER TABLE a ADD COLUMN b SERIAL PRIMARY KEY;
│ ━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/adding_required_field.rs
expression: "lint_errors(sql, Rule::AddingRequiredField)"
---
error[AddingRequiredField]: Adding a new column that is `NOT NULL` and has no default value to an existing table effectively makes it required.
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.
╭▸
2 │ ALTER TABLE "recipe" ADD COLUMN "public" boolean NOT NULL;
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/squawk_linter/src/rules/ban_alter_domain_with_add_constraint.rs
expression: "lint_errors(sql, Rule::BanAlterDomainWithAddConstraint)"
---
error[BanAlterDomainWithAddConstraint]: Domains with constraints have poor support for online migrations. Use table and column constraints instead.
warning[ban-alter-domain-with-add-constraint]: Domains with constraints have poor support for online migrations. Use table and column constraints instead.
╭▸
2 │ ALTER DOMAIN domain_name ADD CONSTRAINT constraint_name CHECK (value > 0);
╰╴ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Loading
Loading