Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion crates/pgls_cli/src/execute/process_file/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) fn check_with_guard<'ctx>(

let pull_diagnostics_result = workspace_file
.guard()
.pull_diagnostics(
.pull_file_diagnostics(
RuleCategoriesBuilder::default().all().build(),
max_diagnostics,
only,
Expand Down
754 changes: 0 additions & 754 deletions crates/pgls_configuration/src/analyser/splinter/rules.rs

This file was deleted.

29 changes: 0 additions & 29 deletions crates/pgls_configuration/src/generated/splinter.rs

This file was deleted.

3 changes: 2 additions & 1 deletion crates/pgls_configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod linter;
pub mod migrations;
pub mod plpgsql_check;
pub mod rules;
pub mod splinter;
pub mod typecheck;
pub mod vcs;

Expand Down Expand Up @@ -37,7 +38,7 @@ use plpgsql_check::{
partial_pl_pg_sql_check_configuration,
};
pub use rules::{
RuleConfiguration, RuleFixConfiguration, RulePlainConfiguration, RuleSelector,
AnalyzerGroup, RuleConfiguration, RuleFixConfiguration, RulePlainConfiguration, RuleSelector,
RuleWithFixOptions, RuleWithOptions,
};
use serde::{Deserialize, Serialize};
Expand Down
6 changes: 2 additions & 4 deletions crates/pgls_configuration/src/linter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ pub struct LinterConfiguration {
#[doc = r" List of rules"]
#[partial(bpaf(pure(Default::default()), optional, hide))]
pub rules: Rules,
#[doc = r" A list of Unix shell style patterns. The formatter will ignore files/folders that will"]
#[doc = r" match these patterns."]
#[doc = r" A list of Unix shell style patterns. The linter will ignore files/folders that will match these patterns."]
#[partial(bpaf(hide))]
pub ignore: StringSet,
#[doc = r" A list of Unix shell style patterns. The formatter will include files/folders that will"]
#[doc = r" match these patterns."]
#[doc = r" A list of Unix shell style patterns. The linter will include files/folders that will match these patterns."]
#[partial(bpaf(hide))]
pub include: StringSet,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pgls_configuration/src/linter/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ impl Rules {
#[doc = r" The function can return `None` if the rule is not properly configured."]
pub fn get_severity_from_code(&self, category: &Category) -> Option<Severity> {
let mut split_code = category.name().split('/');
let _lint = split_code.next();
debug_assert_eq!(_lint, Some("lint"));
let _category_prefix = split_code.next();
debug_assert_eq!(_category_prefix, Some("lint"));
let group = <RuleGroup as std::str::FromStr>::from_str(split_code.next()?).ok()?;
let rule_name = split_code.next()?;
let rule_name = Self::has_rule(group, rule_name)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/pgls_configuration/src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pub use configuration::{
RuleConfiguration, RuleFixConfiguration, RulePlainConfiguration, RuleWithFixOptions,
RuleWithOptions,
};
pub use selector::RuleSelector;
pub use selector::{AnalyzerGroup, RuleSelector};
98 changes: 80 additions & 18 deletions crates/pgls_configuration/src/rules/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@ use pgls_analyse::RuleFilter;

use std::str::FromStr;

use crate::{Rules, linter::RuleGroup};
/// Represents a rule group from any analyzer (linter or splinter)
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum AnalyzerGroup {
Linter(crate::linter::RuleGroup),
Splinter(crate::splinter::RuleGroup),
}

impl AnalyzerGroup {
pub const fn as_str(self) -> &'static str {
match self {
Self::Linter(group) => group.as_str(),
Self::Splinter(group) => group.as_str(),
}
}

pub const fn category_prefix(&self) -> &'static str {
match self {
Self::Linter(_) => "lint",
Self::Splinter(_) => "splinter",
}
}
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum RuleSelector {
Group(RuleGroup),
Rule(RuleGroup, &'static str),
Group(AnalyzerGroup),
Rule(AnalyzerGroup, &'static str),
}

impl From<RuleSelector> for RuleFilter<'static> {
Expand All @@ -31,20 +52,56 @@ impl<'a> From<&'a RuleSelector> for RuleFilter<'static> {
impl FromStr for RuleSelector {
type Err = &'static str;
fn from_str(selector: &str) -> Result<Self, Self::Err> {
let selector = selector.strip_prefix("lint/").unwrap_or(selector);
if let Some((group_name, rule_name)) = selector.split_once('/') {
let group = RuleGroup::from_str(group_name)?;
if let Some(rule_name) = Rules::has_rule(group, rule_name) {
Ok(RuleSelector::Rule(group, rule_name))
} else {
Err("This rule doesn't exist.")
// Try to detect the analyzer from the prefix
let (analyzer_type, rest) = if let Some(rest) = selector.strip_prefix("lint/") {
("lint", rest)
} else if let Some(rest) = selector.strip_prefix("splinter/") {
("splinter", rest)
} else {
// Default to lint for backward compatibility
("lint", selector)
};

if let Some((group_name, rule_name)) = rest.split_once('/') {
// Parse as <group>/<rule>
match analyzer_type {
"lint" => {
let group = crate::linter::RuleGroup::from_str(group_name)?;
if let Some(rule_name) = crate::linter::Rules::has_rule(group, rule_name) {
Ok(RuleSelector::Rule(AnalyzerGroup::Linter(group), rule_name))
} else {
Err("This rule doesn't exist.")
}
}
"splinter" => {
let group = crate::splinter::RuleGroup::from_str(group_name)?;
if let Some(rule_name) = crate::splinter::Rules::has_rule(group, rule_name) {
Ok(RuleSelector::Rule(
AnalyzerGroup::Splinter(group),
rule_name,
))
} else {
Err("This rule doesn't exist.")
}
}
_ => Err("Unknown analyzer type."),
}
} else {
match RuleGroup::from_str(selector) {
Ok(group) => Ok(RuleSelector::Group(group)),
Err(_) => Err(
"This group doesn't exist. Use the syntax `<group>/<rule>` to specify a rule.",
),
// Parse as just <group>
match analyzer_type {
"lint" => match crate::linter::RuleGroup::from_str(rest) {
Ok(group) => Ok(RuleSelector::Group(AnalyzerGroup::Linter(group))),
Err(_) => Err(
"This group doesn't exist. Use the syntax `<group>/<rule>` to specify a rule.",
),
},
"splinter" => match crate::splinter::RuleGroup::from_str(rest) {
Ok(group) => Ok(RuleSelector::Group(AnalyzerGroup::Splinter(group))),
Err(_) => Err(
"This group doesn't exist. Use the syntax `<group>/<rule>` to specify a rule.",
),
},
_ => Err("Unknown analyzer type."),
}
}
}
Expand All @@ -53,10 +110,15 @@ impl FromStr for RuleSelector {
impl serde::Serialize for RuleSelector {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
RuleSelector::Group(group) => serializer.serialize_str(group.as_str()),
RuleSelector::Group(group) => {
let prefix = group.category_prefix();
let group_name = group.as_str();
serializer.serialize_str(&format!("{prefix}/{group_name}"))
}
RuleSelector::Rule(group, rule_name) => {
let prefix = group.category_prefix();
let group_name = group.as_str();
serializer.serialize_str(&format!("{group_name}/{rule_name}"))
serializer.serialize_str(&format!("{prefix}/{group_name}/{rule_name}"))
}
}
}
Expand All @@ -68,7 +130,7 @@ impl<'de> serde::Deserialize<'de> for RuleSelector {
impl serde::de::Visitor<'_> for Visitor {
type Value = RuleSelector;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("<group>/<ruyle_name>")
formatter.write_str("<group>/<rule_name>")
}
fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
match RuleSelector::from_str(v) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
mod rules;
//! Generated file, do not edit by hand, see `xtask/codegen`

#![doc = r" Generated file, do not edit by hand, see `xtask/codegen`"]
mod rules;
use biome_deserialize::StringSet;
use biome_deserialize_macros::{Merge, Partial};
use bpaf::Bpaf;
pub use rules::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize)]
#[partial(derive(Bpaf, Clone, Eq, Merge, PartialEq))]
#[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))]
#[partial(serde(rename_all = "camelCase", default, deny_unknown_fields))]
pub struct SplinterConfiguration {
/// if `false`, it disables the feature and the splinter won't be executed. `true` by default
#[doc = r" if `false`, it disables the feature and the linter won't be executed. `true` by default"]
#[partial(bpaf(hide))]
pub enabled: bool,

/// List of rules
#[doc = r" List of rules"]
#[partial(bpaf(pure(Default::default()), optional, hide))]
pub rules: Rules,

/// A list of Unix shell style patterns. The splinter will ignore files/folders that will
/// match these patterns.
#[doc = r" A list of Unix shell style patterns. The linter will ignore files/folders that will match these patterns."]
#[partial(bpaf(hide))]
pub ignore: StringSet,

/// A list of Unix shell style patterns. The splinter will include files/folders that will
/// match these patterns.
#[doc = r" A list of Unix shell style patterns. The linter will include files/folders that will match these patterns."]
#[partial(bpaf(hide))]
pub include: StringSet,
}

impl SplinterConfiguration {
pub const fn is_disabled(&self) -> bool {
!self.enabled
}
}

impl Default for SplinterConfiguration {
fn default() -> Self {
Self {
Expand All @@ -46,12 +40,10 @@ impl Default for SplinterConfiguration {
}
}
}

impl PartialSplinterConfiguration {
pub const fn is_disabled(&self) -> bool {
matches!(self.enabled, Some(false))
}

pub fn get_rules(&self) -> Rules {
self.rules.clone().unwrap_or_default()
}
Expand Down
Loading