-
Notifications
You must be signed in to change notification settings - Fork 106
refactor: config codegen #598
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
Open
psteinroe
wants to merge
6
commits into
main
Choose a base branch
from
refactor/config-codegen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+914
−775
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e32289
refactor: config codegen
psteinroe d3f0a21
fix: update imports and resolve clippy warnings
psteinroe 4d6e4ba
fix: order roles alphabetically and update test expectations
psteinroe 14ee3b8
progress
psteinroe fd92394
Merge branch 'main' into refactor/config-codegen
psteinroe b9b130c
progress
psteinroe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| pub(crate) mod configuration; | ||
| pub(crate) mod selector; | ||
|
|
||
| pub use configuration::{ | ||
| RuleAssistConfiguration, RuleAssistPlainConfiguration, RuleAssistWithOptions, | ||
| RuleConfiguration, RuleFixConfiguration, RulePlainConfiguration, RuleWithFixOptions, | ||
| RuleWithOptions, | ||
| }; | ||
| pub use selector::RuleSelector; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| use pgls_analyse::RuleFilter; | ||
|
|
||
| use std::str::FromStr; | ||
|
|
||
| use crate::{Rules, linter::RuleGroup}; | ||
|
|
||
| #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] | ||
| pub enum RuleSelector { | ||
| Group(RuleGroup), | ||
| Rule(RuleGroup, &'static str), | ||
| } | ||
|
|
||
| impl From<RuleSelector> for RuleFilter<'static> { | ||
| fn from(value: RuleSelector) -> Self { | ||
| match value { | ||
| RuleSelector::Group(group) => RuleFilter::Group(group.as_str()), | ||
| RuleSelector::Rule(group, name) => RuleFilter::Rule(group.as_str(), name), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<'a> From<&'a RuleSelector> for RuleFilter<'static> { | ||
| fn from(value: &'a RuleSelector) -> Self { | ||
| match value { | ||
| RuleSelector::Group(group) => RuleFilter::Group(group.as_str()), | ||
| RuleSelector::Rule(group, name) => RuleFilter::Rule(group.as_str(), name), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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.") | ||
| } | ||
| } 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.", | ||
| ), | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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::Rule(group, rule_name) => { | ||
| let group_name = group.as_str(); | ||
| serializer.serialize_str(&format!("{group_name}/{rule_name}")) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<'de> serde::Deserialize<'de> for RuleSelector { | ||
| fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { | ||
| struct Visitor; | ||
| 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>") | ||
| } | ||
| fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> { | ||
| match RuleSelector::from_str(v) { | ||
| Ok(result) => Ok(result), | ||
| Err(error) => Err(serde::de::Error::custom(error)), | ||
| } | ||
| } | ||
| } | ||
| deserializer.deserialize_str(Visitor) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "schema")] | ||
| impl schemars::JsonSchema for RuleSelector { | ||
| fn schema_name() -> String { | ||
| "RuleCode".to_string() | ||
| } | ||
| fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema { | ||
| String::json_schema(r#gen) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this will be made more generic in a future pr