diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ce0c603e..f1ac6625 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,6 +8,11 @@ on: - "**" pull_request: +env: + RUST_BACKTRACE: 1 + CARGO_TERM_COLOR: always + CLICOLOR: 1 + jobs: pre_job: runs-on: ubuntu-22.04 diff --git a/crates/squawk/src/snapshots/example.svg b/crates/squawk/src/snapshots/example.svg new file mode 100644 index 00000000..3498bde2 --- /dev/null +++ b/crates/squawk/src/snapshots/example.svg @@ -0,0 +1,147 @@ + + + + + + + warning[prefer-bigint-over-int]: Using 32-bit integer fields can result in hitting the max `int` limit. + + ╭▸ ../../example.sql:6:10 + + + + 6 "id" serial NOT NULL PRIMARY KEY, + + ━━━━━━ + + + + help: Use 64-bit integer values instead to prevent hitting this limit. + + ╭╴ + + 6 "id" bigserial NOT NULL PRIMARY KEY, + + ╰╴ +++ + + warning[prefer-identity]: Serial types make schema, dependency, and permission management difficult. + + ╭▸ ../../example.sql:6:10 + + + + 6 "id" serial NOT NULL PRIMARY KEY, + + ━━━━━━ + + + + help: Use an `IDENTITY` column instead. + + ╭╴ + + 6 - "id" serial NOT NULL PRIMARY KEY, + + 6 + "id" integer generated by default as identity NOT NULL PRIMARY KEY, + + ╰╴ + + warning[prefer-text-field]: Changing the size of a `varchar` field requires an `ACCESS EXCLUSIVE` lock, that will prevent all reads and writes to the table. + + ╭▸ ../../example.sql:7:13 + + + + 7 "alpha" varchar(100) NOT NULL + + ━━━━━━━━━━━━ + + + + help: Use a `TEXT` field with a `CHECK` constraint. + + ╭╴ + + 7 - "alpha" varchar(100) NOT NULL + + 7 + "alpha" text NOT NULL + + ╰╴ + + warning[require-concurrent-index-creation]: During normal index creation, table updates are blocked, but reads are still allowed. + + ╭▸ ../../example.sql:10:1 + + + + 10 CREATE INDEX "field_name_idx" ON "table_name" ("field_name"); + + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + + help: Use `concurrently` to avoid blocking writes. + + ╭╴ + + 10 CREATE INDEX concurrently "field_name_idx" ON "table_name" ("field_name"); + + ╰╴ ++++++++++++ + + warning[constraint-missing-not-valid]: By default new constraints require a table scan and block writes to the table while that scan occurs. + + ╭▸ ../../example.sql:12:24 + + + + 12 ALTER TABLE table_name ADD CONSTRAINT field_name_constraint UNIQUE (field_name); + + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + + help: Use `NOT VALID` with a later `VALIDATE CONSTRAINT` call. + + warning[disallowed-unique-constraint]: Adding a `UNIQUE` constraint requires an `ACCESS EXCLUSIVE` lock which blocks reads and writes to the table while the index is built. + + ╭▸ ../../example.sql:12:28 + + + + 12 ALTER TABLE table_name ADD CONSTRAINT field_name_constraint UNIQUE (field_name); + + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + + help: Create an index `CONCURRENTLY` and create the constraint using the index. + + + + Find detailed examples and solutions for each rule at https://squawkhq.com/docs/rules + + Found 6 issues in 1 file (checked 1 source file) + + + + + + diff --git a/crates/squawk/tests/example_output.rs b/crates/squawk/tests/example_output.rs new file mode 100644 index 00000000..e7dc864e --- /dev/null +++ b/crates/squawk/tests/example_output.rs @@ -0,0 +1,15 @@ +use snapbox::{cmd::Command, file}; + +#[test] +fn example_sql_svg() { + let expected = file!["../src/snapshots/example.svg": TermSvg]; + let bin_path = snapbox::cmd::cargo_bin("squawk"); + Command::new(bin_path) + .env("CLICOLOR_FORCE", "1") + .env("SQUAWK_DISABLE_GITHUB_ANNOTATIONS", "1") + .arg("../../example.sql") + .assert() + .code(1) // squawk returns 1 when it finds violations + .stderr_eq("") + .stdout_eq(expected.raw()); +}