-
Notifications
You must be signed in to change notification settings - Fork 112
feat(splinter): allow ignoring db objects #634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| use biome_deserialize_macros::Deserializable; | ||
| #[cfg(feature = "schema")] | ||
| use schemars::JsonSchema; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Shared options for all splinter rules. | ||
| /// | ||
| /// These options allow configuring per-rule filtering of database objects. | ||
| #[derive(Clone, Debug, Default, Deserialize, Deserializable, Eq, PartialEq, Serialize)] | ||
| #[cfg_attr(feature = "schema", derive(JsonSchema))] | ||
| #[serde(rename_all = "camelCase", deny_unknown_fields)] | ||
| pub struct SplinterRuleOptions { | ||
| /// A list of glob patterns for database objects to ignore. | ||
| /// | ||
| /// Patterns use Unix-style globs where: | ||
| /// - `*` matches any sequence of characters | ||
| /// - `?` matches any single character | ||
| /// | ||
| /// Each pattern should be in the format `schema.object_name`, for example: | ||
| /// - `"public.my_table"` - ignores a specific table | ||
| /// - `"audit.*"` - ignores all objects in the audit schema | ||
| /// - `"*.audit_*"` - ignores objects with audit_ prefix in any schema | ||
| #[serde(default)] | ||
| pub ignore: Vec<String>, | ||
| } |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [package] | ||
| authors.workspace = true | ||
| categories.workspace = true | ||
| description = "Unix shell style pattern matching for Postgres Language Server" | ||
| edition.workspace = true | ||
| homepage.workspace = true | ||
| keywords.workspace = true | ||
| license.workspace = true | ||
| name = "pgls_matcher" | ||
| repository.workspace = true | ||
| version = "0.0.0" | ||
|
|
||
| [dependencies] | ||
| pgls_console = { workspace = true } | ||
| pgls_diagnostics = { workspace = true } | ||
| rustc-hash = { workspace = true } |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ pub mod rule; | |||
| pub mod rules; | ||||
|
|
||||
| use pgls_analyse::{AnalysisFilter, RegistryVisitor, RuleMeta}; | ||||
| use pgls_configuration::splinter::Rules; | ||||
| use pgls_schema_cache::SchemaCache; | ||||
| use sqlx::PgPool; | ||||
|
|
||||
|
|
@@ -17,6 +18,8 @@ pub use rule::SplinterRule; | |||
| pub struct SplinterParams<'a> { | ||||
| pub conn: &'a PgPool, | ||||
| pub schema_cache: Option<&'a SchemaCache>, | ||||
| /// Optional rules configuration for per-rule database object filtering | ||||
| pub rules_config: Option<&'a Rules>, | ||||
| } | ||||
|
|
||||
| /// Visitor that collects enabled splinter rules based on filter | ||||
|
|
@@ -134,7 +137,35 @@ pub async fn run_splinter( | |||
| tx.commit().await?; | ||||
|
|
||||
| // Convert results to diagnostics | ||||
| let diagnostics: Vec<SplinterDiagnostic> = results.into_iter().map(Into::into).collect(); | ||||
| let mut diagnostics: Vec<SplinterDiagnostic> = results.into_iter().map(Into::into).collect(); | ||||
|
|
||||
| // Apply per-rule object filtering if rules config is provided | ||||
| if let Some(rules_config) = params.rules_config { | ||||
| let rule_matchers = rules_config.get_ignore_matchers(); | ||||
|
|
||||
| if !rule_matchers.is_empty() { | ||||
| diagnostics.retain(|diag| { | ||||
| // Extract rule name from category (e.g., "splinter/performance/noPrimaryKey" -> "noPrimaryKey") | ||||
| let rule_name = diag.category.name().split('/').next_back().unwrap_or(""); | ||||
|
|
||||
| // Look up pre-built matcher for this rule | ||||
|
||||
| // Look up pre-built matcher for this rule |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Build object identifier from schema and name |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // If the object matches an ignore pattern, filter it out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.