diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-12-05 22:06:19 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-05 22:06:19 -0500 |
commit | 65993e5efa5931c7a50b1fe926a0fa43eae0ca13 (patch) | |
tree | 655651478c9b72cef02530bfa69d8db35a2b531b | |
parent | bd7a6bb0161c3f75785dc6431220c20f0d50c8fd (diff) |
fix(fmt): `"singleQuote": true` should prefer single quote—not always use one (#21470)
-rw-r--r-- | cli/tools/fmt.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 36828e23c..084da7fd4 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -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", + ); + } } |