Skip to content

Commit

Permalink
fix(fmt): "singleQuote": true should prefer single quote—not always…
Browse files Browse the repository at this point in the history
… use one (#21470)
  • Loading branch information
dsherret committed Dec 6, 2023
1 parent bd7a6bb commit 65993e5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cli/tools/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
Expand Down Expand Up @@ -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",
);
}
}

0 comments on commit 65993e5

Please sign in to comment.