Skip to content

Commit 08d9b38

Browse files
committed
refactor: remove type aliases from pgls_analyser
Removed confusing type aliases that created two names for the same types: - Rule → LinterRule - RuleContext → LinterRuleContext - RuleDiagnostic → LinterDiagnostic Updated all 34 rule files and the codegen template to use the full type names for better clarity and consistency. The aliases made the API confusing by having two names for the same type (e.g., "is RuleDiagnostic different from LinterDiagnostic?"). All rule implementations now consistently use: - use crate::{LinterRule, LinterRuleContext, LinterDiagnostic}; - impl LinterRule for RuleName { ... }
1 parent c5f8b07 commit 08d9b38

36 files changed

+158
-1070
lines changed

PLAN.md

Lines changed: 0 additions & 907 deletions
This file was deleted.

crates/pgls_analyser/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ pub use linter_registry::{
1919
};
2020
pub use linter_rule::{LinterDiagnostic, LinterRule};
2121

22-
// For convenience in macros and rule files - keep these shorter names
23-
pub use LinterDiagnostic as RuleDiagnostic;
24-
pub use LinterRule as Rule;
25-
pub use LinterRuleContext as RuleContext;
26-
2722
pub static METADATA: LazyLock<MetadataRegistry> = LazyLock::new(|| {
2823
let mut metadata = MetadataRegistry::default();
2924
// Use a separate visitor for metadata that implements pgls_analyse::RegistryVisitor

crates/pgls_analyser/src/lint/safety/add_serial_column.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Rule, RuleContext, RuleDiagnostic};
1+
use crate::{LinterDiagnostic, LinterRule, LinterRuleContext};
22
use pgls_analyse::{RuleSource, declare_lint_rule};
33
use pgls_console::markup;
44
use pgls_diagnostics::Severity;
@@ -38,10 +38,10 @@ declare_lint_rule! {
3838
}
3939
}
4040

41-
impl Rule for AddSerialColumn {
41+
impl LinterRule for AddSerialColumn {
4242
type Options = ();
4343

44-
fn run(ctx: &RuleContext<Self>) -> Vec<RuleDiagnostic> {
44+
fn run(ctx: &LinterRuleContext<Self>) -> Vec<LinterDiagnostic> {
4545
let mut diagnostics = Vec::new();
4646

4747
if let pgls_query::NodeEnum::AlterTableStmt(stmt) = &ctx.stmt() {
@@ -56,7 +56,7 @@ impl Rule for AddSerialColumn {
5656
let type_str = get_type_name(type_name);
5757
if is_serial_type(&type_str) {
5858
diagnostics.push(
59-
RuleDiagnostic::new(
59+
LinterDiagnostic::new(
6060
rule_category!(),
6161
None,
6262
markup! {
@@ -86,7 +86,7 @@ impl Rule for AddSerialColumn {
8686

8787
if has_stored_generated {
8888
diagnostics.push(
89-
RuleDiagnostic::new(
89+
LinterDiagnostic::new(
9090
rule_category!(),
9191
None,
9292
markup! {

crates/pgls_analyser/src/lint/safety/adding_field_with_default.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Rule, RuleContext, RuleDiagnostic};
1+
use crate::{LinterDiagnostic, LinterRule, LinterRuleContext};
22
use pgls_analyse::{RuleSource, declare_lint_rule};
33
use pgls_console::markup;
44
use pgls_diagnostics::Severity;
@@ -39,10 +39,10 @@ declare_lint_rule! {
3939
}
4040
}
4141

42-
impl Rule for AddingFieldWithDefault {
42+
impl LinterRule for AddingFieldWithDefault {
4343
type Options = ();
4444

45-
fn run(ctx: &RuleContext<Self>) -> Vec<RuleDiagnostic> {
45+
fn run(ctx: &LinterRuleContext<Self>) -> Vec<LinterDiagnostic> {
4646
let mut diagnostics = Vec::new();
4747

4848
// Check PostgreSQL version - in 11+, non-volatile defaults are safe
@@ -75,7 +75,7 @@ impl Rule for AddingFieldWithDefault {
7575

7676
if has_generated {
7777
diagnostics.push(
78-
RuleDiagnostic::new(
78+
LinterDiagnostic::new(
7979
rule_category!(),
8080
None,
8181
markup! {
@@ -102,7 +102,7 @@ impl Rule for AddingFieldWithDefault {
102102

103103
if !is_safe_default {
104104
diagnostics.push(
105-
RuleDiagnostic::new(
105+
LinterDiagnostic::new(
106106
rule_category!(),
107107
None,
108108
markup! {
@@ -116,7 +116,7 @@ impl Rule for AddingFieldWithDefault {
116116
} else {
117117
// Pre PG 11, all defaults cause rewrites
118118
diagnostics.push(
119-
RuleDiagnostic::new(
119+
LinterDiagnostic::new(
120120
rule_category!(),
121121
None,
122122
markup! {

crates/pgls_analyser/src/lint/safety/adding_foreign_key_constraint.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Rule, RuleContext, RuleDiagnostic};
1+
use crate::{LinterDiagnostic, LinterRule, LinterRuleContext};
22
use pgls_analyse::{RuleSource, declare_lint_rule};
33
use pgls_console::markup;
44
use pgls_diagnostics::Severity;
@@ -43,10 +43,10 @@ declare_lint_rule! {
4343
}
4444
}
4545

46-
impl Rule for AddingForeignKeyConstraint {
46+
impl LinterRule for AddingForeignKeyConstraint {
4747
type Options = ();
4848

49-
fn run(ctx: &RuleContext<Self>) -> Vec<RuleDiagnostic> {
49+
fn run(ctx: &LinterRuleContext<Self>) -> Vec<LinterDiagnostic> {
5050
let mut diagnostics = Vec::new();
5151

5252
if let pgls_query::NodeEnum::AlterTableStmt(stmt) = &ctx.stmt() {
@@ -95,7 +95,7 @@ impl Rule for AddingForeignKeyConstraint {
9595
fn check_foreign_key_constraint(
9696
constraint: &pgls_query::protobuf::Constraint,
9797
is_column_constraint: bool,
98-
) -> Option<RuleDiagnostic> {
98+
) -> Option<LinterDiagnostic> {
9999
// Only check foreign key constraints
100100
if constraint.contype() != pgls_query::protobuf::ConstrType::ConstrForeign {
101101
return None;
@@ -121,7 +121,7 @@ fn check_foreign_key_constraint(
121121
};
122122

123123
Some(
124-
RuleDiagnostic::new(rule_category!(), None, markup! { {message} })
124+
LinterDiagnostic::new(rule_category!(), None, markup! { {message} })
125125
.detail(None, detail)
126126
.note(note),
127127
)

crates/pgls_analyser/src/lint/safety/adding_not_null_field.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Rule, RuleContext, RuleDiagnostic};
1+
use crate::{LinterDiagnostic, LinterRule, LinterRuleContext};
22
use pgls_analyse::{RuleSource, declare_lint_rule};
33
use pgls_console::markup;
44
use pgls_diagnostics::Severity;
@@ -42,10 +42,10 @@ declare_lint_rule! {
4242
}
4343
}
4444

45-
impl Rule for AddingNotNullField {
45+
impl LinterRule for AddingNotNullField {
4646
type Options = ();
4747

48-
fn run(ctx: &RuleContext<Self>) -> Vec<RuleDiagnostic> {
48+
fn run(ctx: &LinterRuleContext<Self>) -> Vec<LinterDiagnostic> {
4949
let mut diagnostics = Vec::new();
5050

5151
// In Postgres 11+, this is less of a concern
@@ -60,7 +60,7 @@ impl Rule for AddingNotNullField {
6060
for cmd in &stmt.cmds {
6161
if let Some(pgls_query::NodeEnum::AlterTableCmd(cmd)) = &cmd.node {
6262
if cmd.subtype() == pgls_query::protobuf::AlterTableType::AtSetNotNull {
63-
diagnostics.push(RuleDiagnostic::new(
63+
diagnostics.push(LinterDiagnostic::new(
6464
rule_category!(),
6565
None,
6666
markup! {

crates/pgls_analyser/src/lint/safety/adding_primary_key_constraint.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Rule, RuleContext, RuleDiagnostic};
1+
use crate::{LinterDiagnostic, LinterRule, LinterRuleContext};
22
use pgls_analyse::{RuleSource, declare_lint_rule};
33
use pgls_console::markup;
44
use pgls_diagnostics::Severity;
@@ -40,10 +40,10 @@ declare_lint_rule! {
4040
}
4141
}
4242

43-
impl Rule for AddingPrimaryKeyConstraint {
43+
impl LinterRule for AddingPrimaryKeyConstraint {
4444
type Options = ();
4545

46-
fn run(ctx: &RuleContext<Self>) -> Vec<RuleDiagnostic> {
46+
fn run(ctx: &LinterRuleContext<Self>) -> Vec<LinterDiagnostic> {
4747
let mut diagnostics = Vec::new();
4848

4949
if let pgls_query::NodeEnum::AlterTableStmt(stmt) = &ctx.stmt() {
@@ -92,12 +92,12 @@ impl Rule for AddingPrimaryKeyConstraint {
9292

9393
fn check_for_primary_key_constraint(
9494
constraint: &pgls_query::protobuf::Constraint,
95-
) -> Option<RuleDiagnostic> {
95+
) -> Option<LinterDiagnostic> {
9696
if constraint.contype() == pgls_query::protobuf::ConstrType::ConstrPrimary
9797
&& constraint.indexname.is_empty()
9898
{
9999
Some(
100-
RuleDiagnostic::new(
100+
LinterDiagnostic::new(
101101
rule_category!(),
102102
None,
103103
markup! {

crates/pgls_analyser/src/lint/safety/adding_required_field.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Rule, RuleContext, RuleDiagnostic};
1+
use crate::{LinterDiagnostic, LinterRule, LinterRuleContext};
22
use pgls_analyse::{RuleSource, declare_lint_rule};
33
use pgls_console::markup;
44
use pgls_diagnostics::Severity;
@@ -25,10 +25,10 @@ declare_lint_rule! {
2525
}
2626
}
2727

28-
impl Rule for AddingRequiredField {
28+
impl LinterRule for AddingRequiredField {
2929
type Options = ();
3030

31-
fn run(ctx: &RuleContext<Self>) -> Vec<RuleDiagnostic> {
31+
fn run(ctx: &LinterRuleContext<Self>) -> Vec<LinterDiagnostic> {
3232
let mut diagnostics = vec![];
3333

3434
if let pgls_query::NodeEnum::AlterTableStmt(stmt) = ctx.stmt() {
@@ -47,7 +47,7 @@ impl Rule for AddingRequiredField {
4747
== pgls_query::protobuf::AlterTableType::AtAddColumn
4848
{
4949
diagnostics.push(
50-
RuleDiagnostic::new(
50+
LinterDiagnostic::new(
5151
rule_category!(),
5252
None,
5353
markup! {

crates/pgls_analyser/src/lint/safety/ban_char_field.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Rule, RuleContext, RuleDiagnostic};
1+
use crate::{LinterDiagnostic, LinterRule, LinterRuleContext};
22
use pgls_analyse::{RuleSource, declare_lint_rule};
33
use pgls_console::markup;
44
use pgls_diagnostics::Severity;
@@ -41,10 +41,10 @@ declare_lint_rule! {
4141
}
4242
}
4343

44-
impl Rule for BanCharField {
44+
impl LinterRule for BanCharField {
4545
type Options = ();
4646

47-
fn run(ctx: &RuleContext<Self>) -> Vec<RuleDiagnostic> {
47+
fn run(ctx: &LinterRuleContext<Self>) -> Vec<LinterDiagnostic> {
4848
let mut diagnostics = Vec::new();
4949

5050
if let pgls_query::NodeEnum::CreateStmt(stmt) = &ctx.stmt() {
@@ -78,7 +78,9 @@ impl Rule for BanCharField {
7878
}
7979
}
8080

81-
fn check_column_for_char_type(col_def: &pgls_query::protobuf::ColumnDef) -> Option<RuleDiagnostic> {
81+
fn check_column_for_char_type(
82+
col_def: &pgls_query::protobuf::ColumnDef,
83+
) -> Option<LinterDiagnostic> {
8284
if let Some(type_name) = &col_def.type_name {
8385
for name_node in &type_name.names {
8486
if let Some(pgls_query::NodeEnum::String(name)) = &name_node.node {
@@ -87,7 +89,7 @@ fn check_column_for_char_type(col_def: &pgls_query::protobuf::ColumnDef) -> Opti
8789
let type_str = name.sval.to_lowercase();
8890
if type_str == "bpchar" || type_str == "char" || type_str == "character" {
8991
return Some(
90-
RuleDiagnostic::new(
92+
LinterDiagnostic::new(
9193
rule_category!(),
9294
None,
9395
markup! {

crates/pgls_analyser/src/lint/safety/ban_concurrent_index_creation_in_transaction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Rule, RuleContext, RuleDiagnostic};
1+
use crate::{LinterDiagnostic, LinterRule, LinterRuleContext};
22
use pgls_analyse::{RuleSource, declare_lint_rule};
33
use pgls_console::markup;
44
use pgls_diagnostics::Severity;
@@ -27,10 +27,10 @@ declare_lint_rule! {
2727
}
2828
}
2929

30-
impl Rule for BanConcurrentIndexCreationInTransaction {
30+
impl LinterRule for BanConcurrentIndexCreationInTransaction {
3131
type Options = ();
3232

33-
fn run(ctx: &RuleContext<Self>) -> Vec<RuleDiagnostic> {
33+
fn run(ctx: &LinterRuleContext<Self>) -> Vec<LinterDiagnostic> {
3434
let mut diagnostics = Vec::new();
3535

3636
// check if the current statement is CREATE INDEX CONCURRENTLY and there is at least one
@@ -39,7 +39,7 @@ impl Rule for BanConcurrentIndexCreationInTransaction {
3939
// since our analyser assumes we're always in a transaction context, we always flag concurrent indexes
4040
if let pgls_query::NodeEnum::IndexStmt(stmt) = ctx.stmt() {
4141
if stmt.concurrent && ctx.file_context().stmt_count() > 1 {
42-
diagnostics.push(RuleDiagnostic::new(
42+
diagnostics.push(LinterDiagnostic::new(
4343
rule_category!(),
4444
None,
4545
markup! {

0 commit comments

Comments
 (0)