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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) fn adding_field_with_default(ctx: &mut Linter, parse: &Parse<SourceFi
let file = parse.tree();
// TODO: use match_ast! like in #api_walkthrough
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
for action in alter_table.actions() {
if let ast::AlterTableAction::AddColumn(add_column) = action {
for constraint in add_column.constraints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) fn adding_foreign_key_constraint(ctx: &mut Linter, parse: &Parse<Sour
let file = parse.tree();
// TODO: use match_ast! like in #api_walkthrough
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
for action in alter_table.actions() {
match action {
ast::AlterTableAction::AddConstraint(add_constraint) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/src/rules/adding_not_null_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) fn adding_not_null_field(ctx: &mut Linter, parse: &Parse<SourceFile>)
}
let file = parse.tree();
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
for action in alter_table.actions() {
if let ast::AlterTableAction::AlterColumn(alter_column) = action {
let Some(option) = alter_column.option() else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) fn adding_primary_key_constraint(ctx: &mut Linter, parse: &Parse<Sour
let help = "Add the `PRIMARY KEY` constraint `USING` an index.";
let file = parse.tree();
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
for action in alter_table.actions() {
match action {
ast::AlterTableAction::AddConstraint(add_constraint) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/src/rules/adding_required_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn adding_required_field(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
for action in alter_table.actions() {
if let ast::AlterTableAction::AddColumn(add_column) = action {
if has_generated_constrait(add_column.constraints()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn ban_alter_domain_with_add_constraint(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::AlterDomain(alter_domain) = item {
if let ast::Stmt::AlterDomain(alter_domain) = item {
let actions = alter_domain.actions();
for action in actions {
if let ast::AlterDomainAction::AddConstraint(add_constraint) = action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ pub(crate) fn ban_concurrent_index_creation_in_transaction(
for item in file.items() {
stmt_count += 1;
match item {
ast::Item::Begin(_) => {
ast::Stmt::Begin(_) => {
in_transaction = true;
}
ast::Item::Commit(_) => {
ast::Stmt::Commit(_) => {
in_transaction = false;
}
ast::Item::CreateIndex(create_index) => {
ast::Stmt::CreateIndex(create_index) => {
if in_transaction {
if let Some(concurrently) = create_index.concurrently_token() {
errors.push(Violation::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn ban_create_domain_with_constraint(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::CreateDomain(domain) = item {
if let ast::Stmt::CreateDomain(domain) = item {
let range =
domain
.constraints()
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/src/rules/ban_drop_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn ban_drop_column(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
for action in alter_table.actions() {
if let ast::AlterTableAction::DropColumn(drop_column) = action {
ctx.report(Violation::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/src/rules/ban_drop_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn ban_drop_database(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::DropDatabase(drop_database) = item {
if let ast::Stmt::DropDatabase(drop_database) = item {
ctx.report(Violation::new(
Rule::BanDropDatabase,
"Dropping a database may break existing clients.".into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/src/rules/ban_drop_not_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn ban_drop_not_null(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
for action in alter_table.actions() {
if let ast::AlterTableAction::AlterColumn(alter_column) = action {
if let Some(ast::AlterColumnOption::DropNotNull(drop_not_null)) =
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/src/rules/ban_drop_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn ban_drop_table(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::DropTable(drop_table) = item {
if let ast::Stmt::DropTable(drop_table) = item {
ctx.report(Violation::new(
Rule::BanDropTable,
"Dropping a table may break existing clients.".into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/src/rules/ban_truncate_cascade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) fn ban_truncate_cascade(ctx: &mut Linter, parse: &Parse<SourceFile>)
let file = parse.tree();
for item in file.items() {
match item {
ast::Item::Truncate(truncate) => {
ast::Stmt::Truncate(truncate) => {
if let Some(cascade) = truncate.cascade_token() {
// TODO: if we had knowledge about the entire schema, we
// could be more precise here and actually navigate the
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/src/rules/changing_column_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn changing_column_type(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
for action in alter_table.actions() {
if let ast::AlterTableAction::AlterColumn(alter_column) = action {
if let Some(ast::AlterColumnOption::SetType(set_type)) = alter_column.option() {
Expand Down
14 changes: 7 additions & 7 deletions crates/squawk_linter/src/rules/constraint_missing_not_valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ pub fn tables_created_in_transaction(
let mut inside_transaction = assume_in_transaction;
for item in file.items() {
match item {
ast::Item::Begin(_) => {
ast::Stmt::Begin(_) => {
inside_transaction = true;
}
ast::Item::Commit(_) => {
ast::Stmt::Commit(_) => {
inside_transaction = false;
}
ast::Item::CreateTable(create_table) if inside_transaction => {
ast::Stmt::CreateTable(create_table) if inside_transaction => {
let Some(table_name) = create_table
.path()
.and_then(|x| x.segment())
Expand All @@ -46,7 +46,7 @@ fn not_valid_validate_in_transaction(
let mut not_valid_names: HashSet<String> = HashSet::new();
for item in file.items() {
match item {
ast::Item::AlterTable(alter_table) => {
ast::Stmt::AlterTable(alter_table) => {
for action in alter_table.actions() {
match action {
ast::AlterTableAction::ValidateConstraint(validate_constraint) => {
Expand Down Expand Up @@ -81,13 +81,13 @@ fn not_valid_validate_in_transaction(
}
}
}
ast::Item::Begin(_) => {
ast::Stmt::Begin(_) => {
if !inside_transaction {
not_valid_names.clear();
}
inside_transaction = true;
}
ast::Item::Commit(_) => {
ast::Stmt::Commit(_) => {
inside_transaction = false;
}
_ => (),
Expand All @@ -105,7 +105,7 @@ pub(crate) fn constraint_missing_not_valid(ctx: &mut Linter, parse: &Parse<Sourc
let tables_created = tables_created_in_transaction(assume_in_transaction, &file);

for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
let Some(table_name) = alter_table
.path()
.and_then(|x| x.segment())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) fn disallow_unique_constraint(ctx: &mut Linter, parse: &Parse<SourceF
let file = parse.tree();
let tables_created = tables_created_in_transaction(ctx.settings.assume_in_transaction, &file);
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
let Some(table_name) = alter_table
.path()
.and_then(|x| x.segment())
Expand Down
16 changes: 8 additions & 8 deletions crates/squawk_linter/src/rules/prefer_robust_stmts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {

for item in file.items() {
match item {
ast::Item::Begin(_) => {
ast::Stmt::Begin(_) => {
inside_transaction = true;
}
ast::Item::Commit(_) => {
ast::Stmt::Commit(_) => {
inside_transaction = false;
}
ast::Item::AlterTable(alter_table) => {
ast::Stmt::AlterTable(alter_table) => {
for action in alter_table.actions() {
let message_type = match &action {
ast::AlterTableAction::DropConstraint(drop_constraint) => {
Expand Down Expand Up @@ -122,7 +122,7 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
));
}
}
ast::Item::CreateIndex(create_index)
ast::Stmt::CreateIndex(create_index)
if create_index.if_not_exists().is_none()
&& (create_index.concurrently_token().is_some() || !inside_transaction) =>
{
Expand All @@ -133,7 +133,7 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
"Use an explicit name for a concurrently created index".to_string(),
));
}
ast::Item::CreateTable(create_table)
ast::Stmt::CreateTable(create_table)
if create_table.if_not_exists().is_none() && !inside_transaction =>
{
ctx.report(Violation::new(
Expand All @@ -143,7 +143,7 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
None,
));
}
ast::Item::DropIndex(drop_index)
ast::Stmt::DropIndex(drop_index)
if drop_index.if_exists().is_none() && !inside_transaction =>
{
ctx.report(Violation::new(
Expand All @@ -153,7 +153,7 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
None,
));
}
ast::Item::DropTable(drop_table)
ast::Stmt::DropTable(drop_table)
if drop_table.if_exists().is_none() && !inside_transaction =>
{
ctx.report(Violation::new(
Expand All @@ -163,7 +163,7 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
None,
));
}
ast::Item::DropType(drop_type)
ast::Stmt::DropType(drop_type)
if drop_type.if_exists().is_none() && !inside_transaction =>
{
ctx.report(Violation::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/src/rules/renaming_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn renaming_column(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
for action in alter_table.actions() {
if let ast::AlterTableAction::RenameColumn(rename_column) = action {
ctx.report(Violation::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_linter/src/rules/renaming_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn renaming_table(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::AlterTable(alter_table) = item {
if let ast::Stmt::AlterTable(alter_table) = item {
for action in alter_table.actions() {
if let ast::AlterTableAction::RenameTable(rename_table) = action {
ctx.report(Violation::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) fn require_concurrent_index_creation(ctx: &mut Linter, parse: &Parse<
let file = parse.tree();
let tables_created = tables_created_in_transaction(ctx.settings.assume_in_transaction, &file);
for item in file.items() {
if let ast::Item::CreateIndex(create_index) = item {
if let ast::Stmt::CreateIndex(create_index) = item {
if let Some(table_name) = create_index
.path()
.and_then(|x| x.segment())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{Linter, Rule, Violation};
pub(crate) fn require_concurrent_index_deletion(ctx: &mut Linter, parse: &Parse<SourceFile>) {
let file = parse.tree();
for item in file.items() {
if let ast::Item::DropIndex(drop_index) = item {
if let ast::Stmt::DropIndex(drop_index) = item {
if drop_index.concurrently_token().is_none() {
ctx.report(Violation::new(
Rule::RequireConcurrentIndexDeletion,
Expand Down
4 changes: 2 additions & 2 deletions crates/squawk_linter/src/rules/transaction_nesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) fn transaction_nesting(ctx: &mut Linter, parse: &Parse<SourceFile>) {

for item in file.items() {
match item {
ast::Item::Begin(_) => {
ast::Stmt::Begin(_) => {
if ctx.settings.assume_in_transaction {
ctx.report(Violation::new(
Rule::TransactionNesting,
Expand All @@ -30,7 +30,7 @@ pub(crate) fn transaction_nesting(ctx: &mut Linter, parse: &Parse<SourceFile>) {
}
in_explicit_transaction = true;
}
ast::Item::Commit(_) | ast::Item::Rollback(_) => {
ast::Stmt::Commit(_) | ast::Stmt::Rollback(_) => {
if ctx.settings.assume_in_transaction {
ctx.report(Violation::new(
Rule::TransactionNesting,
Expand Down
4 changes: 2 additions & 2 deletions crates/squawk_linter/src/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) fn check_not_allowed_types(
) {
for item in file.items() {
match item {
ast::Item::CreateTable(create_table) => {
ast::Stmt::CreateTable(create_table) => {
if let Some(table_args) = create_table.table_args() {
for arg in table_args.args() {
if let ast::TableArg::Column(column) = arg {
Expand All @@ -50,7 +50,7 @@ pub(crate) fn check_not_allowed_types(
}
}
}
ast::Item::AlterTable(alter_table) => {
ast::Stmt::AlterTable(alter_table) => {
for action in alter_table.actions() {
match action {
ast::AlterTableAction::AddColumn(add_column) => {
Expand Down
Loading
Loading