Skip to content

Commit

Permalink
feat: move fix to SerializableRuleCore
Browse files Browse the repository at this point in the history
fix #859
  • Loading branch information
HerringtonDarkholme committed Jan 15, 2024
1 parent f8ab6df commit 5389e37
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/config/src/rule_config.rs
Expand Up @@ -48,8 +48,12 @@ pub struct SerializableRuleCore<L: Language> {
pub utils: Option<HashMap<String, SerializableRule>>,
/// A dictionary for metavariable manipulation. Dict key is the new variable name.
/// Dict value is a [transformation] that specifies how meta var is processed.
/// Warning: this is experimental option. [`https://github.com/ast-grep/ast-grep/issues/436`]
/// See [transformation doc](https://ast-grep.github.io/reference/yaml/transformation.html).
pub transform: Option<HashMap<String, Transformation>>,
/// A pattern string or a FixConfig object to auto fix the issue.
/// It can reference metavariables appeared in rule.
/// See details in fix [object reference](https://ast-grep.github.io/reference/yaml/fix.html#fixconfig).
pub fix: Option<SerializableFixer>,
}

impl<L: Language> SerializableRuleCore<L> {
Expand Down Expand Up @@ -113,8 +117,6 @@ pub struct SerializableRuleConfig<L: Language> {
/// One of: hint, info, warning, or error
#[serde(default)]
pub severity: Severity,
/// A pattern to auto fix the issue. It can reference metavariables appeared in rule.
pub fix: Option<SerializableFixer>,
/// Glob patterns to specify that the rule only applies to matching files
pub files: Option<Vec<String>>,
/// Glob patterns that exclude rules from applying to files
Expand Down Expand Up @@ -225,14 +227,14 @@ mod test {
constraints: None,
transform: None,
utils: None,
fix: None,
};
SerializableRuleConfig {
core,
id: "".into(),
message: "".into(),
note: None,
severity: Severity::Hint,
fix: None,
files: None,
ignores: None,
url: None,
Expand Down
1 change: 1 addition & 0 deletions crates/napi/src/doc.rs
Expand Up @@ -40,6 +40,7 @@ impl NapiConfig {
constraints: self.constraints.map(serde_json::from_value).transpose()?,
transform: self.transform.map(serde_json::from_value).transpose()?,
utils: self.utils.map(serde_json::from_value).transpose()?,
fix: None,
};
rule.get_matcher(&Default::default()).map_err(|e| {
let error = Error::from(e)
Expand Down
1 change: 1 addition & 0 deletions crates/pyo3/src/py_node.rs
Expand Up @@ -306,6 +306,7 @@ fn config_from_rule(
constraints: None,
utils: None,
transform: None,
fix: None,
})
}

Expand Down

0 comments on commit 5389e37

Please sign in to comment.