Skip to content

Commit a1ea831

Browse files
committed
chore: bump rust version to 2024
1 parent 50d0fe0 commit a1ea831

20 files changed

Lines changed: 98 additions & 110 deletions

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "pg-migration-lint"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
authors = ["pg-migration-lint contributors"]
66
description = "Static analyzer for PostgreSQL migration files"
77
license = "MIT OR Apache-2.0"

src/catalog/replay.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ fn apply_drop_index(catalog: &mut Catalog, di: &DropIndex) {
143143
.find(|t| t.indexes.iter().any(|idx| idx.name == di.index_name))
144144
.map(|t| t.name.clone());
145145

146-
if let Some(table_name) = owning_table {
147-
if let Some(table) = catalog.get_table_mut(&table_name) {
148-
table.indexes.retain(|idx| idx.name != di.index_name);
149-
}
146+
if let Some(table_name) = owning_table
147+
&& let Some(table) = catalog.get_table_mut(&table_name)
148+
{
149+
table.indexes.retain(|idx| idx.name != di.index_name);
150150
}
151151
}
152152

@@ -158,10 +158,10 @@ fn apply_drop_table(catalog: &mut Catalog, dt: &DropTable) {
158158

159159
/// Handle Unparseable: if a table_hint is provided, mark that table as incomplete.
160160
fn apply_unparseable(catalog: &mut Catalog, table_hint: &Option<String>) {
161-
if let Some(hint) = table_hint {
162-
if let Some(table) = catalog.get_table_mut(hint) {
163-
table.incomplete = true;
164-
}
161+
if let Some(hint) = table_hint
162+
&& let Some(table) = catalog.get_table_mut(hint)
163+
{
164+
table.incomplete = true;
165165
}
166166
}
167167

src/input/liquibase_xml.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
//! not processed, so the catalog can be flagged as potentially incomplete.
2020
2121
use crate::input::{LoadError, RawMigrationUnit};
22-
use quick_xml::events::Event;
2322
use quick_xml::Reader;
23+
use quick_xml::events::Event;
2424
use std::path::{Path, PathBuf};
2525

2626
/// Lightweight XML fallback loader for Liquibase changelogs.
@@ -1154,9 +1154,11 @@ mod tests {
11541154
.expect("Should parse changeset with multiple changes");
11551155
assert_eq!(units.len(), 1);
11561156
assert!(units[0].sql.contains("CREATE TABLE users"));
1157-
assert!(units[0]
1158-
.sql
1159-
.contains("CREATE INDEX idx_users_id ON users (id);"));
1157+
assert!(
1158+
units[0]
1159+
.sql
1160+
.contains("CREATE INDEX idx_users_id ON users (id);")
1161+
);
11601162
}
11611163

11621164
#[test]

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ fn run(args: Args) -> Result<bool> {
225225

226226
let fail_on_str = args.fail_on.as_deref().unwrap_or(&config.cli.fail_on);
227227
let fail_on = Severity::parse(fail_on_str);
228-
if let Some(threshold) = fail_on {
229-
if all_findings.iter().any(|f| f.severity >= threshold) {
230-
return Ok(true);
231-
}
228+
if let Some(threshold) = fail_on
229+
&& all_findings.iter().any(|f| f.severity >= threshold)
230+
{
231+
return Ok(true);
232232
}
233233

234234
Ok(false)

src/output/sarif.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ mod tests {
239239
assert_eq!(parsed["runs"][0]["results"][0]["ruleId"], "PGM001");
240240
assert_eq!(parsed["runs"][0]["results"][0]["level"], "error");
241241
assert_eq!(
242-
parsed["runs"][0]["results"][0]["locations"][0]["physicalLocation"]["region"]
243-
["startLine"],
242+
parsed["runs"][0]["results"][0]["locations"][0]["physicalLocation"]["region"]["startLine"],
244243
3
245244
);
246245
assert_eq!(
@@ -354,10 +353,11 @@ mod tests {
354353
let content = std::fs::read_to_string(dir.path().join("findings.sarif")).expect("read");
355354
let parsed: serde_json::Value = serde_json::from_str(&content).expect("parse json");
356355

357-
let uri = parsed["runs"][0]["results"][0]["locations"][0]["physicalLocation"]
358-
["artifactLocation"]["uri"]
359-
.as_str()
360-
.expect("uri string");
356+
let uri =
357+
parsed["runs"][0]["results"][0]["locations"][0]["physicalLocation"]["artifactLocation"]
358+
["uri"]
359+
.as_str()
360+
.expect("uri string");
361361
assert!(!uri.contains('\\'));
362362
assert!(uri.contains('/'));
363363
}

src/parser/pg_query.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -494,21 +494,21 @@ fn convert_table_constraint(
494494
match con.contype() {
495495
pg_query::protobuf::ConstrType::ConstrPrimary => {
496496
let mut columns = extract_string_list(&con.keys);
497-
if columns.is_empty() {
498-
if let Some(col) = context_column {
499-
columns.push(col.to_string());
500-
}
497+
if columns.is_empty()
498+
&& let Some(col) = context_column
499+
{
500+
columns.push(col.to_string());
501501
}
502502
Some(TableConstraint::PrimaryKey { columns })
503503
}
504504
pg_query::protobuf::ConstrType::ConstrForeign => {
505505
let ref_table = relation_to_qualified_name(con.pktable.as_ref());
506506
let ref_columns = extract_string_list(&con.pk_attrs);
507507
let mut columns = extract_string_list(&con.fk_attrs);
508-
if columns.is_empty() {
509-
if let Some(col) = context_column {
510-
columns.push(col.to_string());
511-
}
508+
if columns.is_empty()
509+
&& let Some(col) = context_column
510+
{
511+
columns.push(col.to_string());
512512
}
513513
Some(TableConstraint::ForeignKey {
514514
name,
@@ -519,10 +519,10 @@ fn convert_table_constraint(
519519
}
520520
pg_query::protobuf::ConstrType::ConstrUnique => {
521521
let mut columns = extract_string_list(&con.keys);
522-
if columns.is_empty() {
523-
if let Some(col) = context_column {
524-
columns.push(col.to_string());
525-
}
522+
if columns.is_empty()
523+
&& let Some(col) = context_column
524+
{
525+
columns.push(col.to_string());
526526
}
527527
Some(TableConstraint::Unique { name, columns })
528528
}
@@ -729,16 +729,13 @@ fn deparse_node(node: &pg_query::protobuf::Node) -> String {
729729
};
730730

731731
// Replace the target list's value with our node
732-
if let Some(stmt) = parse_result.protobuf.stmts.first_mut() {
733-
if let Some(ref mut stmt_node) = stmt.stmt {
734-
if let Some(NodeEnum::SelectStmt(ref mut select)) = stmt_node.node {
735-
if let Some(first_target) = select.target_list.first_mut() {
736-
if let Some(NodeEnum::ResTarget(ref mut res)) = first_target.node {
737-
res.val = Some(Box::new(node.clone()));
738-
}
739-
}
740-
}
741-
}
732+
if let Some(stmt) = parse_result.protobuf.stmts.first_mut()
733+
&& let Some(ref mut stmt_node) = stmt.stmt
734+
&& let Some(NodeEnum::SelectStmt(ref mut select)) = stmt_node.node
735+
&& let Some(first_target) = select.target_list.first_mut()
736+
&& let Some(NodeEnum::ResTarget(ref mut res)) = first_target.node
737+
{
738+
res.val = Some(Box::new(node.clone()));
742739
}
743740

744741
match pg_query::deparse(&parse_result.protobuf) {

src/rules/pgm001.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ impl Rule for Pgm001 {
9191
#[cfg(test)]
9292
mod tests {
9393
use super::*;
94-
use crate::catalog::builder::CatalogBuilder;
9594
use crate::catalog::Catalog;
95+
use crate::catalog::builder::CatalogBuilder;
9696
use crate::parser::ir::*;
9797
use std::collections::HashSet;
9898
use std::path::PathBuf;

src/rules/pgm002.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ impl Rule for Pgm002 {
8888
#[cfg(test)]
8989
mod tests {
9090
use super::*;
91-
use crate::catalog::builder::CatalogBuilder;
9291
use crate::catalog::Catalog;
92+
use crate::catalog::builder::CatalogBuilder;
9393
use crate::parser::ir::*;
9494
use std::collections::HashSet;
9595
use std::path::PathBuf;

src/rules/pgm003.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ impl Rule for Pgm003 {
143143
#[cfg(test)]
144144
mod tests {
145145
use super::*;
146-
use crate::catalog::builder::CatalogBuilder;
147146
use crate::catalog::Catalog;
147+
use crate::catalog::builder::CatalogBuilder;
148148
use crate::parser::ir::*;
149149
use std::collections::HashSet;
150150
use std::path::PathBuf;

src/rules/pgm004.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ impl Rule for Pgm004 {
9797
#[cfg(test)]
9898
mod tests {
9999
use super::*;
100-
use crate::catalog::builder::CatalogBuilder;
101100
use crate::catalog::Catalog;
101+
use crate::catalog::builder::CatalogBuilder;
102102
use crate::parser::ir::*;
103103
use std::collections::HashSet;
104104
use std::path::PathBuf;

0 commit comments

Comments
 (0)