Skip to content

Commit 064b707

Browse files
psteinroeclaude
andauthored
refactor: use registry for splinter rule categories (#722)
- Replace the hardcoded Splinter rule-to-category match with `registry::get_rule_category` - Fall back to the generic `splinter` category and emit a warning for unknown rules instead of panicking - Remove unused category imports and simplify diagnostic conversion logic --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8822583 commit 064b707

File tree

3 files changed

+10
-62
lines changed

3 files changed

+10
-62
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ jobs:
190190
- name: Install toolchain
191191
uses: moonrepo/setup-rust@v1
192192
with:
193+
components: clippy
193194
cache-base: main
194195
env:
195196
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

crates/pgls_cli/src/service/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn spawn_daemon(
9191
cmd.arg(format!("--log-path={}", log_path.display()));
9292
}
9393
if let Some(log_file_name_prefix) = log_file_name_prefix {
94-
cmd.arg(format!("--log-prefix-name={}", log_file_name_prefix));
94+
cmd.arg(format!("--log-prefix-name={log_file_name_prefix}"));
9595
}
9696
cmd.creation_flags(CREATE_NEW_PROCESS_GROUP);
9797

crates/pgls_splinter/src/convert.rs

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use pgls_diagnostics::{Category, DatabaseObjectOwned, Severity, category};
1+
use pgls_diagnostics::{DatabaseObjectOwned, Severity};
22
use serde_json::Value;
33

4-
use crate::{SplinterAdvices, SplinterDiagnostic, SplinterQueryResult};
4+
use crate::{SplinterAdvices, SplinterDiagnostic, SplinterQueryResult, registry};
55

66
impl From<SplinterQueryResult> for SplinterDiagnostic {
77
fn from(result: SplinterQueryResult) -> Self {
@@ -18,8 +18,13 @@ impl From<SplinterQueryResult> for SplinterDiagnostic {
1818
.map(|s| s.to_lowercase())
1919
.unwrap_or_else(|| "unknown".to_string());
2020

21+
let category = registry::get_rule_category(&result.name).unwrap_or_else(|| {
22+
eprintln!("Warning: Unknown splinter rule: {group}/{}", result.name);
23+
pgls_diagnostics::category!("splinter")
24+
});
25+
2126
SplinterDiagnostic {
22-
category: rule_name_to_category(&result.name, &group),
27+
category,
2328
message: result.detail.into(),
2429
severity,
2530
db_object: object_name.as_ref().map(|name| DatabaseObjectOwned {
@@ -49,64 +54,6 @@ fn parse_severity(level: &str) -> Severity {
4954
}
5055
}
5156

52-
/// Convert rule name and group to a Category
53-
/// Note: Rule names use snake_case, but categories use camelCase
54-
fn rule_name_to_category(name: &str, group: &str) -> &'static Category {
55-
// we cannot use convert_case here because category! macro requires a string literal
56-
match (group, name) {
57-
("performance", "unindexed_foreign_keys") => {
58-
category!("splinter/performance/unindexedForeignKeys")
59-
}
60-
("performance", "auth_rls_initplan") => {
61-
category!("splinter/performance/authRlsInitplan")
62-
}
63-
("performance", "no_primary_key") => category!("splinter/performance/noPrimaryKey"),
64-
("performance", "unused_index") => category!("splinter/performance/unusedIndex"),
65-
("performance", "duplicate_index") => category!("splinter/performance/duplicateIndex"),
66-
("performance", "table_bloat") => category!("splinter/performance/tableBloat"),
67-
("performance", "multiple_permissive_policies") => {
68-
category!("splinter/performance/multiplePermissivePolicies")
69-
}
70-
("security", "auth_users_exposed") => category!("splinter/security/authUsersExposed"),
71-
("security", "extension_versions_outdated") => {
72-
category!("splinter/security/extensionVersionsOutdated")
73-
}
74-
("security", "policy_exists_rls_disabled") => {
75-
category!("splinter/security/policyExistsRlsDisabled")
76-
}
77-
("security", "rls_enabled_no_policy") => {
78-
category!("splinter/security/rlsEnabledNoPolicy")
79-
}
80-
("security", "security_definer_view") => {
81-
category!("splinter/security/securityDefinerView")
82-
}
83-
("security", "function_search_path_mutable") => {
84-
category!("splinter/security/functionSearchPathMutable")
85-
}
86-
("security", "rls_disabled_in_public") => {
87-
category!("splinter/security/rlsDisabledInPublic")
88-
}
89-
("security", "extension_in_public") => category!("splinter/security/extensionInPublic"),
90-
("security", "rls_references_user_metadata") => {
91-
category!("splinter/security/rlsReferencesUserMetadata")
92-
}
93-
("security", "materialized_view_in_api") => {
94-
category!("splinter/security/materializedViewInApi")
95-
}
96-
("security", "foreign_table_in_api") => {
97-
category!("splinter/security/foreignTableInApi")
98-
}
99-
("security", "unsupported_reg_types") => {
100-
category!("splinter/security/unsupportedRegTypes")
101-
}
102-
("security", "insecure_queue_exposed_in_api") => {
103-
category!("splinter/security/insecureQueueExposedInApi")
104-
}
105-
("security", "fkey_to_auth_unique") => category!("splinter/security/fkeyToAuthUnique"),
106-
_ => panic!("Unknown splinter rule: {group}/{name}"),
107-
}
108-
}
109-
11057
/// Extract common metadata fields and return the rest as additional_metadata
11158
fn extract_metadata_fields(
11259
metadata: &Value,

0 commit comments

Comments
 (0)