Skip to content

Commit 6c8f04d

Browse files
committed
chore: restore splinter options and matcher crate from main
The branch was missing the splinter options feature (ignore patterns for rules) and the pgls_matcher crate that was added in main after the branch diverged. This restores those files to sync with main.
1 parent bbcb082 commit 6c8f04d

File tree

7 files changed

+380
-23
lines changed

7 files changed

+380
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pgls_lexer = { path = "./crates/pgls_lexer", version = "0.0.0"
8686
pgls_lexer_codegen = { path = "./crates/pgls_lexer_codegen", version = "0.0.0" }
8787
pgls_lsp = { path = "./crates/pgls_lsp", version = "0.0.0" }
8888
pgls_markup = { path = "./crates/pgls_markup", version = "0.0.0" }
89+
pgls_matcher = { path = "./crates/pgls_matcher", version = "0.0.0" }
8990
pgls_plpgsql_check = { path = "./crates/pgls_plpgsql_check", version = "0.0.0" }
9091
pgls_pretty_print = { path = "./crates/pgls_pretty_print", version = "0.0.0" }
9192
pgls_pretty_print_codegen = { path = "./crates/pgls_pretty_print_codegen", version = "0.0.0" }

crates/pgls_configuration/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pgls_analyser = { workspace = true }
2222
pgls_console = { workspace = true }
2323
pgls_diagnostics = { workspace = true }
2424
pgls_env = { workspace = true }
25+
pgls_matcher = { workspace = true }
2526
pgls_pretty_print = { workspace = true }
2627
pgls_text_size = { workspace = true }
2728
rustc-hash = { workspace = true }

crates/pgls_configuration/src/rules/configuration.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ impl<T: Clone + Default + 'static> RuleConfiguration<T> {
5858
}
5959
}
6060
}
61+
impl<T: Default> RuleConfiguration<T> {
62+
/// Get a reference to the typed options if present
63+
pub fn get_options_ref(&self) -> Option<&T> {
64+
match self {
65+
Self::Plain(_) => None,
66+
Self::WithOptions(options) => Some(&options.options),
67+
}
68+
}
69+
}
6170
impl<T: Default> Default for RuleConfiguration<T> {
6271
fn default() -> Self {
6372
Self::Plain(RulePlainConfiguration::Error)

crates/pgls_configuration/src/splinter/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Generated file, do not edit by hand, see `xtask/codegen`
22
33
#![doc = r" Generated file, do not edit by hand, see `xtask/codegen`"]
4+
mod options;
5+
pub use options::SplinterRuleOptions;
46
mod rules;
57
use biome_deserialize::StringSet;
68
use biome_deserialize_macros::{Merge, Partial};

crates/pgls_configuration/src/splinter/rules.rs

Lines changed: 285 additions & 21 deletions
Large diffs are not rendered by default.

xtask/codegen/src/generate_configuration.rs

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,21 @@ fn generate_lint_mod_file(tool: &ToolConfig) -> String {
172172
let generated_file = tool.generated_file().trim_end_matches(".rs");
173173
let generated_file_ident = Ident::new(generated_file, Span::call_site());
174174

175+
// For splinter, we need to include the options module
176+
let options_module = if tool.name == "splinter" {
177+
quote! {
178+
mod options;
179+
pub use options::SplinterRuleOptions;
180+
}
181+
} else {
182+
quote! {}
183+
};
184+
175185
let content = quote! {
176186
//! Generated file, do not edit by hand, see `xtask/codegen`
177187
188+
#options_module
189+
178190
mod #generated_file_ident;
179191

180192
use biome_deserialize::StringSet;
@@ -288,6 +300,34 @@ fn generate_lint_rules_file(
288300
}
289301

290302
let category_prefix = tool.category_prefix();
303+
304+
// Generate get_ignore_matchers() method for splinter only
305+
// We need to generate this method separately in each group struct
306+
// because we need direct access to the rule configurations
307+
let get_ignore_matchers_method = if tool.name == "splinter" {
308+
// Generate code to call each group's get_ignore_matchers method
309+
let mut group_matcher_code = Vec::new();
310+
for group_ident in group_idents.iter() {
311+
group_matcher_code.push(quote! {
312+
if let Some(group) = &self.#group_ident {
313+
matchers.extend(group.get_ignore_matchers());
314+
}
315+
});
316+
}
317+
318+
quote! {
319+
/// Build matchers for all rules that have ignore patterns configured.
320+
/// Returns a map from rule name (camelCase) to the matcher.
321+
pub fn get_ignore_matchers(&self) -> rustc_hash::FxHashMap<&'static str, pgls_matcher::Matcher> {
322+
let mut matchers = rustc_hash::FxHashMap::default();
323+
#( #group_matcher_code )*
324+
matchers
325+
}
326+
}
327+
} else {
328+
quote! {}
329+
};
330+
291331
let rules_struct_content = quote! {
292332
//! Generated file, do not edit by hand, see `xtask/codegen`
293333
@@ -425,6 +465,8 @@ fn generate_lint_rules_file(
425465
#( #group_as_disabled_rules )*
426466
disabled_rules
427467
}
468+
469+
#get_ignore_matchers_method
428470
}
429471

430472
#( #struct_groups )*
@@ -476,6 +518,9 @@ fn generate_lint_group_struct(
476518
let mut get_rule_configuration_line = Vec::new();
477519
let mut get_severity_lines = Vec::new();
478520

521+
// For splinter, generate code to build matchers from ignore patterns
522+
let mut splinter_ignore_matcher_lines = Vec::new();
523+
479524
for (index, (rule, metadata)) in rules.iter().enumerate() {
480525
let summary = extract_summary_from_docs(metadata.docs);
481526
let rule_position = Literal::u8_unsuffixed(index as u8);
@@ -496,10 +541,28 @@ fn generate_lint_group_struct(
496541
#rule
497542
});
498543

499-
// For splinter rules, use () as options since they don't have configurable options
544+
// For splinter, generate code to check each rule's ignore patterns
545+
if tool_name == "splinter" {
546+
let rule_str = Literal::string(rule);
547+
splinter_ignore_matcher_lines.push(quote! {
548+
if let Some(conf) = &self.#rule_identifier {
549+
if let Some(options) = conf.get_options_ref() {
550+
if !options.ignore.is_empty() {
551+
let mut m = pgls_matcher::Matcher::new(pgls_matcher::MatchOptions::default());
552+
for p in &options.ignore {
553+
let _ = m.add_pattern(p);
554+
}
555+
matchers.insert(#rule_str, m);
556+
}
557+
}
558+
}
559+
});
560+
}
561+
562+
// For splinter rules, use SplinterRuleOptions for the shared ignore patterns
500563
// For linter rules, use pgls_analyser::options::#rule_name
501564
let rule_option_type = if tool_name == "splinter" {
502-
quote! { () }
565+
quote! { crate::splinter::SplinterRuleOptions }
503566
} else {
504567
quote! { pgls_analyser::options::#rule_name }
505568
};
@@ -552,6 +615,20 @@ fn generate_lint_group_struct(
552615

553616
let group_pascal_ident = Ident::new(&to_capitalized(group), Span::call_site());
554617

618+
// For splinter, generate get_ignore_matchers method
619+
let get_ignore_matchers_group_method = if tool_name == "splinter" {
620+
quote! {
621+
/// Build matchers for rules in this group that have ignore patterns configured
622+
pub fn get_ignore_matchers(&self) -> rustc_hash::FxHashMap<&'static str, pgls_matcher::Matcher> {
623+
let mut matchers = rustc_hash::FxHashMap::default();
624+
#( #splinter_ignore_matcher_lines )*
625+
matchers
626+
}
627+
}
628+
} else {
629+
quote! {}
630+
};
631+
555632
quote! {
556633
#[derive(Clone, Debug, Default, Deserialize, Eq, Merge, PartialEq, Serialize)]
557634
#[cfg_attr(feature = "schema", derive(JsonSchema))]
@@ -652,6 +729,8 @@ fn generate_lint_group_struct(
652729
_ => None
653730
}
654731
}
732+
733+
#get_ignore_matchers_group_method
655734
}
656735
}
657736
}

0 commit comments

Comments
 (0)