fix(fmt): "singleQuote": true should prefer single quote—not always use one (#21470)

This commit is contained in:
David Sherret 2023-12-05 22:06:19 -05:00 committed by GitHub
parent bd7a6bb016
commit 65993e5efa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -523,7 +523,7 @@ fn get_resolved_typescript_config(
if let Some(single_quote) = options.single_quote {
if single_quote {
builder.quote_style(
dprint_plugin_typescript::configuration::QuoteStyle::AlwaysSingle,
dprint_plugin_typescript::configuration::QuoteStyle::PreferSingle,
);
}
}
@ -792,4 +792,23 @@ mod test {
assert_eq!(result, Some("11".to_string()));
}
#[test]
fn test_single_quote_true_prefers_single_quote() {
let file_text = format_file(
&PathBuf::from("test.ts"),
"console.log(\"there's\");\nconsole.log('hi');\nconsole.log(\"bye\")\n",
&FmtOptionsConfig {
single_quote: Some(true),
..Default::default()
},
)
.unwrap()
.unwrap();
assert_eq!(
file_text,
// should use double quotes for the string with a single quote
"console.log(\"there's\");\nconsole.log('hi');\nconsole.log('bye');\n",
);
}
}