Skip to content
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

refactor: move fixer to RuleCore #860

Merged
merged 6 commits into from Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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