Skip to content

Commit 031e38d

Browse files
committed
make it simpleeeer
1 parent ada2084 commit 031e38d

14 files changed

+124
-564
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ tree_sitter_sql = { path = "./lib/tree_sitter_sql", version = "0.0.0" }
4646
unicode-width = "0.1.12"
4747

4848
# postgres specific crates
49-
pg_base_db = { path = "./crates/pg_base_db", version = "0.0.0" }
5049
pg_analyse = { path = "./crates/pg_analyse", version = "0.0.0" }
50+
pg_base_db = { path = "./crates/pg_base_db", version = "0.0.0" }
5151
pg_cli = { path = "./crates/pg_cli", version = "0.0.0" }
5252
pg_commands = { path = "./crates/pg_commands", version = "0.0.0" }
5353
pg_completions = { path = "./crates/pg_completions", version = "0.0.0" }

crates/pg_analyse/Cargo.toml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@ version = "0.0.0"
1313

1414

1515
[dependencies]
16-
pg_schema_cache.workspace = true
17-
pg_diagnostics.workspace = true
18-
pg_console.workspace = true
19-
pg_query_ext.workspace = true
20-
rustc-hash = { workspace = true }
16+
pg_console.workspace = true
17+
pg_diagnostics.workspace = true
18+
pg_query_ext.workspace = true
19+
pg_schema_cache.workspace = true
20+
rustc-hash = { workspace = true }
2121

22-
text-size.workspace = true
23-
enumflags2.workspace = true
24-
serde = { workspace = true, features = ["derive"], optional = true }
2522
biome_deserialize = { workspace = true, optional = true }
2623
biome_deserialize_macros = { workspace = true, optional = true }
24+
enumflags2.workspace = true
25+
serde = { workspace = true, features = ["derive"], optional = true }
26+
text-size.workspace = true
2727

2828
[features]
2929
serde = ["dep:serde", "dep:biome_deserialize", "dep:biome_deserialize_macros"]
30-

crates/pg_analyse/src/categories.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,3 @@ impl RuleCategoriesBuilder {
332332
RuleCategories(self.flags)
333333
}
334334
}
335-
336-
337-
338-

crates/pg_analyse/src/context.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use pg_diagnostics::{Error, Result};
22
use std::path::Path;
33

4-
use crate::{categories::RuleCategory, rule::{GroupCategory, Rule, RuleGroup, RuleMetadata}};
4+
use crate::{
5+
categories::RuleCategory,
6+
rule::{GroupCategory, Rule, RuleGroup, RuleMetadata},
7+
};
58

69
pub struct RuleContext<'a, R: Rule> {
710
stmt: &'a pg_query_ext::NodeEnum,
@@ -15,7 +18,7 @@ where
1518
{
1619
#[allow(clippy::too_many_arguments)]
1720
pub fn new(
18-
stmt: &'a pg_query_ext::NodeEnum,
21+
stmt: &'a pg_query_ext::NodeEnum,
1922
file_path: &'a Path,
2023
options: &'a R::Options,
2124
) -> Result<Self, Error> {
@@ -86,4 +89,3 @@ where
8689
self.file_path
8790
}
8891
}
89-

crates/pg_analyse/src/diagnostics.rs

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

crates/pg_analyse/src/filter.rs

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
use std::fmt::{Display, Formatter, Debug};
1+
use std::fmt::{Debug, Display, Formatter};
22

33
use text_size::TextRange;
44

5-
use crate::{categories::RuleCategories, rule::{GroupCategory, Rule, RuleGroup}, RuleFilter};
5+
use crate::{
6+
categories::RuleCategories,
7+
rule::{GroupCategory, Rule, RuleGroup},
8+
};
9+
10+
/// Allow filtering a single rule or group of rules by their names
11+
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
12+
pub enum RuleFilter<'a> {
13+
Group(&'a str),
14+
Rule(&'a str, &'a str),
15+
}
616

717
/// Allows filtering the list of rules that will be executed in a run of the analyzer,
818
/// and at what source code range signals (diagnostics or actions) may be raised
@@ -58,8 +68,6 @@ impl<'analysis> AnalysisFilter<'analysis> {
5868
}
5969
}
6070

61-
62-
6371
impl<'a> RuleFilter<'a> {
6472
// Returns the group name of this filter.
6573
pub fn group(self) -> &'a str {
@@ -122,3 +130,64 @@ impl<'a> pg_console::fmt::Display for RuleFilter<'a> {
122130
}
123131
}
124132

133+
/// Opaque identifier for a group of rule
134+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
135+
pub struct GroupKey {
136+
group: &'static str,
137+
}
138+
139+
impl GroupKey {
140+
pub(crate) fn new(group: &'static str) -> Self {
141+
Self { group }
142+
}
143+
144+
pub fn group<G: RuleGroup>() -> Self {
145+
Self::new(G::NAME)
146+
}
147+
}
148+
149+
impl From<GroupKey> for RuleFilter<'static> {
150+
fn from(key: GroupKey) -> Self {
151+
RuleFilter::Group(key.group)
152+
}
153+
}
154+
155+
/// Opaque identifier for a single rule
156+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
157+
pub struct RuleKey {
158+
group: &'static str,
159+
rule: &'static str,
160+
}
161+
162+
impl RuleKey {
163+
pub fn new(group: &'static str, rule: &'static str) -> Self {
164+
Self { group, rule }
165+
}
166+
167+
pub fn rule<R: Rule>() -> Self {
168+
Self::new(<R::Group as RuleGroup>::NAME, R::METADATA.name)
169+
}
170+
171+
pub fn group(&self) -> &'static str {
172+
self.group
173+
}
174+
175+
pub fn rule_name(&self) -> &'static str {
176+
self.rule
177+
}
178+
}
179+
180+
impl From<RuleKey> for RuleFilter<'static> {
181+
fn from(key: RuleKey) -> Self {
182+
RuleFilter::Rule(key.group, key.rule)
183+
}
184+
}
185+
186+
impl PartialEq<RuleKey> for RuleFilter<'static> {
187+
fn eq(&self, other: &RuleKey) -> bool {
188+
match *self {
189+
RuleFilter::Group(group) => group == other.group,
190+
RuleFilter::Rule(group, rule) => group == other.group && rule == other.rule,
191+
}
192+
}
193+
}

crates/pg_analyse/src/lib.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
mod categories;
22
mod context;
3-
mod diagnostics;
43
mod filter;
5-
mod matcher;
64
mod options;
75
mod registry;
86
mod rule;
9-
mod signals;
107

118
pub use crate::categories::{
129
ActionCategory, RefactorKind, RuleCategories, RuleCategoriesBuilder, RuleCategory,
1310
SourceActionKind, SUPPRESSION_ACTION_CATEGORY,
1411
};
15-
// pub use crate::diagnostics::{AnalyzerDiagnostic, RuleError, SuppressionDiagnostic};
16-
pub use crate::matcher::RuleKey;
1712
pub use crate::options::{AnalyzerConfiguration, AnalyzerOptions, AnalyzerRules};
18-
// pub use crate::query::{AddVisitor, QueryKey, QueryMatch, Queryable};
19-
pub use crate::registry::{
20-
MetadataRegistry, RegistryVisitor,
21-
RuleRegistry, RuleRegistryBuilder,
22-
};
23-
pub use crate::rule::{Rule};
24-
// pub use crate::rule::{
25-
// GroupCategory, Rule, RuleAction, RuleDiagnostic, RuleGroup, RuleMeta, RuleMetadata, RuleSource,
26-
// RuleSourceKind, SuppressAction,
27-
// };
28-
29-
/// Allow filtering a single rule or group of rules by their names
30-
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
31-
pub enum RuleFilter<'a> {
32-
Group(&'a str),
33-
Rule(&'a str, &'a str),
34-
}
13+
pub use crate::registry::{MetadataRegistry, RegistryVisitor, RuleRegistry, RuleRegistryBuilder};
14+
pub use crate::rule::Rule;

0 commit comments

Comments
 (0)