diff --git a/Cargo.lock b/Cargo.lock index fc4faa7c..d7822a44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2674,7 +2674,6 @@ dependencies = [ "annotate-snippets", "enum-iterator", "insta", - "lazy_static", "line-index", "rowan", "rustc-hash 2.1.1", diff --git a/Cargo.toml b/Cargo.toml index bf3e6b08..ca21076d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ console = "0.11.3" glob = "0.3.1" insta = "1.39.0" jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] } -lazy_static = "1.5.0" log = "0.4.25" reqwest = { version = "0.11.27", features = ["native-tls-vendored", "blocking", "json"] } la-arena = "0.3.1" diff --git a/crates/squawk_linter/Cargo.toml b/crates/squawk_linter/Cargo.toml index 269d778a..3c2ed994 100644 --- a/crates/squawk_linter/Cargo.toml +++ b/crates/squawk_linter/Cargo.toml @@ -18,7 +18,6 @@ squawk-syntax.workspace = true rowan.workspace = true serde.workspace = true -lazy_static.workspace = true insta.workspace = true enum-iterator.workspace = true line-index.workspace = true diff --git a/crates/squawk_linter/src/rules/adding_field_with_default.rs b/crates/squawk_linter/src/rules/adding_field_with_default.rs index aeb1288e..61404f05 100644 --- a/crates/squawk_linter/src/rules/adding_field_with_default.rs +++ b/crates/squawk_linter/src/rules/adding_field_with_default.rs @@ -1,4 +1,5 @@ -use lazy_static::lazy_static; +use std::sync::OnceLock; + use rustc_hash::FxHashSet; use squawk_syntax::ast::AstNode; @@ -7,15 +8,16 @@ use squawk_syntax::{ast, identifier::Identifier}; use crate::{Linter, Rule, Version, Violation}; -lazy_static! { - static ref NON_VOLATILE_FUNCS: FxHashSet = { +fn non_volatile_funcs() -> &'static FxHashSet { + static NON_VOLATILE_FUNCS: OnceLock> = OnceLock::new(); + NON_VOLATILE_FUNCS.get_or_init(|| { NON_VOLATILE_BUILT_IN_FUNCTIONS .split('\n') .map(|x| x.trim()) .filter(|x| !x.is_empty()) .map(Identifier::new) .collect() - }; + }) } fn is_non_volatile_or_const(expr: &ast::Expr) -> bool { @@ -40,7 +42,7 @@ fn is_non_volatile_or_const(expr: &ast::Expr) -> bool { }; let non_volatile_name = - NON_VOLATILE_FUNCS.contains(&Identifier::new(name_ref.text().as_str())); + non_volatile_funcs().contains(&Identifier::new(name_ref.text().as_str())); no_args && non_volatile_name } else { diff --git a/crates/squawk_linter/src/rules/ban_char_field.rs b/crates/squawk_linter/src/rules/ban_char_field.rs index 02fc8768..25425a7f 100644 --- a/crates/squawk_linter/src/rules/ban_char_field.rs +++ b/crates/squawk_linter/src/rules/ban_char_field.rs @@ -10,20 +10,21 @@ use squawk_syntax::{ use crate::visitors::check_not_allowed_types; use crate::{Edit, Fix, Linter, Rule, Violation}; -use lazy_static::lazy_static; - -lazy_static! { - static ref CHAR_TYPES: FxHashSet = [ - Identifier::new("char"), - Identifier::new("character"), - Identifier::new("bpchar"), - ] - .into_iter() - .collect(); +use std::sync::OnceLock; + +fn char_types() -> &'static FxHashSet { + static CHAR_TYPES: OnceLock> = OnceLock::new(); + CHAR_TYPES.get_or_init(|| { + FxHashSet::from_iter([ + Identifier::new("char"), + Identifier::new("character"), + Identifier::new("bpchar"), + ]) + }) } fn is_char_type(x: TokenText<'_>) -> bool { - CHAR_TYPES.contains(&Identifier::new(x.as_ref())) + char_types().contains(&Identifier::new(x.as_ref())) } fn create_fix(range: TextRange, args: Option) -> Fix { diff --git a/crates/squawk_linter/src/rules/prefer_bigint_over_int.rs b/crates/squawk_linter/src/rules/prefer_bigint_over_int.rs index e1bcfa32..dc07c26c 100644 --- a/crates/squawk_linter/src/rules/prefer_bigint_over_int.rs +++ b/crates/squawk_linter/src/rules/prefer_bigint_over_int.rs @@ -8,18 +8,19 @@ use crate::{Edit, Fix, Linter, Rule, Violation}; use crate::visitors::check_not_allowed_types; use crate::visitors::is_not_valid_int_type; -use lazy_static::lazy_static; - -lazy_static! { - static ref INT_TYPES: FxHashSet = [ - Identifier::new("int"), - Identifier::new("integer"), - Identifier::new("int4"), - Identifier::new("serial"), - Identifier::new("serial4"), - ] - .into_iter() - .collect(); +use std::sync::OnceLock; + +fn int_types() -> &'static FxHashSet { + static INT_TYPES: OnceLock> = OnceLock::new(); + INT_TYPES.get_or_init(|| { + FxHashSet::from_iter([ + Identifier::new("int"), + Identifier::new("integer"), + Identifier::new("int4"), + Identifier::new("serial"), + Identifier::new("serial4"), + ]) + }) } fn int_to_bigint_replacement(int_type: &str) -> &'static str { @@ -44,7 +45,7 @@ fn create_bigint_fix(ty: &ast::Type) -> Option { fn check_ty_for_big_int(ctx: &mut Linter, ty: Option) { if let Some(ty) = ty { - if is_not_valid_int_type(&ty, &INT_TYPES) { + if is_not_valid_int_type(&ty, int_types()) { let fix = create_bigint_fix(&ty); ctx.report( diff --git a/crates/squawk_linter/src/rules/prefer_bigint_over_smallint.rs b/crates/squawk_linter/src/rules/prefer_bigint_over_smallint.rs index 4f88cac9..9791bf97 100644 --- a/crates/squawk_linter/src/rules/prefer_bigint_over_smallint.rs +++ b/crates/squawk_linter/src/rules/prefer_bigint_over_smallint.rs @@ -8,17 +8,18 @@ use crate::{Edit, Fix, Linter, Rule, Violation}; use crate::visitors::check_not_allowed_types; use crate::visitors::is_not_valid_int_type; -use lazy_static::lazy_static; - -lazy_static! { - static ref SMALL_INT_TYPES: FxHashSet = [ - Identifier::new("smallint"), - Identifier::new("int2"), - Identifier::new("smallserial"), - Identifier::new("serial2"), - ] - .into_iter() - .collect(); +use std::sync::OnceLock; + +fn small_int_types() -> &'static FxHashSet { + static SMALL_INT_TYPES: OnceLock> = OnceLock::new(); + SMALL_INT_TYPES.get_or_init(|| { + FxHashSet::from_iter([ + Identifier::new("smallint"), + Identifier::new("int2"), + Identifier::new("smallserial"), + Identifier::new("serial2"), + ]) + }) } fn smallint_to_bigint(smallint_type: &str) -> &'static str { @@ -43,7 +44,7 @@ fn create_bigint_fix(ty: &ast::Type) -> Option { fn check_ty_for_small_int(ctx: &mut Linter, ty: Option) { if let Some(ty) = ty { - if is_not_valid_int_type(&ty, &SMALL_INT_TYPES) { + if is_not_valid_int_type(&ty, small_int_types()) { let fix = create_bigint_fix(&ty); ctx.report( diff --git a/crates/squawk_linter/src/rules/prefer_identity.rs b/crates/squawk_linter/src/rules/prefer_identity.rs index 868902ba..78173485 100644 --- a/crates/squawk_linter/src/rules/prefer_identity.rs +++ b/crates/squawk_linter/src/rules/prefer_identity.rs @@ -8,21 +8,22 @@ use squawk_syntax::{ use crate::{Edit, Fix, Linter, Rule, Violation}; -use lazy_static::lazy_static; +use std::sync::OnceLock; use crate::visitors::{check_not_allowed_types, is_not_valid_int_type}; -lazy_static! { - static ref SERIAL_TYPES: FxHashSet = [ - Identifier::new("serial"), - Identifier::new("serial2"), - Identifier::new("serial4"), - Identifier::new("serial8"), - Identifier::new("smallserial"), - Identifier::new("bigserial"), - ] - .into_iter() - .collect(); +fn serial_types() -> &'static FxHashSet { + static SERIAL_TYPES: OnceLock> = OnceLock::new(); + SERIAL_TYPES.get_or_init(|| { + FxHashSet::from_iter([ + Identifier::new("serial"), + Identifier::new("serial2"), + Identifier::new("serial4"), + Identifier::new("serial8"), + Identifier::new("smallserial"), + Identifier::new("bigserial"), + ]) + }) } fn replace_serial(serial_type: &str) -> &'static str { @@ -43,7 +44,7 @@ fn create_identity_fix(ty: &ast::Type) -> Option { fn check_ty_for_serial(ctx: &mut Linter, ty: Option) { if let Some(ty) = ty { - if is_not_valid_int_type(&ty, &SERIAL_TYPES) { + if is_not_valid_int_type(&ty, serial_types()) { let fix = create_identity_fix(&ty); ctx.report( diff --git a/crates/squawk_linter/src/rules/prefer_text_field.rs b/crates/squawk_linter/src/rules/prefer_text_field.rs index ec4d6c42..6139fe18 100644 --- a/crates/squawk_linter/src/rules/prefer_text_field.rs +++ b/crates/squawk_linter/src/rules/prefer_text_field.rs @@ -1,5 +1,3 @@ -use rustc_hash::FxHashSet; - use squawk_syntax::{ Parse, SourceFile, ast::{self, AstNode}, @@ -10,12 +8,6 @@ use crate::{Edit, Fix, Linter, Rule, Violation}; use crate::visitors::check_not_allowed_types; -use lazy_static::lazy_static; - -lazy_static! { - static ref VARCHAR_TYPE_NAMES: FxHashSet<&'static str> = ["varchar"].into_iter().collect(); -} - fn is_not_allowed_varchar(ty: &ast::Type) -> bool { match ty { ast::Type::ArrayType(array_type) => {