diff --git a/tasks/rulegen/src/json.rs b/tasks/rulegen/src/json.rs index de285d7c5a34b..2a0ee943b3913 100644 --- a/tasks/rulegen/src/json.rs +++ b/tasks/rulegen/src/json.rs @@ -2,14 +2,13 @@ use std::borrow::Cow; use lazy_static::lazy_static; -/// Convert a javascript object literal to JSON by wrapping the property keys in double quote -pub fn wrap_property_in_quotes(object: &str) -> String { +/// Convert a javascript object literal to JSON by wrapping the property keys in double quote, +/// and convert the single quote to a double quote. +pub fn convert_config_to_json_literal(object: &str) -> String { use regex::{Captures, Regex}; lazy_static! { static ref IDENT_MATCHER: Regex = Regex::new(r"(?P[[:alpha:]]\w*\s*):").unwrap(); - static ref DUP_QUOTE_MATCHER: Regex = - Regex::new(r#"(?P"(?P"\w+")")"#).unwrap(); } let add_quote = IDENT_MATCHER @@ -17,6 +16,6 @@ pub fn wrap_property_in_quotes(object: &str) -> String { let ident = &capture["ident"]; Cow::Owned(format!(r#""{ident}":"#)) }) - .into_owned(); + .replace('\'', "\""); add_quote } diff --git a/tasks/rulegen/src/main.rs b/tasks/rulegen/src/main.rs index 2abe20a44bc6f..21a5de5e36a54 100644 --- a/tasks/rulegen/src/main.rs +++ b/tasks/rulegen/src/main.rs @@ -124,11 +124,12 @@ impl<'a> Visit<'a> for TestCase<'a> { self.code = match &prop.value { Expression::StringLiteral(s) => Some(s.value.to_string()), // eslint-plugin-jest use dedent to strips indentation from multi-line strings + // eslint-plugin-unicon use outdent to removes leading indentation from ES6 template strings Expression::TaggedTemplateExpression(tag_expr) => { let Expression::Identifier(ident) = &tag_expr.tag else { continue; }; - if ident.name != "dedent" { + if ident.name != "dedent" && ident.name != "outdent" { continue; } tag_expr.quasi.quasi().map(ToString::to_string) @@ -176,7 +177,8 @@ impl<'a> Visit<'a> for TestCase<'a> { PropertyKey::Identifier(ident) if ident.name == "options" => { let span = prop.value.span(); let option_text = &self.source_text[span.start as usize..span.end as usize]; - self.config = Some(Cow::Owned(json::wrap_property_in_quotes(option_text))); + self.config = + Some(Cow::Owned(json::convert_config_to_json_literal(option_text))); } _ => continue, }, @@ -199,7 +201,7 @@ impl<'a> Visit<'a> for TestCase<'a> { let Expression::Identifier(ident) = &expr.tag else { return; }; - if ident.name != "dedent" { + if ident.name != "dedent" && ident.name != "outdent" { return; } self.code = expr.quasi.quasi().map(std::string::ToString::to_string);