Skip to content

Commit dac2a9c

Browse files
committed
fix(linter/no-template-curly-in-string): remove fixer (#15387)
The fixer is just too unreliable here, and it's too easy for it to generate invalid syntax/code. We don't check to see if the content between the `${`​ and `}`​ is valid, if is't not, is causes an invalid syntax tree.
1 parent 77b603e commit dac2a9c

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

crates/oxc_linter/src/rules/eslint/no_template_curly_in_string.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ declare_oxc_lint!(
4646
/// ```
4747
NoTemplateCurlyInString,
4848
eslint,
49-
style,
50-
dangerous_fix
49+
style
5150
);
5251

5352
impl Rule for NoTemplateCurlyInString {
@@ -60,11 +59,7 @@ impl Rule for NoTemplateCurlyInString {
6059
let Some(start) = text.find("${") else { return };
6160

6261
if text[start + 2..].contains('}') {
63-
let template = format!("`{text}`");
64-
ctx.diagnostic_with_dangerous_fix(
65-
no_template_curly_in_string_diagnostic(literal.span),
66-
|fixer| fixer.replace(literal.span, template),
67-
);
62+
ctx.diagnostic(no_template_curly_in_string_diagnostic(literal.span));
6863
}
6964
}
7065
}
@@ -102,18 +97,6 @@ fn test() {
10297
r#"'Hello, ${{foo: "bar"}.foo}'"#,
10398
];
10499

105-
let fix = vec![
106-
("'Hello, ${name}'", "`Hello, ${name}`"),
107-
("'Hello, ${{name}'", "`Hello, ${{name}`"),
108-
(r#""Hello, ${name}""#, r"`Hello, ${name}`"),
109-
("'${greeting}, ${name}'", "`${greeting}, ${name}`"),
110-
("'Hello, ${index + 1}'", "`Hello, ${index + 1}`"),
111-
(r#"'Hello, ${name + " foo"}'"#, r#"`Hello, ${name + " foo"}`"#),
112-
(r#"'Hello, ${name || "foo"}'"#, r#"`Hello, ${name || "foo"}`"#),
113-
(r#"'Hello, ${{foo: "bar"}.foo}'"#, r#"`Hello, ${{foo: "bar"}.foo}`"#),
114-
];
115-
116100
Tester::new(NoTemplateCurlyInString::NAME, NoTemplateCurlyInString::PLUGIN, pass, fail)
117-
.expect_fix(fix)
118101
.test_and_snapshot();
119102
}

0 commit comments

Comments
 (0)