Skip to content

Commit 813624a

Browse files
psteinroeclaude
andauthored
chore(splinter): integrate runtime (#620)
- wires up the actual execution of splinter with existing `AnalysisFilter` to dynamically build the query by combining the parts with `UNION ALL`. - we skip the rules that are supbase-only if the target database isnt supabase - prepares docs integration by embedding metadata, configuration and the actual sql in the `RuleMeta` comment. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent cf54370 commit 813624a

File tree

105 files changed

+2928
-2879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+2928
-2879
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pgls_analyser/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pub use linter_rule::{LinterDiagnostic, LinterRule};
2323
pub use LinterDiagnostic as RuleDiagnostic;
2424
pub use LinterRule as Rule;
2525
pub use LinterRuleContext as RuleContext;
26-
2726
pub static METADATA: LazyLock<MetadataRegistry> = LazyLock::new(|| {
2827
let mut metadata = MetadataRegistry::default();
2928
// 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)