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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,62 +44,62 @@ Use the WASM powered playground to check your SQL locally in the browser!

```shell
❯ squawk example.sql
warning[prefer-bigint-over-int]: Using 32-bit integer fields can result in hitting the max `int` limit.
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.
├ 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.
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.
├ 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.
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.
├ 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.
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.
├ 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.
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.
╰ 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.
╰ 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)
Expand Down
9 changes: 6 additions & 3 deletions crates/squawk/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,16 @@ fn render_syntax_errors(
for err in errors {
let text = err.message();
let span = err.range().into();
let report = &[Level::ERROR.primary_title(text).id("syntax-error").element(
let mut group = Level::ERROR.primary_title(text).id("syntax-error").element(
Snippet::source(sql)
.path(filename)
.fold(true)
.annotation(AnnotationKind::Primary.span(span)),
)];
writeln!(f, "{}", renderer.render(report))?;
);
if let Some(hint) = err.hint() {
group = group.element(Level::HELP.with_name("hint").message(hint));
}
writeln!(f, "{}", renderer.render(&[group]))?;
}
Ok(())
}
Expand Down
15 changes: 9 additions & 6 deletions crates/squawk/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,10 @@ mod test_github_comment {
level: ViolationLevel::Warning,
rule_name: "adding-not-nullable-field".to_string(),
range: TextRange::new(TextSize::new(7), TextSize::new(8)),
message: "Adding a NOT NULL field requires exclusive locks and table rewrites."
message: "adding a `not null` field requires exclusive locks and table rewrites"
.into(),
help: Some("Make the field nullable.".into()),
note: None,
help: Some("make the field nullable".into()),
column_end: 9,
line_end: 1,
fix: None,
Expand Down Expand Up @@ -472,8 +473,9 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
level: ViolationLevel::Warning,
rule_name: "prefer-bigint-over-int".to_string(),
range: TextRange::new(TextSize::new(0), TextSize::new(0)),
message: "Prefer bigint over int.".into(),
help: Some("Use bigint instead.".into()),
message: "prefer `bigint` over `int`".into(),
note: None,
help: Some("use `bigint` instead".into()),
column_end: 0,
line_end: 1,
fix: None,
Expand Down Expand Up @@ -507,8 +509,9 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
level: ViolationLevel::Warning,
rule_name: "prefer-bigint-over-int".to_string(),
range: TextRange::new(TextSize::new(0), TextSize::new(0)),
message: "Prefer bigint over int.".into(),
help: Some("Use bigint instead.".into()),
message: "prefer `bigint` over `int`".into(),
note: None,
help: Some("use `bigint` instead".into()),
column_end: 0,
line_end: 1,
fix: None,
Expand Down
Loading
Loading