diff --git a/CHANGELOG.md b/CHANGELOG.md index da1c175bea8..dfb89695235 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,8 +31,12 @@ ### Editors ### Formatter +- Added a new option called `--jsx-quote-style` to the formatter. This option allows you to choose between single and double quotes for JSX attributes. [#4486](https://github.com/rome/tools/issues/4486) + ### Linter +- Fix a crash in the `NoParameterAssign` rule that occurred when there was a bogus binding. [#4323](https://github.com/rome/tools/issues/4323) + #### Other changes - `noRedeclare`: allow redeclare of index signatures are in different type members [#4478](https://github.com/rome/tools/issues/4478) diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index 1817f2c3110..14333f57db5 100644 --- a/crates/rome_cli/tests/commands/check.rs +++ b/crates/rome_cli/tests/commands/check.rs @@ -2274,6 +2274,38 @@ if (true) { )); } +#[test] +fn apply_bogus_argument() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Path::new("fix.js"); + fs.insert( + file_path.into(), + "function _13_1_3_fun(arguments) { }".as_bytes(), + ); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(&[ + ("check"), + file_path.as_os_str().to_str().unwrap(), + ("--apply-unsafe"), + ]), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "apply_bogus_argument", + fs, + console, + result, + )); +} + #[test] fn ignores_unknown_file() { let mut fs = MemoryFileSystem::default(); diff --git a/crates/rome_cli/tests/commands/format.rs b/crates/rome_cli/tests/commands/format.rs index f2ed9400461..72ec82e9cd8 100644 --- a/crates/rome_cli/tests/commands/format.rs +++ b/crates/rome_cli/tests/commands/format.rs @@ -19,6 +19,15 @@ const CUSTOM_FORMAT_AFTER: &str = r#"function f() { } "#; +const APPLY_JSX_QUOTE_STYLE_BEFORE: &str = r#" +
"#; + +const APPLY_JSX_QUOTE_STYLE_AFTER: &str = r#"
; +"#; + const APPLY_QUOTE_STYLE_BEFORE: &str = r#" let a = "something"; let b = { @@ -538,6 +547,50 @@ fn applies_custom_configuration_over_config_file_issue_3175_v2() { )); } +#[test] +fn applies_custom_jsx_quote_style() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Path::new("file.js"); + fs.insert(file_path.into(), APPLY_JSX_QUOTE_STYLE_BEFORE.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(&[ + ("format"), + ("--jsx-quote-style"), + ("single"), + ("--quote-properties"), + ("preserve"), + ("--write"), + file_path.as_os_str().to_str().unwrap(), + ]), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let mut file = fs + .open(file_path) + .expect("formatting target file was removed by the CLI"); + + let mut content = String::new(); + file.read_to_string(&mut content) + .expect("failed to read file from memory FS"); + + assert_eq!(content, APPLY_JSX_QUOTE_STYLE_AFTER); + + drop(file); + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "applies_custom_jsx_quote_style", + fs, + console, + result, + )); +} + #[test] fn applies_custom_quote_style() { let mut fs = MemoryFileSystem::default(); diff --git a/crates/rome_cli/tests/configs.rs b/crates/rome_cli/tests/configs.rs index def817fd34c..26924a97272 100644 --- a/crates/rome_cli/tests/configs.rs +++ b/crates/rome_cli/tests/configs.rs @@ -76,6 +76,7 @@ pub const CONFIG_ALL_FIELDS: &str = r#"{ "globals": ["$"], "formatter": { "quoteStyle": "double", + "jsxQuoteStyle": "double", "quoteProperties": "asNeeded" } } diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/apply_bogus_argument.snap b/crates/rome_cli/tests/snapshots/main_commands_check/apply_bogus_argument.snap new file mode 100644 index 00000000000..f5dd858ad26 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_check/apply_bogus_argument.snap @@ -0,0 +1,18 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +expression: content +--- +## `fix.js` + +```js +function _13_1_3_fun(arguments) { } + +``` + +# Emitted Messages + +```block +Fixed 1 file(s) in