From 87b7eb16f684e7eb80206ce808c12e4384c7378b Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Thu, 3 Feb 2022 14:50:44 +0000 Subject: [PATCH 01/10] test: custom tests for formatter --- CONTRIBUTING.md | 31 ++++- Cargo.lock | 10 +- crates/rome_formatter/Cargo.toml | 2 + crates/rome_formatter/src/lib.rs | 19 +++ crates/rome_formatter/tests/spec_test.rs | 114 ++++++++++++++++-- crates/rome_formatter/tests/spec_tests.rs | 4 +- .../tests/specs/js/import/named_import.js | 2 - .../js/module/array/array_nested.js.snap | 11 +- .../js/module/array/binding_pattern.js.snap | 12 +- .../specs/js/module/array/empty_lines.js.snap | 12 +- .../specs/js/module/array/spaces.js.snap | 11 +- .../specs/js/module/array/spread.js.snap | 11 +- .../js/module/arrow/arrow_function.js.snap | 11 +- .../js/module/arrow/arrow_nested.js.snap | 12 +- .../tests/specs/js/module/arrow/call.js.snap | 12 +- .../specs/js/module/arrow/currying.js.snap | 12 +- .../specs/js/module/arrow/params.js.snap | 12 +- .../js/module/assignment/assignment.js.snap | 11 +- .../js/module/binding/array_binding.js.snap | 11 +- .../module/binding/identifier_binding.js.snap | 12 +- .../js/module/binding/object_binding.js.snap | 12 +- .../tests/specs/js/module/class/class.js.snap | 12 +- .../js/module/class/class_comments.js.snap | 12 +- .../js/module/class/private_method.js.snap | 12 +- .../tests/specs/js/module/comments.js.snap | 12 +- .../js/module/export/class_clause.js.snap | 12 +- .../module/export/expression_clause.js.snap | 12 +- .../js/module/export/from_clause.js.snap | 12 +- .../js/module/export/function_clause.js.snap | 12 +- .../js/module/export/named_clause.js.snap | 12 +- .../module/export/named_from_clause.js.snap | 12 +- .../export/variable_declaration.js.snap | 12 +- .../expression/binary_expression.js.snap | 11 +- .../expression/conditional_expression.js.snap | 11 +- .../import_meta_expression.js | 0 .../import_meta_expression.js.snap | 22 +++- .../import_meta_expression/options.json | 8 ++ .../expression/literal_expression.js.snap | 11 +- .../expression/logical_expression.js.snap | 11 +- .../module/expression/new_expression.js.snap | 11 +- .../expression/post_update_expression.js.snap | 11 +- .../expression/pre_update_expression.js.snap | 11 +- .../expression/sequence_expression.js.snap | 11 +- .../static_member_expression.js.snap | 11 +- .../module/expression/this_expression.js.snap | 11 +- .../expression/unary_expression.js.snap | 12 +- .../js/module/function/function_args.js.snap | 12 +- .../module/function/function_comments.js.snap | 12 +- .../tests/specs/js/module/ident.js.snap | 11 +- .../js/module/import/bare_import.js.snap | 12 +- .../js/module/import/default_import.js.snap | 12 +- .../js/module/import/import_call.js.snap | 11 +- .../module/import/import_specifiers.js.snap | 12 +- .../js/module/import/namespace_import.js.snap | 12 +- .../js/module/invalid/block_stmt_err.js.snap | 12 +- .../js/module/invalid/if_stmt_err.js.snap | 12 +- .../tests/specs/js/module/newlines.js.snap | 12 +- .../specs/js/module/number/number.js.snap | 11 +- .../js/module/object/computed_member.js.snap | 12 +- .../js/module/object/getter_setter.js.snap | 11 +- .../specs/js/module/object/object.js.snap | 12 +- .../js/module/object/object_comments.js.snap | 12 +- .../js/module/object/property_key.js.snap | 11 +- .../js/module/parentheses/parentheses.js.snap | 11 +- .../tests/specs/js/module/script.js.snap | 12 +- .../js/module/statement/do_while.js.snap | 12 +- .../specs/js/module/statement/for_in.js.snap | 12 +- .../js/module/statement/for_loop.js.snap | 11 +- .../specs/js/module/statement/if_else.js.snap | 12 +- .../js/module/statement/statement.js.snap | 11 +- .../specs/js/module/statement/switch.js.snap | 12 +- .../specs/js/module/statement/throw.js.snap | 12 +- .../statement/try_catch_finally.js.snap | 12 +- .../js/module/statement/while_loop.js.snap | 12 +- .../specs/js/module/template/template.js.snap | 12 +- .../tests/specs/js/module/with.js.snap | 12 +- .../tests/specs/js/script/script.js.snap | 11 +- .../tests/specs/js/script/with.js.snap | 12 +- crates/rslint_parser/src/tests.rs | 4 +- crates/tests_macros/src/lib.rs | 11 +- 80 files changed, 814 insertions(+), 204 deletions(-) delete mode 100644 crates/rome_formatter/tests/specs/js/import/named_import.js rename crates/rome_formatter/tests/specs/js/{expression => module/expression/import_meta_expression}/import_meta_expression.js (100%) rename crates/rome_formatter/tests/specs/js/{expression => module/expression/import_meta_expression}/import_meta_expression.js.snap (58%) create mode 100644 crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c6e36d11fee..746f6677da9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -198,19 +198,23 @@ The command will tell the test suite to generate and update the `.rast` files. If tests that are inside the `ok/` folder fail or if tests that are inside the `err/` folder don't emit, the whole test suite will fail. -### Write snapshot tests for the formatter + +### Write tests for the formatter We use [insta.rs](https://insta.rs/docs) for our snapshot tests, please make sure you read its documentation to learn the basics of snapshot testing. You should install the companion [`cargo-insta`](https://insta.rs/docs/cli/) command to assist with snapshot reviewing. -To create a new snapshot test for JavaScript, create a new file to `crates/rome_formatter/tests/specs/javascript`, e.g. `arrow.js` +To create a new snapshot test for JavaScript, create a new file to `crates/rome_formatter/tests/specs/js/`, e.g. `arrow_with_spaces.js` ```javascript -const foo = () => { +const foo = () => { return bar } ``` +Files processed as modules must go inside the `module/` directory, files processed as script must go inside the +`script/` directory. + Run the following command to generate the new snapshot (the snapshot tests are generated by a procedure macro so we need to recompile the tests): ```bash @@ -226,3 +230,24 @@ cargo watch -i '*.new' -x 'test -p rome_formatter formatter' After test execution, you will get a new `arrow.js.snap.new` file. To actually update the snapshot, run `cargo insta review` to interactively review and accept the pending snapshot. `arrow.js.snap.new` will be replaced with `arrow.js.snap` + +Sometimes, you need to verify the formatting for different cases/options. In order to do that, create a folder with +the cases you need to verify. If we needed to follow the previous example: + +1. create a folder called `arrow_with_spaces/` and move the JS file there; +2. then create a file called `options.json` +3. The content would be something like: + ```json + { + "cases": [ + { + "line_width": 120, + "indent_style": {"Space": 4} + } + ] + } + ```` +4. the `cases` keyword is mandatory; +5. then each object of the array will contain the matrix of options you'd want to test. +In this case the test suite will run a **second test case** with `line_width` to 120 and `ident_style` with 4 spaces +6. when the test suite is run, you will have two outputs in your snapshot: the default one and the custom one \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 71aedd8f927..14e553f3482 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1228,6 +1228,8 @@ dependencies = [ "rome_path", "rome_rowan", "rslint_parser", + "serde", + "serde_json", "tests_macros", "thiserror", ] @@ -1408,9 +1410,9 @@ checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" [[package]] name = "serde" -version = "1.0.135" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cf9235533494ea2ddcdb794665461814781c53f19d87b76e571a1c35acbad2b" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" dependencies = [ "serde_derive", ] @@ -1427,9 +1429,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.135" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dcde03d87d4c973c04be249e7d8f0b35db1c848c487bd43032808e59dd8328d" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" dependencies = [ "proc-macro2", "quote", diff --git a/crates/rome_formatter/Cargo.toml b/crates/rome_formatter/Cargo.toml index e9f8435935d..e2ae108c7fa 100644 --- a/crates/rome_formatter/Cargo.toml +++ b/crates/rome_formatter/Cargo.toml @@ -16,3 +16,5 @@ thiserror = "1.0.30" [dev-dependencies] tests_macros = { path = "../tests_macros" } insta = "1.10.0" +serde = { version = "1", features = ["derive"] } +serde_json = "1" diff --git a/crates/rome_formatter/src/lib.rs b/crates/rome_formatter/src/lib.rs index 7b3a5f9d9c2..f2c4a685e78 100644 --- a/crates/rome_formatter/src/lib.rs +++ b/crates/rome_formatter/src/lib.rs @@ -55,11 +55,13 @@ pub mod formatter_traits; mod intersperse; mod printer; mod ts; + pub use formatter::Formatter; use rome_rowan::TextRange; use rome_rowan::TextSize; use rome_rowan::TokenAtOffset; use rslint_parser::{parse, Syntax, SyntaxError, SyntaxNode}; +use std::fmt::Display; pub use format_element::{ block_indent, concat_elements, empty_element, empty_line, group_elements, hard_line_break, @@ -141,6 +143,15 @@ impl FromStr for IndentStyle { } } +impl Display for IndentStyle { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + IndentStyle::Tab => write!(f, "Tab"), + IndentStyle::Space(size) => write!(f, "Spaces, size: {}", size), + } + } +} + #[derive(Debug, Clone, Copy)] pub struct FormatOptions { /// The indent style @@ -168,6 +179,14 @@ impl Default for FormatOptions { } } +impl Display for FormatOptions { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!(f, "Indent style: {}", self.indent_style)?; + writeln!(f, "Line width: {}", self.line_width)?; + Ok(()) + } +} + /// Lightweight sourcemap marker between source and output tokens #[derive(Debug, Clone, Eq, PartialEq)] pub struct SourceMarker { diff --git a/crates/rome_formatter/tests/spec_test.rs b/crates/rome_formatter/tests/spec_test.rs index 194cebbacb3..19d28a33459 100644 --- a/crates/rome_formatter/tests/spec_test.rs +++ b/crates/rome_formatter/tests/spec_test.rs @@ -1,9 +1,90 @@ use rome_core::App; -use rome_formatter::{format, FormatOptions}; +use rome_formatter::{format, FormatOptions, IndentStyle}; use rome_path::RomePath; use rslint_parser::{parse, Syntax}; +use serde::{Deserialize, Serialize}; +use std::fmt::Debug; use std::fs; -use std::path::Path; +use std::path::{Path, PathBuf}; + +#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] +pub enum IndentStyleTest { + /// Tab + Tab, + /// Space, with its quantity + Space(u8), +} + +impl From for IndentStyle { + fn from(test: IndentStyleTest) -> Self { + match test { + IndentStyleTest::Tab => IndentStyle::Tab, + IndentStyleTest::Space(s) => IndentStyle::Space(s), + } + } +} + +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct FormatOptionsTest { + /// The indent style + pub indent_style: Option, + + /// What's the max width of a line. Defaults to 80 + pub line_width: Option, +} + +impl From for FormatOptions { + fn from(test: FormatOptionsTest) -> Self { + Self { + indent_style: test + .indent_style + .map_or_else(|| IndentStyle::Tab, |value| value.into()), + line_width: test.line_width.unwrap_or(80), + } + } +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct Options { + cases: Vec, +} + +#[derive(Debug, Default)] +struct SnapshotContent { + input: String, + output: Vec<(String, FormatOptions)>, +} + +impl SnapshotContent { + pub fn add_output(&mut self, content: &str, options: FormatOptions) { + self.output.push((String::from(content), options)) + } + + pub fn set_input(&mut self, content: &str) { + self.input = String::from(content); + } + + pub fn snap_content(&mut self) -> String { + let mut output = String::new(); + output.push_str("# Input"); + output.push('\n'); + output.push_str(self.input.as_str()); + output.push_str("\n=============================\n"); + + output.push_str("# Outputs\n"); + let iter = self.output.iter(); + for (index, (content, options)) in iter.enumerate() { + let formal_index = index + 1; + output.push_str(format!("## Output {formal_index}\n").as_str()); + output.push_str("-----\n"); + output.push_str(format!("{}\n", options).as_str()); + output.push_str("-----\n"); + output.push_str(content.as_str()); + } + + output + } +} /// [insta.rs](https://insta.rs/docs) snapshot testing /// @@ -22,7 +103,7 @@ use std::path::Path; /// /// * `json/null` -> input: `tests/specs/json/null.json`, expected output: `tests/specs/json/null.json.snap` /// * `null` -> input: `tests/specs/null.json`, expected output: `tests/specs/null.json.snap` -pub fn run(spec_input_file: &str, _: &str, file_type: &str) { +pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, file_type: &str) { let app = App::new(); let file_path = &spec_input_file; let spec_input_file = Path::new(spec_input_file); @@ -35,6 +116,7 @@ pub fn run(spec_input_file: &str, _: &str, file_type: &str) { let mut rome_path = RomePath::new(file_path); if app.can_format(&rome_path) { + let mut snapshot_content = SnapshotContent::default(); let buffer = rome_path.get_buffer_from_file(); let syntax = if file_type == "module" { Syntax::default().module() @@ -42,19 +124,37 @@ pub fn run(spec_input_file: &str, _: &str, file_type: &str) { Syntax::default() }; + let input = fs::read_to_string(file_path).unwrap(); + snapshot_content.set_input(input.as_str()); + let root = parse(buffer.as_str(), 0, syntax).syntax(); let formatted_result = format(FormatOptions::default(), &root); let file_name = spec_input_file.file_name().unwrap().to_str().unwrap(); - let input = fs::read_to_string(file_path).unwrap(); - let result = formatted_result.unwrap(); // we ignore the error for now - let snapshot = format!("# Input\n{}\n---\n# Output\n{}", input, result.as_code()); + let result = formatted_result.unwrap(); + + snapshot_content.add_output(result.as_code(), FormatOptions::default()); + + let test_directory = PathBuf::from(test_directory); + let options_path = test_directory.join("options.json"); + if options_path.exists() { + let mut options_path = RomePath::new(options_path.display().to_string().as_str()); + // SAFETY: we checked its existence already, we assume we have rights to read it + let options: Options = + serde_json::from_str(options_path.get_buffer_from_file().as_str()).unwrap(); + + for test_case in options.cases { + let options = test_case.clone(); + let formatted_result = format(test_case.into(), &root).unwrap(); + snapshot_content.add_output(formatted_result.as_code(), options.into()); + } + } insta::with_settings!({ prepend_module_to_snapshot => false, snapshot_path => spec_input_file.parent().unwrap(), }, { - insta::assert_snapshot!(file_name, snapshot, file_name); + insta::assert_snapshot!(file_name, snapshot_content.snap_content(), file_name); }); } } diff --git a/crates/rome_formatter/tests/spec_tests.rs b/crates/rome_formatter/tests/spec_tests.rs index 66b8418eb69..0823605eb00 100644 --- a/crates/rome_formatter/tests/spec_tests.rs +++ b/crates/rome_formatter/tests/spec_tests.rs @@ -4,11 +4,11 @@ mod formatter { mod js_module { use crate::spec_test; - tests_macros::gen_tests! {"tests/specs/js/module/**/**/*.js", spec_test::run, "module"} + tests_macros::gen_tests! {"tests/specs/js/module/**/**/**/*.js", spec_test::run, "module"} } mod js_script { use crate::spec_test; - tests_macros::gen_tests! {"tests/specs/js/script/**/**/*.js", spec_test::run, "script"} + tests_macros::gen_tests! {"tests/specs/js/script/**/**/**/*.js", spec_test::run, "script"} } } diff --git a/crates/rome_formatter/tests/specs/js/import/named_import.js b/crates/rome_formatter/tests/specs/js/import/named_import.js deleted file mode 100644 index 4fd5c3036f6..00000000000 --- a/crates/rome_formatter/tests/specs/js/import/named_import.js +++ /dev/null @@ -1,2 +0,0 @@ -import "very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_"; - diff --git a/crates/rome_formatter/tests/specs/js/module/array/array_nested.js.snap b/crates/rome_formatter/tests/specs/js/module/array/array_nested.js.snap index d6f729ee0f1..ccf776f0428 100644 --- a/crates/rome_formatter/tests/specs/js/module/array/array_nested.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/array/array_nested.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: array_nested.js --- @@ -46,8 +47,14 @@ let m1 = [{ a, b }, { a }, { a }]; let n1 = [{ a, b }, { a, b }]; let o1 = [{ a, b }, { a, b, c }]; ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- let a = [[]]; let b = [[], []]; let c = [[], [], []]; diff --git a/crates/rome_formatter/tests/specs/js/module/array/binding_pattern.js.snap b/crates/rome_formatter/tests/specs/js/module/array/binding_pattern.js.snap index 2cd3c282cf9..e20c1098fc3 100644 --- a/crates/rome_formatter/tests/specs/js/module/array/binding_pattern.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/array/binding_pattern.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: binding_pattern.js --- @@ -9,8 +9,14 @@ let [a,b]=c; let [d,...e]=c; let [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,...cccccccccccccccccccccccccccccc]=f; ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- let [a, b] = c; let [d, ...e] = c; let [ diff --git a/crates/rome_formatter/tests/specs/js/module/array/empty_lines.js.snap b/crates/rome_formatter/tests/specs/js/module/array/empty_lines.js.snap index b45ece50d8f..cfda4e909fa 100644 --- a/crates/rome_formatter/tests/specs/js/module/array/empty_lines.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/array/empty_lines.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: empty_lines.js --- @@ -18,8 +18,14 @@ let a = [ ]; ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- let a = [ 1, 2, diff --git a/crates/rome_formatter/tests/specs/js/module/array/spaces.js.snap b/crates/rome_formatter/tests/specs/js/module/array/spaces.js.snap index 3c563749842..c7ed988880a 100644 --- a/crates/rome_formatter/tests/specs/js/module/array/spaces.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/array/spaces.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: spaces.js --- @@ -10,8 +11,14 @@ let c = [,,1,]; let d = [,,1,1]; let e = [2,2,1,3]; ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- let a = [,]; let b = [, ,]; let c = [, , 1]; diff --git a/crates/rome_formatter/tests/specs/js/module/array/spread.js.snap b/crates/rome_formatter/tests/specs/js/module/array/spread.js.snap index b9773c025a3..6580dded634 100644 --- a/crates/rome_formatter/tests/specs/js/module/array/spread.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/array/spread.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: spread.js --- @@ -10,8 +11,14 @@ let b = [...a, ...b]; let a = [...baaaaaaaaaaaaaaaaaaaaaaaaaaaaa,...bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,...cccccccccccccccccccccccccccccc] ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- let a = [...a, ...b]; let b = [...a, ...b]; [...a]; diff --git a/crates/rome_formatter/tests/specs/js/module/arrow/arrow_function.js.snap b/crates/rome_formatter/tests/specs/js/module/arrow/arrow_function.js.snap index e946c9084b9..6e35b9b561d 100644 --- a/crates/rome_formatter/tests/specs/js/module/arrow/arrow_function.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/arrow/arrow_function.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: arrow_function.js --- @@ -9,8 +10,14 @@ async () => {} (foo) => {} (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,ccccccccccccccccccccccccccccc) => {} ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- () => {}; async () => {}; (foo) => {}; diff --git a/crates/rome_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap b/crates/rome_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap index b7fc2b56ae2..61b76748f83 100644 --- a/crates/rome_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: arrow_nested.js --- @@ -33,8 +33,14 @@ runtimeAgent.getProperties( }, ); ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- Seq(typeDef.interface.groups).forEach( (group) => Seq(group.members).forEach( diff --git a/crates/rome_formatter/tests/specs/js/module/arrow/call.js.snap b/crates/rome_formatter/tests/specs/js/module/arrow/call.js.snap index dc215f47b56..db2be1354bd 100644 --- a/crates/rome_formatter/tests/specs/js/module/arrow/call.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/arrow/call.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: call.js --- @@ -50,8 +50,14 @@ const composition = (ViewComponent, ContainerComponent) => romise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail"); ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- const testResults = results.testResults.map( (testResult) => formatResult(testResult, formatter, reporter), ); diff --git a/crates/rome_formatter/tests/specs/js/module/arrow/currying.js.snap b/crates/rome_formatter/tests/specs/js/module/arrow/currying.js.snap index de05cbddcdb..d289026df34 100644 --- a/crates/rome_formatter/tests/specs/js/module/arrow/currying.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/arrow/currying.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: currying.js --- @@ -23,8 +23,14 @@ const middleware = options => (req, res, next) => { // ... }; ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- const fn = (b) => (c) => (d) => { return 3; }; diff --git a/crates/rome_formatter/tests/specs/js/module/arrow/params.js.snap b/crates/rome_formatter/tests/specs/js/module/arrow/params.js.snap index 1d53703063c..7b600540d2e 100644 --- a/crates/rome_formatter/tests/specs/js/module/arrow/params.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/arrow/params.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: params.js --- @@ -327,8 +327,14 @@ foo( ) => {} ); ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- fooooooooooooooooooooooooooooooooooooooooooooooooooo( (action) => (next) => dispatch(action), ); diff --git a/crates/rome_formatter/tests/specs/js/module/assignment/assignment.js.snap b/crates/rome_formatter/tests/specs/js/module/assignment/assignment.js.snap index adca3f57e8f..4350ffa9a09 100644 --- a/crates/rome_formatter/tests/specs/js/module/assignment/assignment.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/assignment/assignment.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: assignment.js --- @@ -28,8 +29,14 @@ a[ b ] = c[ d ] ;({a,b=c,d:e,f:g=h,...j} = x) ;({aaaaaaaaaa,bbbbbbbbbb=cccccccccc,dddddddddd:eeeeeeeeee,ffffffffff:gggggggggg=hhhhhhhhhh,...jjjjjjjjjj} = x) ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- a = b; a += b; a -= b; diff --git a/crates/rome_formatter/tests/specs/js/module/binding/array_binding.js.snap b/crates/rome_formatter/tests/specs/js/module/binding/array_binding.js.snap index b7c7e8ea7c2..6fd2b78c882 100644 --- a/crates/rome_formatter/tests/specs/js/module/binding/array_binding.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/binding/array_binding.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: array_binding.js --- @@ -8,8 +9,14 @@ expression: array_binding.js let [a="b"]=c let [aaaaaaaaaaaaaaaaaaaa=bbbbbbbbbbbbbbbbbbbb,cccccccccccccccccccc=dddddddddddddddddddd]=e ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- [a = "b"] = c; let [a = "b"] = c; let [ diff --git a/crates/rome_formatter/tests/specs/js/module/binding/identifier_binding.js.snap b/crates/rome_formatter/tests/specs/js/module/binding/identifier_binding.js.snap index 5886fd1b6ff..d4335edc1b2 100644 --- a/crates/rome_formatter/tests/specs/js/module/binding/identifier_binding.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/binding/identifier_binding.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: identifier_binding.js --- @@ -9,8 +9,14 @@ let x = y let abcde = "very long value that will cause a line break", fghij = "this should end up on the next line" ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- let x = y; let abcde = "very long value that will cause a line break", diff --git a/crates/rome_formatter/tests/specs/js/module/binding/object_binding.js.snap b/crates/rome_formatter/tests/specs/js/module/binding/object_binding.js.snap index 08b17725150..e1f4ed85966 100644 --- a/crates/rome_formatter/tests/specs/js/module/binding/object_binding.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/binding/object_binding.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: object_binding.js --- @@ -10,8 +10,14 @@ let {d,b:c}=d let {x,y=c,z:pp=f,...g}=h let {aaaaaaaaaaaaaaaaaaaa,bbbbbbbbbbbbbbbbbbbb=cccccccccccccccccccc,dddddddddddddddddddd:eeeeeeeeeeeeeeeeeeee=ffffffffffffffffffff,...gggggggggggggggggggg}=h ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- let { a } = b; let { d, b: c } = d; let { x, y = c, z: pp = f, ...g } = h; diff --git a/crates/rome_formatter/tests/specs/js/module/class/class.js.snap b/crates/rome_formatter/tests/specs/js/module/class/class.js.snap index 11f7f8126d7..8c8ecd4f213 100644 --- a/crates/rome_formatter/tests/specs/js/module/class/class.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/class/class.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: class.js --- @@ -63,8 +63,14 @@ x = class foo extends Boar { x = class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa extends bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb { } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- class Foo extends Boar { static { // some comment diff --git a/crates/rome_formatter/tests/specs/js/module/class/class_comments.js.snap b/crates/rome_formatter/tests/specs/js/module/class/class_comments.js.snap index ada800cc59f..50b2a02e662 100644 --- a/crates/rome_formatter/tests/specs/js/module/class/class_comments.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/class/class_comments.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: class_comments.js --- @@ -12,8 +12,14 @@ class A extends B { // leading comment // trailing comment } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- class A extends B { // leading comment constructor() { diff --git a/crates/rome_formatter/tests/specs/js/module/class/private_method.js.snap b/crates/rome_formatter/tests/specs/js/module/class/private_method.js.snap index 4166fba75ef..5bb45a05ceb 100644 --- a/crates/rome_formatter/tests/specs/js/module/class/private_method.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/class/private_method.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: private_method.js --- @@ -22,8 +22,14 @@ class Foo { } } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- class Foo { a = 1; diff --git a/crates/rome_formatter/tests/specs/js/module/comments.js.snap b/crates/rome_formatter/tests/specs/js/module/comments.js.snap index 482092a9492..8c6f8d6a164 100644 --- a/crates/rome_formatter/tests/specs/js/module/comments.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/comments.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: comments.js --- @@ -52,8 +52,14 @@ statement(); /* block comment */ statement(); statement(); // inline ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- // import { // func, // trailing comma removal // } from 'module'; diff --git a/crates/rome_formatter/tests/specs/js/module/export/class_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/class_clause.js.snap index 194ecdb9b6e..b317a1609b5 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/class_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/class_clause.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: class_clause.js --- @@ -15,8 +15,14 @@ export class A { // small comment export default class B {} ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- // another comment export class A { // small comment diff --git a/crates/rome_formatter/tests/specs/js/module/export/expression_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/expression_clause.js.snap index 062cd1ed057..1c9c9b6ccf2 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/expression_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/expression_clause.js.snap @@ -1,12 +1,18 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: expression_clause.js --- # Input export default (1 - 43); ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- export default (1 - 43); diff --git a/crates/rome_formatter/tests/specs/js/module/export/from_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/from_clause.js.snap index 2ccaa1e4d83..47225385889 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/from_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/from_clause.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: from_clause.js --- @@ -10,8 +10,14 @@ export * from "hey" export * as something_bad_will_happen from "something_bad_might_not_happen" export * as something_bad_will_happen from "something_bad_might_not_happen" assert { "type": "json", "type2": "json3"} ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- export * from "hey"; export * as something_bad_will_happen from "something_bad_might_not_happen"; diff --git a/crates/rome_formatter/tests/specs/js/module/export/function_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/function_clause.js.snap index 340aa341c44..3cc0ad6dfdc 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/function_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/function_clause.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: function_clause.js --- @@ -14,8 +14,14 @@ export function f() { export default function ff() { } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- export function f() {} export default function ff() {} diff --git a/crates/rome_formatter/tests/specs/js/module/export/named_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/named_clause.js.snap index 9d060c7922c..09f1c64bf77 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/named_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/named_clause.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: named_clause.js --- @@ -12,8 +12,14 @@ export { buzz as bar, } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- export { // the boo api boo, diff --git a/crates/rome_formatter/tests/specs/js/module/export/named_from_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/named_from_clause.js.snap index ab9f3a13feb..d088526d3ee 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/named_from_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/named_from_clause.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: named_from_clause.js --- @@ -14,8 +14,14 @@ export { lorem_lorem_lorem_lorem_lorem_lorem_lorem_lorem_lorem, lorem_lorem_lorem_lorem_lorem_ as ipsum_ipsum_ipsum_ipsum_ipsum_ipsum_ } from "fancy" assert { type: "json", "type2": "json", type23: "json", "type24": "json"} ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- export { a, as c b } from "fancy" assert { type: "json" }; export { diff --git a/crates/rome_formatter/tests/specs/js/module/export/variable_declaration.js.snap b/crates/rome_formatter/tests/specs/js/module/export/variable_declaration.js.snap index 086ad66e56c..01f864f9ca3 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/variable_declaration.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/variable_declaration.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: variable_declaration.js --- @@ -8,8 +8,14 @@ expression: variable_declaration.js export let a, d, c; export const foofoofoofoofoofoofoo = "ahah", barbarbarbarbarbarbar = {}, loremloremloremloremlorem = [] ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- export let a, d, c; export const foofoofoofoofoofoofoo = "ahah", diff --git a/crates/rome_formatter/tests/specs/js/module/expression/binary_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/binary_expression.js.snap index 717384ecfa7..a31f7275d32 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/binary_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/binary_expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: binary_expression.js --- @@ -28,8 +29,14 @@ a ^ b a in b a instanceof b ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- a + b; a < b; a > b; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/conditional_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/conditional_expression.js.snap index ead47a1ccd9..b8f0941cdd3 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/conditional_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/conditional_expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: conditional_expression.js --- @@ -9,8 +10,14 @@ d ? (e + f) : (g + h) ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- a ? b : c; d ? (e + f) : (g + h); diff --git a/crates/rome_formatter/tests/specs/js/expression/import_meta_expression.js b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js similarity index 100% rename from crates/rome_formatter/tests/specs/js/expression/import_meta_expression.js rename to crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js diff --git a/crates/rome_formatter/tests/specs/js/expression/import_meta_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js.snap similarity index 58% rename from crates/rome_formatter/tests/specs/js/expression/import_meta_expression.js.snap rename to crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js.snap index e4845adc59b..18aa7f94dd8 100644 --- a/crates/rome_formatter/tests/specs/js/expression/import_meta_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: import_meta_expression.js --- @@ -9,10 +9,26 @@ console.log(import.meta); import.meta.field = obj.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariable; import.meta.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariable; ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- console.log(import.meta); import.meta.field = obj.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariable; import.meta.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariable; +## Output 2 +----- +Indent style: Spaces, size: 4 +Line width: 120 + +----- +console.log(import.meta); +import.meta.field = + obj.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariable; +import.meta.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariable; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json new file mode 100644 index 00000000000..7df0ee8ca0c --- /dev/null +++ b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json @@ -0,0 +1,8 @@ +{ + "cases": [ + { + "line_width": 120, + "indent_style": {"Space": 4} + } + ] +} \ No newline at end of file diff --git a/crates/rome_formatter/tests/specs/js/module/expression/literal_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/literal_expression.js.snap index d230e82fc0f..5dfb1d5b1cf 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/literal_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/literal_expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: literal_expression.js --- @@ -11,8 +12,14 @@ true false null ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- "a"; 1; 45n; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/logical_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/logical_expression.js.snap index b742008e9e6..ee1564633c2 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/logical_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/logical_expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: logical_expression.js --- @@ -8,8 +9,14 @@ x ?? y x || y x && y ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- x ?? y; x || y; x && y; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/new_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/new_expression.js.snap index b90055b0185..66384b140b4 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/new_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/new_expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: new_expression.js --- @@ -8,8 +9,14 @@ new a() new b(x) new c(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,cccccccccccccccccccccccccccccc) ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- new a(); new b(x); new c( diff --git a/crates/rome_formatter/tests/specs/js/module/expression/post_update_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/post_update_expression.js.snap index 013f0437636..3bd59f37722 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/post_update_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/post_update_expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: post_update_expression.js --- @@ -9,8 +10,14 @@ y-- x = y++ x = y-- ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- y++; y--; x = y++; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/pre_update_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/pre_update_expression.js.snap index 29f8295a177..2d012f1b4bb 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/pre_update_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/pre_update_expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: pre_update_expression.js --- @@ -9,8 +10,14 @@ expression: pre_update_expression.js x = ++y x = --y ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- ++y; --y; x = ++y; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/sequence_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/sequence_expression.js.snap index 99542a58f8c..0a741d88614 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/sequence_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/sequence_expression.js.snap @@ -1,12 +1,19 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: sequence_expression.js --- # Input a,b ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- a, b; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/static_member_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/static_member_expression.js.snap index 60f07b1d327..e8c08a03245 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/static_member_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/static_member_expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: static_member_expression.js --- @@ -11,8 +12,14 @@ a?.#b a?.b.#c a?.#b.c().d ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- a.b; a?.b; a.#b; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/this_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/this_expression.js.snap index 8bca66e56f3..b573029a635 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/this_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/this_expression.js.snap @@ -1,12 +1,19 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: this_expression.js --- # Input this ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- this; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/unary_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/unary_expression.js.snap index ab2ca0aa5f3..bf300576d67 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/unary_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/unary_expression.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: unary_expression.js --- @@ -20,8 +20,14 @@ x = -aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa x = ~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa x = !aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- delete a.a; void b; typeof c; diff --git a/crates/rome_formatter/tests/specs/js/module/function/function_args.js.snap b/crates/rome_formatter/tests/specs/js/module/function/function_args.js.snap index 2177cfcb4c8..969a0b67bc3 100644 --- a/crates/rome_formatter/tests/specs/js/module/function/function_args.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/function/function_args.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: function_args.js --- @@ -8,8 +8,14 @@ expression: function_args.js function foo(someotherlongvariableshould1, someotherlongvariableshould2, someotherlongvariableshould3, someotherlongvariableshould4, someotherlongvariableshould5, someotherlongvariableshould6 = foooooooooooo, ...someotherlongvariableshould7) { return "nothing"; } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- function foo( someotherlongvariableshould1, someotherlongvariableshould2, diff --git a/crates/rome_formatter/tests/specs/js/module/function/function_comments.js.snap b/crates/rome_formatter/tests/specs/js/module/function/function_comments.js.snap index ba1c6f2d5e1..b63f6f0c9d8 100644 --- a/crates/rome_formatter/tests/specs/js/module/function/function_comments.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/function/function_comments.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: function_comments.js --- @@ -22,8 +22,14 @@ function b() // leading comment function c( //some comment foo, bar, ) {} ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- function a() { // trailing comment let a = 2; diff --git a/crates/rome_formatter/tests/specs/js/module/ident.js.snap b/crates/rome_formatter/tests/specs/js/module/ident.js.snap index 2f518117178..f8366c0da00 100644 --- a/crates/rome_formatter/tests/specs/js/module/ident.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/ident.js.snap @@ -1,12 +1,19 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: ident.js --- # Input x ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- x; diff --git a/crates/rome_formatter/tests/specs/js/module/import/bare_import.js.snap b/crates/rome_formatter/tests/specs/js/module/import/bare_import.js.snap index 73a522cce5d..b7ae8754546 100644 --- a/crates/rome_formatter/tests/specs/js/module/import/bare_import.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/import/bare_import.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 63 +assertion_line: 157 expression: bare_import.js --- @@ -25,8 +25,14 @@ import "very_long_import_very_long_import_very" assert { "type4": /****/ "json", "typetypetypetypetypetypetypetypetypetypetype": /****/ "typetypetypetypetypetypetypetypetypetypetypetypetypetype", } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- import "very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_"; import "very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_very_long" assert { type: "json", diff --git a/crates/rome_formatter/tests/specs/js/module/import/default_import.js.snap b/crates/rome_formatter/tests/specs/js/module/import/default_import.js.snap index e77676e8e8e..097ca25ca1c 100644 --- a/crates/rome_formatter/tests/specs/js/module/import/default_import.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/import/default_import.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 63 +assertion_line: 157 expression: default_import.js --- @@ -17,8 +17,14 @@ import foo from "foo.json" assert { import foo2 from "foo.json" assert { "type": "json", type: "html", "type": "js" }; import a, * as b from "foo" ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- import hey from "hey"; import hey from "hey"; import "x" assert { type: "json" }; diff --git a/crates/rome_formatter/tests/specs/js/module/import/import_call.js.snap b/crates/rome_formatter/tests/specs/js/module/import/import_call.js.snap index 547d59cfda0..7f319546eba 100644 --- a/crates/rome_formatter/tests/specs/js/module/import/import_call.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/import/import_call.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: import_call.js --- @@ -8,8 +9,14 @@ import(x) import('x') import(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, {assert: {type:'json'}}) ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- import(x); import("x"); import( diff --git a/crates/rome_formatter/tests/specs/js/module/import/import_specifiers.js.snap b/crates/rome_formatter/tests/specs/js/module/import/import_specifiers.js.snap index 812046b0425..81f4d9e0bd1 100644 --- a/crates/rome_formatter/tests/specs/js/module/import/import_specifiers.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/import/import_specifiers.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: import_specifiers.js --- @@ -22,8 +22,14 @@ import {loooooooooooooooooooong3,loooooooooooooooooooong5,loooooooooooooooooooon import { f as x, default as w, "a-b-c" as y } from "b"; import loooooooooooooooooooong7, { loooooooooooooooooooong8, loooooooooooooooooooong9, loooooooooooooooooooong10} from "module" ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- import { hey } from "hey"; import { hey } from "hey"; import { test } from "foo.json" assert { for: "for" }; diff --git a/crates/rome_formatter/tests/specs/js/module/import/namespace_import.js.snap b/crates/rome_formatter/tests/specs/js/module/import/namespace_import.js.snap index 19ccf11e997..0259a3d32fa 100644 --- a/crates/rome_formatter/tests/specs/js/module/import/namespace_import.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/import/namespace_import.js.snap @@ -1,12 +1,18 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 63 +assertion_line: 157 expression: namespace_import.js --- # Input import * as all from "all" ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- import * as all from "all"; diff --git a/crates/rome_formatter/tests/specs/js/module/invalid/block_stmt_err.js.snap b/crates/rome_formatter/tests/specs/js/module/invalid/block_stmt_err.js.snap index 2b077eaeab9..8d1119d562d 100644 --- a/crates/rome_formatter/tests/specs/js/module/invalid/block_stmt_err.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/invalid/block_stmt_err.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: block_stmt_err.js --- @@ -16,8 +16,14 @@ expression: block_stmt_err.js let recovered = "no" ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- { let x = 10; let y = 100; diff --git a/crates/rome_formatter/tests/specs/js/module/invalid/if_stmt_err.js.snap b/crates/rome_formatter/tests/specs/js/module/invalid/if_stmt_err.js.snap index 28728db9d58..eef8b28a46a 100644 --- a/crates/rome_formatter/tests/specs/js/module/invalid/if_stmt_err.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/invalid/if_stmt_err.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: if_stmt_err.js --- @@ -22,8 +22,14 @@ if (false) { let x = 99; } else { ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- function test() { let x = 10; if test { diff --git a/crates/rome_formatter/tests/specs/js/module/newlines.js.snap b/crates/rome_formatter/tests/specs/js/module/newlines.js.snap index 32b0a3cbce4..db763748984 100644 --- a/crates/rome_formatter/tests/specs/js/module/newlines.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/newlines.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: newlines.js --- @@ -84,8 +84,14 @@ const object = { }; ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- "directive"; // comment "directive"; diff --git a/crates/rome_formatter/tests/specs/js/module/number/number.js.snap b/crates/rome_formatter/tests/specs/js/module/number/number.js.snap index ed6817aad4c..477578ca61b 100644 --- a/crates/rome_formatter/tests/specs/js/module/number/number.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/number/number.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: number.js --- @@ -7,8 +8,14 @@ expression: number.js 1.23e4 1000e3 // FIXME handle number with scientific notation #1294 ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- 1.23e4; 1000e3; // FIXME handle number with scientific notation #1294 diff --git a/crates/rome_formatter/tests/specs/js/module/object/computed_member.js.snap b/crates/rome_formatter/tests/specs/js/module/object/computed_member.js.snap index 97d1a3b96b7..0958007a285 100644 --- a/crates/rome_formatter/tests/specs/js/module/object/computed_member.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/object/computed_member.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: computed_member.js --- @@ -14,8 +14,14 @@ foo.bar["bar"]["lorem_ispsum"].foo["lorem-ipsum"] = true; a[ b ] c?.[ d ] ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- const foo = {}; foo["bar"] = true; diff --git a/crates/rome_formatter/tests/specs/js/module/object/getter_setter.js.snap b/crates/rome_formatter/tests/specs/js/module/object/getter_setter.js.snap index 6870fa07fcd..2c89476a405 100644 --- a/crates/rome_formatter/tests/specs/js/module/object/getter_setter.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/object/getter_setter.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: getter_setter.js --- @@ -11,8 +12,14 @@ let b = { set foo(a) {} } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- let a = { get foo() {} }; let b = { set foo(a) {} }; diff --git a/crates/rome_formatter/tests/specs/js/module/object/object.js.snap b/crates/rome_formatter/tests/specs/js/module/object/object.js.snap index 68dcbd0a7c7..3fe2ffae1aa 100644 --- a/crates/rome_formatter/tests/specs/js/module/object/object.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/object/object.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: object.js --- @@ -27,8 +27,14 @@ let a = { ...spread, } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- let a = { ...spread, diff --git a/crates/rome_formatter/tests/specs/js/module/object/object_comments.js.snap b/crates/rome_formatter/tests/specs/js/module/object/object_comments.js.snap index 5b2980d809b..1c9c89dd6e4 100644 --- a/crates/rome_formatter/tests/specs/js/module/object/object_comments.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/object/object_comments.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: object_comments.js --- @@ -9,8 +9,14 @@ let a = { // leading comment "type": "bar" // trailing comment } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- let a = { // leading comment "type": "bar", diff --git a/crates/rome_formatter/tests/specs/js/module/object/property_key.js.snap b/crates/rome_formatter/tests/specs/js/module/object/property_key.js.snap index 1f56eec43f7..b42ab3bf19d 100644 --- a/crates/rome_formatter/tests/specs/js/module/object/property_key.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/object/property_key.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: property_key.js --- @@ -13,8 +14,14 @@ const foo = { }, }; ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- const foo = { "foo-bar": true, "bar": { "lorem_ispsum": { "lorem-ipsum": true } }, diff --git a/crates/rome_formatter/tests/specs/js/module/parentheses/parentheses.js.snap b/crates/rome_formatter/tests/specs/js/module/parentheses/parentheses.js.snap index 774dc1c1dfd..b8e6d5b4561 100644 --- a/crates/rome_formatter/tests/specs/js/module/parentheses/parentheses.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/parentheses/parentheses.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: parentheses.js --- @@ -16,8 +17,14 @@ const foo = class extends (Bar ?? Baz) {} ;(1) ;(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- (foo++)?.(); async () => { (await foo)?.(); diff --git a/crates/rome_formatter/tests/specs/js/module/script.js.snap b/crates/rome_formatter/tests/specs/js/module/script.js.snap index 4e385aab8b9..26b16c7a7e5 100644 --- a/crates/rome_formatter/tests/specs/js/module/script.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/script.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 68 +assertion_line: 157 expression: script.js --- @@ -10,8 +10,14 @@ expression: script.js 'use asm' var express = require("express") ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- #!/usr/bin/env node "use strict"; "use asm"; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/do_while.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/do_while.js.snap index 68b0e79dc14..c6a54dad26a 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/do_while.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/do_while.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: do_while.js --- @@ -17,8 +17,14 @@ do { // trailing } while (something) ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- do { var foo = 4; } while (something); diff --git a/crates/rome_formatter/tests/specs/js/module/statement/for_in.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/for_in.js.snap index f35217cc99a..6e3eae05855 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/for_in.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/for_in.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: for_in.js --- @@ -12,8 +12,14 @@ for (aVeryLongVariableNameToEnforceLineBreaksaVeryLongVariableNameToEnforceLineB for (a in b) { // trailing } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- for (a in b) {} for ( diff --git a/crates/rome_formatter/tests/specs/js/module/statement/for_loop.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/for_loop.js.snap index 3bb778f0d39..982201df9be 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/for_loop.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/for_loop.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: for_loop.js --- @@ -22,8 +23,14 @@ for(a;b;c) { for(let aVeryLongVariableNameToEnforceLineBreaks = 0; aVeryLongVariableNameToEnforceLineBreaks; aVeryLongVariableNameToEnforceLineBreaks) { } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- for (;;) { let x = 10; } diff --git a/crates/rome_formatter/tests/specs/js/module/statement/if_else.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/if_else.js.snap index fd4312bf96e..0e66c931dd2 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/if_else.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/if_else.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: if_else.js --- @@ -64,8 +64,14 @@ if (true) { } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- if (Math.random() > 0.5) { console.log(1); } else if (Math.random() > 0.5) { diff --git a/crates/rome_formatter/tests/specs/js/module/statement/statement.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/statement.js.snap index 5fa7e0aba79..8d6048d61b4 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/statement.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/statement.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: statement.js --- @@ -7,7 +8,13 @@ expression: statement.js ; debugger ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- debugger; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/switch.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/switch.js.snap index 4ef6ec18fea..e39f2fc53e5 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/switch.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/switch.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: switch.js --- @@ -16,8 +16,14 @@ switch (key) { } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- switch (key) { case value: break; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/throw.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/throw.js.snap index f596b6e49a8..67d1a92d599 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/throw.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/throw.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: throw.js --- @@ -9,8 +9,14 @@ throw "Something"; throw false ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- throw "Something"; throw false; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/try_catch_finally.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/try_catch_finally.js.snap index e45658a8397..82ed06b9483 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/try_catch_finally.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/try_catch_finally.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: try_catch_finally.js --- @@ -32,8 +32,14 @@ try { var foo = 4 } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- try { var foo = 4; } catch { diff --git a/crates/rome_formatter/tests/specs/js/module/statement/while_loop.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/while_loop.js.snap index e85366a20ca..a81af0bcb06 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/while_loop.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/while_loop.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: while_loop.js --- @@ -32,8 +32,14 @@ tour: while (true) { break tour; } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- while (true) { var foo = 4; } diff --git a/crates/rome_formatter/tests/specs/js/module/template/template.js.snap b/crates/rome_formatter/tests/specs/js/module/template/template.js.snap index 00dff2abff6..4c01a393373 100644 --- a/crates/rome_formatter/tests/specs/js/module/template/template.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/template/template.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 157 expression: template.js --- @@ -23,8 +23,14 @@ output abcd ${ () => { var hey; const looooooooooong_expression = "loooooooooong_expression"; return hey; }} output `; ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- `something`; tag`something``something ${" hello"}`; diff --git a/crates/rome_formatter/tests/specs/js/module/with.js.snap b/crates/rome_formatter/tests/specs/js/module/with.js.snap index 68e1fa37488..2ce885e4af3 100644 --- a/crates/rome_formatter/tests/specs/js/module/with.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/with.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 68 +assertion_line: 157 expression: with.js --- @@ -11,8 +11,14 @@ with ( b) 5 } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- with ( b) { diff --git a/crates/rome_formatter/tests/specs/js/script/script.js.snap b/crates/rome_formatter/tests/specs/js/script/script.js.snap index d190d18e3cc..26b16c7a7e5 100644 --- a/crates/rome_formatter/tests/specs/js/script/script.js.snap +++ b/crates/rome_formatter/tests/specs/js/script/script.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs +assertion_line: 157 expression: script.js --- @@ -9,8 +10,14 @@ expression: script.js 'use asm' var express = require("express") ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- #!/usr/bin/env node "use strict"; "use asm"; diff --git a/crates/rome_formatter/tests/specs/js/script/with.js.snap b/crates/rome_formatter/tests/specs/js/script/with.js.snap index 4862aa63b4e..19a450dd17b 100644 --- a/crates/rome_formatter/tests/specs/js/script/with.js.snap +++ b/crates/rome_formatter/tests/specs/js/script/with.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 43 +assertion_line: 157 expression: with.js --- @@ -11,8 +11,14 @@ with ( b) 5 } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 + +----- with (b) { 5; } diff --git a/crates/rslint_parser/src/tests.rs b/crates/rslint_parser/src/tests.rs index 2d4d92a8992..00f8564c17b 100644 --- a/crates/rslint_parser/src/tests.rs +++ b/crates/rslint_parser/src/tests.rs @@ -99,7 +99,7 @@ fn try_parse_with_printed_ast(path: &str, text: &str) -> (Parse, Stri } #[cfg(test)] -fn run_and_expect_no_errors(path: &str, _: &str, _: &str) { +fn run_and_expect_no_errors(path: &str, _: &str, _: &str, _: &str) { let path = PathBuf::from(path); let text = std::fs::read_to_string(&path).unwrap(); @@ -112,7 +112,7 @@ fn run_and_expect_no_errors(path: &str, _: &str, _: &str) { } #[cfg(test)] -fn run_and_expect_errors(path: &str, _: &str, _: &str) { +fn run_and_expect_errors(path: &str, _: &str, _: &str, _: &str) { let path = PathBuf::from(path); let text = std::fs::read_to_string(&path).unwrap(); diff --git a/crates/tests_macros/src/lib.rs b/crates/tests_macros/src/lib.rs index f242fc9b2c6..83c59c1496f 100644 --- a/crates/tests_macros/src/lib.rs +++ b/crates/tests_macros/src/lib.rs @@ -16,6 +16,7 @@ struct Variables { test_name: String, test_full_path: String, test_expected_fullpath: String, + test_directory: String, } struct AllFiles(GlobWalker); @@ -70,9 +71,12 @@ impl Arguments { let file_stem = path.file_stem()?; let file_stem = file_stem.to_str()?; let test_name = file_stem.to_snake(); + let mut ancestors = path.ancestors(); + // the first one will yield the path to the current file + ancestors.next(); + let test_directory = ancestors.next().unwrap().display().to_string(); let test_full_path = path.display().to_string(); - let extension = match path.extension() { Some(ext) => format!(".{}", ext.to_str().unwrap_or("")), None => "".into(), @@ -87,6 +91,7 @@ impl Arguments { test_name, test_full_path, test_expected_fullpath, + test_directory, }) } @@ -99,6 +104,7 @@ impl Arguments { test_name, test_full_path, test_expected_fullpath, + test_directory, } = Arguments::get_variables(&file).ok_or("Cannot generate variables for this file")?; let test_name = test_name.replace("-", "_"); @@ -113,7 +119,8 @@ impl Arguments { let test_file = #test_full_path; let test_expected_file = #test_expected_fullpath; let file_type = #file_type; - #f(test_file, test_expected_file, file_type); + let test_directory = #test_directory; + #f(test_file, test_expected_file, test_directory, file_type); } }); } From 9068e85b39ace0b3787ae4edfd655de29bb5c6a7 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Thu, 3 Feb 2022 16:32:35 +0000 Subject: [PATCH 02/10] removed new line --- crates/rome_formatter/tests/spec_test.rs | 2 +- .../tests/specs/js/module/array/array_nested.js.snap | 1 - .../tests/specs/js/module/array/binding_pattern.js.snap | 1 - .../tests/specs/js/module/array/empty_lines.js.snap | 1 - .../rome_formatter/tests/specs/js/module/array/spaces.js.snap | 1 - .../rome_formatter/tests/specs/js/module/array/spread.js.snap | 1 - .../tests/specs/js/module/arrow/arrow_function.js.snap | 1 - .../tests/specs/js/module/arrow/arrow_nested.js.snap | 1 - crates/rome_formatter/tests/specs/js/module/arrow/call.js.snap | 1 - .../rome_formatter/tests/specs/js/module/arrow/currying.js.snap | 1 - .../rome_formatter/tests/specs/js/module/arrow/params.js.snap | 1 - .../tests/specs/js/module/assignment/assignment.js.snap | 1 - .../tests/specs/js/module/binding/array_binding.js.snap | 1 - .../tests/specs/js/module/binding/identifier_binding.js.snap | 1 - .../tests/specs/js/module/binding/object_binding.js.snap | 1 - crates/rome_formatter/tests/specs/js/module/class/class.js.snap | 1 - .../tests/specs/js/module/class/class_comments.js.snap | 1 - .../tests/specs/js/module/class/private_method.js.snap | 1 - crates/rome_formatter/tests/specs/js/module/comments.js.snap | 1 - .../tests/specs/js/module/export/class_clause.js.snap | 1 - .../tests/specs/js/module/export/expression_clause.js.snap | 1 - .../tests/specs/js/module/export/from_clause.js.snap | 1 - .../tests/specs/js/module/export/function_clause.js.snap | 1 - .../tests/specs/js/module/export/named_clause.js.snap | 1 - .../tests/specs/js/module/export/named_from_clause.js.snap | 1 - .../tests/specs/js/module/export/variable_declaration.js.snap | 1 - .../tests/specs/js/module/expression/binary_expression.js.snap | 1 - .../specs/js/module/expression/conditional_expression.js.snap | 1 - .../import_meta_expression/import_meta_expression.js.snap | 2 -- .../tests/specs/js/module/expression/literal_expression.js.snap | 1 - .../tests/specs/js/module/expression/logical_expression.js.snap | 1 - .../tests/specs/js/module/expression/new_expression.js.snap | 1 - .../specs/js/module/expression/post_update_expression.js.snap | 1 - .../specs/js/module/expression/pre_update_expression.js.snap | 1 - .../specs/js/module/expression/sequence_expression.js.snap | 1 - .../specs/js/module/expression/static_member_expression.js.snap | 1 - .../tests/specs/js/module/expression/this_expression.js.snap | 1 - .../tests/specs/js/module/expression/unary_expression.js.snap | 1 - .../tests/specs/js/module/function/function_args.js.snap | 1 - .../tests/specs/js/module/function/function_comments.js.snap | 1 - crates/rome_formatter/tests/specs/js/module/ident.js.snap | 1 - .../tests/specs/js/module/import/bare_import.js.snap | 1 - .../tests/specs/js/module/import/default_import.js.snap | 1 - .../tests/specs/js/module/import/import_call.js.snap | 1 - .../tests/specs/js/module/import/import_specifiers.js.snap | 1 - .../tests/specs/js/module/import/namespace_import.js.snap | 1 - .../tests/specs/js/module/invalid/block_stmt_err.js.snap | 1 - .../tests/specs/js/module/invalid/if_stmt_err.js.snap | 1 - crates/rome_formatter/tests/specs/js/module/newlines.js.snap | 1 - .../rome_formatter/tests/specs/js/module/number/number.js.snap | 1 - .../tests/specs/js/module/object/computed_member.js.snap | 1 - .../tests/specs/js/module/object/getter_setter.js.snap | 1 - .../rome_formatter/tests/specs/js/module/object/object.js.snap | 1 - .../tests/specs/js/module/object/object_comments.js.snap | 1 - .../tests/specs/js/module/object/property_key.js.snap | 1 - .../tests/specs/js/module/parentheses/parentheses.js.snap | 1 - crates/rome_formatter/tests/specs/js/module/script.js.snap | 1 - .../tests/specs/js/module/statement/do_while.js.snap | 1 - .../tests/specs/js/module/statement/for_in.js.snap | 1 - .../tests/specs/js/module/statement/for_loop.js.snap | 1 - .../tests/specs/js/module/statement/if_else.js.snap | 1 - .../tests/specs/js/module/statement/statement.js.snap | 1 - .../tests/specs/js/module/statement/switch.js.snap | 1 - .../tests/specs/js/module/statement/throw.js.snap | 1 - .../tests/specs/js/module/statement/try_catch_finally.js.snap | 1 - .../tests/specs/js/module/statement/while_loop.js.snap | 1 - .../tests/specs/js/module/template/template.js.snap | 1 - crates/rome_formatter/tests/specs/js/module/with.js.snap | 1 - crates/rome_formatter/tests/specs/js/script/script.js.snap | 1 - crates/rome_formatter/tests/specs/js/script/with.js.snap | 1 - 70 files changed, 1 insertion(+), 71 deletions(-) diff --git a/crates/rome_formatter/tests/spec_test.rs b/crates/rome_formatter/tests/spec_test.rs index 19d28a33459..255bfa15519 100644 --- a/crates/rome_formatter/tests/spec_test.rs +++ b/crates/rome_formatter/tests/spec_test.rs @@ -77,7 +77,7 @@ impl SnapshotContent { let formal_index = index + 1; output.push_str(format!("## Output {formal_index}\n").as_str()); output.push_str("-----\n"); - output.push_str(format!("{}\n", options).as_str()); + output.push_str(format!("{}", options).as_str()); output.push_str("-----\n"); output.push_str(content.as_str()); } diff --git a/crates/rome_formatter/tests/specs/js/module/array/array_nested.js.snap b/crates/rome_formatter/tests/specs/js/module/array/array_nested.js.snap index ccf776f0428..bc86675806c 100644 --- a/crates/rome_formatter/tests/specs/js/module/array/array_nested.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/array/array_nested.js.snap @@ -53,7 +53,6 @@ let o1 = [{ a, b }, { a, b, c }]; ----- Indent style: Tab Line width: 80 - ----- let a = [[]]; let b = [[], []]; diff --git a/crates/rome_formatter/tests/specs/js/module/array/binding_pattern.js.snap b/crates/rome_formatter/tests/specs/js/module/array/binding_pattern.js.snap index e20c1098fc3..0b4c5e99f27 100644 --- a/crates/rome_formatter/tests/specs/js/module/array/binding_pattern.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/array/binding_pattern.js.snap @@ -15,7 +15,6 @@ let [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,...cccccccccc ----- Indent style: Tab Line width: 80 - ----- let [a, b] = c; let [d, ...e] = c; diff --git a/crates/rome_formatter/tests/specs/js/module/array/empty_lines.js.snap b/crates/rome_formatter/tests/specs/js/module/array/empty_lines.js.snap index cfda4e909fa..6dbeeaf5a27 100644 --- a/crates/rome_formatter/tests/specs/js/module/array/empty_lines.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/array/empty_lines.js.snap @@ -24,7 +24,6 @@ let a = [ ----- Indent style: Tab Line width: 80 - ----- let a = [ 1, diff --git a/crates/rome_formatter/tests/specs/js/module/array/spaces.js.snap b/crates/rome_formatter/tests/specs/js/module/array/spaces.js.snap index c7ed988880a..6a0664f9cd5 100644 --- a/crates/rome_formatter/tests/specs/js/module/array/spaces.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/array/spaces.js.snap @@ -17,7 +17,6 @@ let e = [2,2,1,3]; ----- Indent style: Tab Line width: 80 - ----- let a = [,]; let b = [, ,]; diff --git a/crates/rome_formatter/tests/specs/js/module/array/spread.js.snap b/crates/rome_formatter/tests/specs/js/module/array/spread.js.snap index 6580dded634..0fc0e7524ae 100644 --- a/crates/rome_formatter/tests/specs/js/module/array/spread.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/array/spread.js.snap @@ -17,7 +17,6 @@ let a = [...baaaaaaaaaaaaaaaaaaaaaaaaaaaaa,...bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,... ----- Indent style: Tab Line width: 80 - ----- let a = [...a, ...b]; let b = [...a, ...b]; diff --git a/crates/rome_formatter/tests/specs/js/module/arrow/arrow_function.js.snap b/crates/rome_formatter/tests/specs/js/module/arrow/arrow_function.js.snap index 6e35b9b561d..c3786142b34 100644 --- a/crates/rome_formatter/tests/specs/js/module/arrow/arrow_function.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/arrow/arrow_function.js.snap @@ -16,7 +16,6 @@ async () => {} ----- Indent style: Tab Line width: 80 - ----- () => {}; async () => {}; diff --git a/crates/rome_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap b/crates/rome_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap index 61b76748f83..1c1ebe2e862 100644 --- a/crates/rome_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap @@ -39,7 +39,6 @@ runtimeAgent.getProperties( ----- Indent style: Tab Line width: 80 - ----- Seq(typeDef.interface.groups).forEach( (group) => diff --git a/crates/rome_formatter/tests/specs/js/module/arrow/call.js.snap b/crates/rome_formatter/tests/specs/js/module/arrow/call.js.snap index db2be1354bd..ab4fdced993 100644 --- a/crates/rome_formatter/tests/specs/js/module/arrow/call.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/arrow/call.js.snap @@ -56,7 +56,6 @@ romise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVa ----- Indent style: Tab Line width: 80 - ----- const testResults = results.testResults.map( (testResult) => formatResult(testResult, formatter, reporter), diff --git a/crates/rome_formatter/tests/specs/js/module/arrow/currying.js.snap b/crates/rome_formatter/tests/specs/js/module/arrow/currying.js.snap index d289026df34..bda1e8b10d6 100644 --- a/crates/rome_formatter/tests/specs/js/module/arrow/currying.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/arrow/currying.js.snap @@ -29,7 +29,6 @@ const middleware = options => (req, res, next) => { ----- Indent style: Tab Line width: 80 - ----- const fn = (b) => (c) => (d) => { return 3; diff --git a/crates/rome_formatter/tests/specs/js/module/arrow/params.js.snap b/crates/rome_formatter/tests/specs/js/module/arrow/params.js.snap index 7b600540d2e..64048017d78 100644 --- a/crates/rome_formatter/tests/specs/js/module/arrow/params.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/arrow/params.js.snap @@ -333,7 +333,6 @@ foo( ----- Indent style: Tab Line width: 80 - ----- fooooooooooooooooooooooooooooooooooooooooooooooooooo( (action) => (next) => dispatch(action), diff --git a/crates/rome_formatter/tests/specs/js/module/assignment/assignment.js.snap b/crates/rome_formatter/tests/specs/js/module/assignment/assignment.js.snap index 4350ffa9a09..794fc4fd651 100644 --- a/crates/rome_formatter/tests/specs/js/module/assignment/assignment.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/assignment/assignment.js.snap @@ -35,7 +35,6 @@ a[ b ] = c[ d ] ----- Indent style: Tab Line width: 80 - ----- a = b; a += b; diff --git a/crates/rome_formatter/tests/specs/js/module/binding/array_binding.js.snap b/crates/rome_formatter/tests/specs/js/module/binding/array_binding.js.snap index 6fd2b78c882..c73a7cc3757 100644 --- a/crates/rome_formatter/tests/specs/js/module/binding/array_binding.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/binding/array_binding.js.snap @@ -15,7 +15,6 @@ let [aaaaaaaaaaaaaaaaaaaa=bbbbbbbbbbbbbbbbbbbb,cccccccccccccccccccc=dddddddddddd ----- Indent style: Tab Line width: 80 - ----- [a = "b"] = c; let [a = "b"] = c; diff --git a/crates/rome_formatter/tests/specs/js/module/binding/identifier_binding.js.snap b/crates/rome_formatter/tests/specs/js/module/binding/identifier_binding.js.snap index d4335edc1b2..1cf783e98f1 100644 --- a/crates/rome_formatter/tests/specs/js/module/binding/identifier_binding.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/binding/identifier_binding.js.snap @@ -15,7 +15,6 @@ let abcde = "very long value that will cause a line break", fghij = "this should ----- Indent style: Tab Line width: 80 - ----- let x = y; diff --git a/crates/rome_formatter/tests/specs/js/module/binding/object_binding.js.snap b/crates/rome_formatter/tests/specs/js/module/binding/object_binding.js.snap index e1f4ed85966..30348858de0 100644 --- a/crates/rome_formatter/tests/specs/js/module/binding/object_binding.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/binding/object_binding.js.snap @@ -16,7 +16,6 @@ let {aaaaaaaaaaaaaaaaaaaa,bbbbbbbbbbbbbbbbbbbb=cccccccccccccccccccc,dddddddddddd ----- Indent style: Tab Line width: 80 - ----- let { a } = b; let { d, b: c } = d; diff --git a/crates/rome_formatter/tests/specs/js/module/class/class.js.snap b/crates/rome_formatter/tests/specs/js/module/class/class.js.snap index 8c8ecd4f213..6b0b23f5cc2 100644 --- a/crates/rome_formatter/tests/specs/js/module/class/class.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/class/class.js.snap @@ -69,7 +69,6 @@ x = class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa extends bbbbbbb ----- Indent style: Tab Line width: 80 - ----- class Foo extends Boar { static { diff --git a/crates/rome_formatter/tests/specs/js/module/class/class_comments.js.snap b/crates/rome_formatter/tests/specs/js/module/class/class_comments.js.snap index 50b2a02e662..bb7e39b1490 100644 --- a/crates/rome_formatter/tests/specs/js/module/class/class_comments.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/class/class_comments.js.snap @@ -18,7 +18,6 @@ class A extends B { // leading comment ----- Indent style: Tab Line width: 80 - ----- class A extends B { // leading comment diff --git a/crates/rome_formatter/tests/specs/js/module/class/private_method.js.snap b/crates/rome_formatter/tests/specs/js/module/class/private_method.js.snap index 5bb45a05ceb..45c2cdb5cd8 100644 --- a/crates/rome_formatter/tests/specs/js/module/class/private_method.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/class/private_method.js.snap @@ -28,7 +28,6 @@ class Foo { ----- Indent style: Tab Line width: 80 - ----- class Foo { a = 1; diff --git a/crates/rome_formatter/tests/specs/js/module/comments.js.snap b/crates/rome_formatter/tests/specs/js/module/comments.js.snap index 8c6f8d6a164..1e57a75fb01 100644 --- a/crates/rome_formatter/tests/specs/js/module/comments.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/comments.js.snap @@ -58,7 +58,6 @@ statement(); // inline ----- Indent style: Tab Line width: 80 - ----- // import { // func, // trailing comma removal diff --git a/crates/rome_formatter/tests/specs/js/module/export/class_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/class_clause.js.snap index b317a1609b5..f5790bf5e5f 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/class_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/class_clause.js.snap @@ -21,7 +21,6 @@ B {} ----- Indent style: Tab Line width: 80 - ----- // another comment export class A { diff --git a/crates/rome_formatter/tests/specs/js/module/export/expression_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/expression_clause.js.snap index 1c9c9b6ccf2..0b91981dad7 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/expression_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/expression_clause.js.snap @@ -12,7 +12,6 @@ export default (1 - 43); ----- Indent style: Tab Line width: 80 - ----- export default (1 - 43); diff --git a/crates/rome_formatter/tests/specs/js/module/export/from_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/from_clause.js.snap index 47225385889..ce141e2aeba 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/from_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/from_clause.js.snap @@ -16,7 +16,6 @@ export * as something_bad_will_happen from "something_bad_might_not_happen" asse ----- Indent style: Tab Line width: 80 - ----- export * from "hey"; diff --git a/crates/rome_formatter/tests/specs/js/module/export/function_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/function_clause.js.snap index 3cc0ad6dfdc..506465d3254 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/function_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/function_clause.js.snap @@ -20,7 +20,6 @@ export default function ff() { ----- Indent style: Tab Line width: 80 - ----- export function f() {} diff --git a/crates/rome_formatter/tests/specs/js/module/export/named_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/named_clause.js.snap index 09f1c64bf77..e441f5c8d97 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/named_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/named_clause.js.snap @@ -18,7 +18,6 @@ export { ----- Indent style: Tab Line width: 80 - ----- export { // the boo api diff --git a/crates/rome_formatter/tests/specs/js/module/export/named_from_clause.js.snap b/crates/rome_formatter/tests/specs/js/module/export/named_from_clause.js.snap index d088526d3ee..70f49ce3260 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/named_from_clause.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/named_from_clause.js.snap @@ -20,7 +20,6 @@ export { ----- Indent style: Tab Line width: 80 - ----- export { a, as c b } from "fancy" assert { type: "json" }; diff --git a/crates/rome_formatter/tests/specs/js/module/export/variable_declaration.js.snap b/crates/rome_formatter/tests/specs/js/module/export/variable_declaration.js.snap index 01f864f9ca3..394f3b58697 100644 --- a/crates/rome_formatter/tests/specs/js/module/export/variable_declaration.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/export/variable_declaration.js.snap @@ -14,7 +14,6 @@ export const foofoofoofoofoofoofoo = "ahah", barbarbarbarbarbarbar = {}, loremlo ----- Indent style: Tab Line width: 80 - ----- export let a, d, c; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/binary_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/binary_expression.js.snap index a31f7275d32..48137f17ca0 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/binary_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/binary_expression.js.snap @@ -35,7 +35,6 @@ a instanceof b ----- Indent style: Tab Line width: 80 - ----- a + b; a < b; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/conditional_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/conditional_expression.js.snap index b8f0941cdd3..d83964e9dbd 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/conditional_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/conditional_expression.js.snap @@ -16,7 +16,6 @@ d ----- Indent style: Tab Line width: 80 - ----- a ? b : c; d ? (e + f) : (g + h); diff --git a/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js.snap index 18aa7f94dd8..9e2eac1361e 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js.snap @@ -15,7 +15,6 @@ import.meta.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherR ----- Indent style: Tab Line width: 80 - ----- console.log(import.meta); import.meta.field = @@ -25,7 +24,6 @@ import.meta.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherR ----- Indent style: Spaces, size: 4 Line width: 120 - ----- console.log(import.meta); import.meta.field = diff --git a/crates/rome_formatter/tests/specs/js/module/expression/literal_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/literal_expression.js.snap index 5dfb1d5b1cf..5b834d01732 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/literal_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/literal_expression.js.snap @@ -18,7 +18,6 @@ null ----- Indent style: Tab Line width: 80 - ----- "a"; 1; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/logical_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/logical_expression.js.snap index ee1564633c2..16fc364097f 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/logical_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/logical_expression.js.snap @@ -15,7 +15,6 @@ x && y ----- Indent style: Tab Line width: 80 - ----- x ?? y; x || y; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/new_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/new_expression.js.snap index 66384b140b4..101085b1daf 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/new_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/new_expression.js.snap @@ -15,7 +15,6 @@ new c(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,cccccccccccc ----- Indent style: Tab Line width: 80 - ----- new a(); new b(x); diff --git a/crates/rome_formatter/tests/specs/js/module/expression/post_update_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/post_update_expression.js.snap index 3bd59f37722..3ac7537a03b 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/post_update_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/post_update_expression.js.snap @@ -16,7 +16,6 @@ x = y-- ----- Indent style: Tab Line width: 80 - ----- y++; y--; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/pre_update_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/pre_update_expression.js.snap index 2d012f1b4bb..a8bbcd6f28f 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/pre_update_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/pre_update_expression.js.snap @@ -16,7 +16,6 @@ x = --y ----- Indent style: Tab Line width: 80 - ----- ++y; --y; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/sequence_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/sequence_expression.js.snap index 0a741d88614..682f6bc8303 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/sequence_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/sequence_expression.js.snap @@ -13,7 +13,6 @@ a,b ----- Indent style: Tab Line width: 80 - ----- a, b; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/static_member_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/static_member_expression.js.snap index e8c08a03245..9f09bf0c205 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/static_member_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/static_member_expression.js.snap @@ -18,7 +18,6 @@ a?.#b.c().d ----- Indent style: Tab Line width: 80 - ----- a.b; a?.b; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/this_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/this_expression.js.snap index b573029a635..397ede83cde 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/this_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/this_expression.js.snap @@ -13,7 +13,6 @@ this ----- Indent style: Tab Line width: 80 - ----- this; diff --git a/crates/rome_formatter/tests/specs/js/module/expression/unary_expression.js.snap b/crates/rome_formatter/tests/specs/js/module/expression/unary_expression.js.snap index bf300576d67..9389ff3f325 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/unary_expression.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/expression/unary_expression.js.snap @@ -26,7 +26,6 @@ x = !aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ----- Indent style: Tab Line width: 80 - ----- delete a.a; void b; diff --git a/crates/rome_formatter/tests/specs/js/module/function/function_args.js.snap b/crates/rome_formatter/tests/specs/js/module/function/function_args.js.snap index 969a0b67bc3..49cb8dc36e1 100644 --- a/crates/rome_formatter/tests/specs/js/module/function/function_args.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/function/function_args.js.snap @@ -14,7 +14,6 @@ function foo(someotherlongvariableshould1, someotherlongvariableshould2, someoth ----- Indent style: Tab Line width: 80 - ----- function foo( someotherlongvariableshould1, diff --git a/crates/rome_formatter/tests/specs/js/module/function/function_comments.js.snap b/crates/rome_formatter/tests/specs/js/module/function/function_comments.js.snap index b63f6f0c9d8..e4fdde448ae 100644 --- a/crates/rome_formatter/tests/specs/js/module/function/function_comments.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/function/function_comments.js.snap @@ -28,7 +28,6 @@ function c( //some comment ----- Indent style: Tab Line width: 80 - ----- function a() { // trailing comment diff --git a/crates/rome_formatter/tests/specs/js/module/ident.js.snap b/crates/rome_formatter/tests/specs/js/module/ident.js.snap index f8366c0da00..4ae63f5d9bb 100644 --- a/crates/rome_formatter/tests/specs/js/module/ident.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/ident.js.snap @@ -13,7 +13,6 @@ x ----- Indent style: Tab Line width: 80 - ----- x; diff --git a/crates/rome_formatter/tests/specs/js/module/import/bare_import.js.snap b/crates/rome_formatter/tests/specs/js/module/import/bare_import.js.snap index b7ae8754546..04c3ba90368 100644 --- a/crates/rome_formatter/tests/specs/js/module/import/bare_import.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/import/bare_import.js.snap @@ -31,7 +31,6 @@ import "very_long_import_very_long_import_very" assert { ----- Indent style: Tab Line width: 80 - ----- import "very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_"; import "very_long_import_very_long_import_very_long_import_very_long_import_very_long_import_very_long" assert { diff --git a/crates/rome_formatter/tests/specs/js/module/import/default_import.js.snap b/crates/rome_formatter/tests/specs/js/module/import/default_import.js.snap index 097ca25ca1c..34d4e571784 100644 --- a/crates/rome_formatter/tests/specs/js/module/import/default_import.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/import/default_import.js.snap @@ -23,7 +23,6 @@ import a, * as b from "foo" ----- Indent style: Tab Line width: 80 - ----- import hey from "hey"; import hey from "hey"; diff --git a/crates/rome_formatter/tests/specs/js/module/import/import_call.js.snap b/crates/rome_formatter/tests/specs/js/module/import/import_call.js.snap index 7f319546eba..ca6a7ddca0c 100644 --- a/crates/rome_formatter/tests/specs/js/module/import/import_call.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/import/import_call.js.snap @@ -15,7 +15,6 @@ import(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ----- Indent style: Tab Line width: 80 - ----- import(x); import("x"); diff --git a/crates/rome_formatter/tests/specs/js/module/import/import_specifiers.js.snap b/crates/rome_formatter/tests/specs/js/module/import/import_specifiers.js.snap index 81f4d9e0bd1..873cbe3cde2 100644 --- a/crates/rome_formatter/tests/specs/js/module/import/import_specifiers.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/import/import_specifiers.js.snap @@ -28,7 +28,6 @@ import loooooooooooooooooooong7, { loooooooooooooooooooong8, loooooooooooooooooo ----- Indent style: Tab Line width: 80 - ----- import { hey } from "hey"; import { hey } from "hey"; diff --git a/crates/rome_formatter/tests/specs/js/module/import/namespace_import.js.snap b/crates/rome_formatter/tests/specs/js/module/import/namespace_import.js.snap index 0259a3d32fa..c0c9bc88020 100644 --- a/crates/rome_formatter/tests/specs/js/module/import/namespace_import.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/import/namespace_import.js.snap @@ -12,7 +12,6 @@ import * as all from "all" ----- Indent style: Tab Line width: 80 - ----- import * as all from "all"; diff --git a/crates/rome_formatter/tests/specs/js/module/invalid/block_stmt_err.js.snap b/crates/rome_formatter/tests/specs/js/module/invalid/block_stmt_err.js.snap index 8d1119d562d..1bacdc0fef7 100644 --- a/crates/rome_formatter/tests/specs/js/module/invalid/block_stmt_err.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/invalid/block_stmt_err.js.snap @@ -22,7 +22,6 @@ let recovered = "no" ----- Indent style: Tab Line width: 80 - ----- { let x = 10; diff --git a/crates/rome_formatter/tests/specs/js/module/invalid/if_stmt_err.js.snap b/crates/rome_formatter/tests/specs/js/module/invalid/if_stmt_err.js.snap index eef8b28a46a..24191fc8f20 100644 --- a/crates/rome_formatter/tests/specs/js/module/invalid/if_stmt_err.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/invalid/if_stmt_err.js.snap @@ -28,7 +28,6 @@ if (false) { ----- Indent style: Tab Line width: 80 - ----- function test() { let x = 10; diff --git a/crates/rome_formatter/tests/specs/js/module/newlines.js.snap b/crates/rome_formatter/tests/specs/js/module/newlines.js.snap index db763748984..c0a99b33fbd 100644 --- a/crates/rome_formatter/tests/specs/js/module/newlines.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/newlines.js.snap @@ -90,7 +90,6 @@ const object = { ----- Indent style: Tab Line width: 80 - ----- "directive"; // comment diff --git a/crates/rome_formatter/tests/specs/js/module/number/number.js.snap b/crates/rome_formatter/tests/specs/js/module/number/number.js.snap index 477578ca61b..26d34d4cc39 100644 --- a/crates/rome_formatter/tests/specs/js/module/number/number.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/number/number.js.snap @@ -14,7 +14,6 @@ expression: number.js ----- Indent style: Tab Line width: 80 - ----- 1.23e4; 1000e3; // FIXME handle number with scientific notation #1294 diff --git a/crates/rome_formatter/tests/specs/js/module/object/computed_member.js.snap b/crates/rome_formatter/tests/specs/js/module/object/computed_member.js.snap index 0958007a285..da73bf88d14 100644 --- a/crates/rome_formatter/tests/specs/js/module/object/computed_member.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/object/computed_member.js.snap @@ -20,7 +20,6 @@ c?.[ d ] ----- Indent style: Tab Line width: 80 - ----- const foo = {}; diff --git a/crates/rome_formatter/tests/specs/js/module/object/getter_setter.js.snap b/crates/rome_formatter/tests/specs/js/module/object/getter_setter.js.snap index 2c89476a405..4a775aec809 100644 --- a/crates/rome_formatter/tests/specs/js/module/object/getter_setter.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/object/getter_setter.js.snap @@ -18,7 +18,6 @@ let b = { ----- Indent style: Tab Line width: 80 - ----- let a = { get foo() {} }; let b = { set foo(a) {} }; diff --git a/crates/rome_formatter/tests/specs/js/module/object/object.js.snap b/crates/rome_formatter/tests/specs/js/module/object/object.js.snap index 3fe2ffae1aa..5c96f0a62cb 100644 --- a/crates/rome_formatter/tests/specs/js/module/object/object.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/object/object.js.snap @@ -33,7 +33,6 @@ let a = { ----- Indent style: Tab Line width: 80 - ----- let a = { ...spread, diff --git a/crates/rome_formatter/tests/specs/js/module/object/object_comments.js.snap b/crates/rome_formatter/tests/specs/js/module/object/object_comments.js.snap index 1c9c89dd6e4..3b42acaca30 100644 --- a/crates/rome_formatter/tests/specs/js/module/object/object_comments.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/object/object_comments.js.snap @@ -15,7 +15,6 @@ let a = { // leading comment ----- Indent style: Tab Line width: 80 - ----- let a = { // leading comment diff --git a/crates/rome_formatter/tests/specs/js/module/object/property_key.js.snap b/crates/rome_formatter/tests/specs/js/module/object/property_key.js.snap index b42ab3bf19d..2ba0fe20d74 100644 --- a/crates/rome_formatter/tests/specs/js/module/object/property_key.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/object/property_key.js.snap @@ -20,7 +20,6 @@ const foo = { ----- Indent style: Tab Line width: 80 - ----- const foo = { "foo-bar": true, diff --git a/crates/rome_formatter/tests/specs/js/module/parentheses/parentheses.js.snap b/crates/rome_formatter/tests/specs/js/module/parentheses/parentheses.js.snap index b8e6d5b4561..1389b5cd393 100644 --- a/crates/rome_formatter/tests/specs/js/module/parentheses/parentheses.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/parentheses/parentheses.js.snap @@ -23,7 +23,6 @@ const foo = class extends (Bar ?? Baz) {} ----- Indent style: Tab Line width: 80 - ----- (foo++)?.(); async () => { diff --git a/crates/rome_formatter/tests/specs/js/module/script.js.snap b/crates/rome_formatter/tests/specs/js/module/script.js.snap index 26b16c7a7e5..c0bca8a7a64 100644 --- a/crates/rome_formatter/tests/specs/js/module/script.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/script.js.snap @@ -16,7 +16,6 @@ var express = require("express") ----- Indent style: Tab Line width: 80 - ----- #!/usr/bin/env node "use strict"; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/do_while.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/do_while.js.snap index c6a54dad26a..211ef1546b8 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/do_while.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/do_while.js.snap @@ -23,7 +23,6 @@ while (something) ----- Indent style: Tab Line width: 80 - ----- do { var foo = 4; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/for_in.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/for_in.js.snap index 6e3eae05855..d3da4989ca0 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/for_in.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/for_in.js.snap @@ -18,7 +18,6 @@ for (a in b) { // trailing ----- Indent style: Tab Line width: 80 - ----- for (a in b) {} diff --git a/crates/rome_formatter/tests/specs/js/module/statement/for_loop.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/for_loop.js.snap index 982201df9be..bbf962145f2 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/for_loop.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/for_loop.js.snap @@ -29,7 +29,6 @@ for(let aVeryLongVariableNameToEnforceLineBreaks = 0; aVeryLongVariableNameToEnf ----- Indent style: Tab Line width: 80 - ----- for (;;) { let x = 10; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/if_else.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/if_else.js.snap index 0e66c931dd2..a144ae73b70 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/if_else.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/if_else.js.snap @@ -70,7 +70,6 @@ if (true) { ----- Indent style: Tab Line width: 80 - ----- if (Math.random() > 0.5) { console.log(1); diff --git a/crates/rome_formatter/tests/specs/js/module/statement/statement.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/statement.js.snap index 8d6048d61b4..9a416efbc55 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/statement.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/statement.js.snap @@ -14,7 +14,6 @@ debugger ----- Indent style: Tab Line width: 80 - ----- debugger; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/switch.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/switch.js.snap index e39f2fc53e5..246fd8ae204 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/switch.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/switch.js.snap @@ -22,7 +22,6 @@ switch (key) { ----- Indent style: Tab Line width: 80 - ----- switch (key) { case value: diff --git a/crates/rome_formatter/tests/specs/js/module/statement/throw.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/throw.js.snap index 67d1a92d599..e059ff07eee 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/throw.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/throw.js.snap @@ -15,7 +15,6 @@ throw false ----- Indent style: Tab Line width: 80 - ----- throw "Something"; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/try_catch_finally.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/try_catch_finally.js.snap index 82ed06b9483..5e6819fd916 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/try_catch_finally.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/try_catch_finally.js.snap @@ -38,7 +38,6 @@ try { ----- Indent style: Tab Line width: 80 - ----- try { var foo = 4; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/while_loop.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/while_loop.js.snap index a81af0bcb06..f0ae798fd30 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/while_loop.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/while_loop.js.snap @@ -38,7 +38,6 @@ tour: while (true) { ----- Indent style: Tab Line width: 80 - ----- while (true) { var foo = 4; diff --git a/crates/rome_formatter/tests/specs/js/module/template/template.js.snap b/crates/rome_formatter/tests/specs/js/module/template/template.js.snap index 4c01a393373..420e8b888af 100644 --- a/crates/rome_formatter/tests/specs/js/module/template/template.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/template/template.js.snap @@ -29,7 +29,6 @@ output ----- Indent style: Tab Line width: 80 - ----- `something`; diff --git a/crates/rome_formatter/tests/specs/js/module/with.js.snap b/crates/rome_formatter/tests/specs/js/module/with.js.snap index 2ce885e4af3..84f13a2dd16 100644 --- a/crates/rome_formatter/tests/specs/js/module/with.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/with.js.snap @@ -17,7 +17,6 @@ with ( b) ----- Indent style: Tab Line width: 80 - ----- with ( b) diff --git a/crates/rome_formatter/tests/specs/js/script/script.js.snap b/crates/rome_formatter/tests/specs/js/script/script.js.snap index 26b16c7a7e5..c0bca8a7a64 100644 --- a/crates/rome_formatter/tests/specs/js/script/script.js.snap +++ b/crates/rome_formatter/tests/specs/js/script/script.js.snap @@ -16,7 +16,6 @@ var express = require("express") ----- Indent style: Tab Line width: 80 - ----- #!/usr/bin/env node "use strict"; diff --git a/crates/rome_formatter/tests/specs/js/script/with.js.snap b/crates/rome_formatter/tests/specs/js/script/with.js.snap index 19a450dd17b..f8d32367db0 100644 --- a/crates/rome_formatter/tests/specs/js/script/with.js.snap +++ b/crates/rome_formatter/tests/specs/js/script/with.js.snap @@ -17,7 +17,6 @@ with ( b) ----- Indent style: Tab Line width: 80 - ----- with (b) { 5; From 8a47d5dd0927e0062be23548207354a68e505e2c Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Thu, 3 Feb 2022 17:12:35 +0000 Subject: [PATCH 03/10] applied feature "test" to conditionally apply serde --- crates/rome_formatter/Cargo.toml | 7 +- crates/rome_formatter/src/lib.rs | 2 + crates/rome_formatter/tests/spec_test.rs | 262 ++++++++++------------ crates/rome_formatter/tests/spec_tests.rs | 8 +- 4 files changed, 129 insertions(+), 150 deletions(-) diff --git a/crates/rome_formatter/Cargo.toml b/crates/rome_formatter/Cargo.toml index e2ae108c7fa..f88c8541624 100644 --- a/crates/rome_formatter/Cargo.toml +++ b/crates/rome_formatter/Cargo.toml @@ -12,9 +12,12 @@ rome_path = { version = "0.0.0", path = "../rome_path" } rome_core = { version = "0.0.0", path = "../rome_core" } cfg-if = "1.0.0" thiserror = "1.0.30" +serde = { version = "1", features = ["derive"] } +serde_json = "1" [dev-dependencies] tests_macros = { path = "../tests_macros" } insta = "1.10.0" -serde = { version = "1", features = ["derive"] } -serde_json = "1" + +[features] +test = ["serde_json/default", "serde/derive"] diff --git a/crates/rome_formatter/src/lib.rs b/crates/rome_formatter/src/lib.rs index f2c4a685e78..75cc2b0d747 100644 --- a/crates/rome_formatter/src/lib.rs +++ b/crates/rome_formatter/src/lib.rs @@ -117,6 +117,7 @@ impl From<&SyntaxError> for FormatError { } #[derive(Debug, Eq, PartialEq, Clone, Copy)] +#[cfg_attr(feature = "test", derive(serde::Serialize, serde::Deserialize))] pub enum IndentStyle { /// Tab Tab, @@ -153,6 +154,7 @@ impl Display for IndentStyle { } #[derive(Debug, Clone, Copy)] +#[cfg_attr(feature = "test", derive(serde::Serialize, serde::Deserialize))] pub struct FormatOptions { /// The indent style pub indent_style: IndentStyle, diff --git a/crates/rome_formatter/tests/spec_test.rs b/crates/rome_formatter/tests/spec_test.rs index 255bfa15519..6d32b0d80a7 100644 --- a/crates/rome_formatter/tests/spec_test.rs +++ b/crates/rome_formatter/tests/spec_test.rs @@ -1,160 +1,130 @@ -use rome_core::App; -use rome_formatter::{format, FormatOptions, IndentStyle}; -use rome_path::RomePath; -use rslint_parser::{parse, Syntax}; -use serde::{Deserialize, Serialize}; -use std::fmt::Debug; -use std::fs; -use std::path::{Path, PathBuf}; - -#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] -pub enum IndentStyleTest { - /// Tab - Tab, - /// Space, with its quantity - Space(u8), -} - -impl From for IndentStyle { - fn from(test: IndentStyleTest) -> Self { - match test { - IndentStyleTest::Tab => IndentStyle::Tab, - IndentStyleTest::Space(s) => IndentStyle::Space(s), - } +#[cfg(feature = "test")] +pub mod test_formatter { + use rome_core::App; + use rome_formatter::{format, FormatOptions}; + use rome_path::RomePath; + use rslint_parser::{parse, Syntax}; + use serde::{Deserialize, Serialize}; + use std::fmt::Debug; + use std::fs; + use std::path::{Path, PathBuf}; + + #[derive(Debug, Deserialize, Serialize)] + pub struct Options { + cases: Vec, } -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct FormatOptionsTest { - /// The indent style - pub indent_style: Option, - /// What's the max width of a line. Defaults to 80 - pub line_width: Option, -} - -impl From for FormatOptions { - fn from(test: FormatOptionsTest) -> Self { - Self { - indent_style: test - .indent_style - .map_or_else(|| IndentStyle::Tab, |value| value.into()), - line_width: test.line_width.unwrap_or(80), - } + #[derive(Debug, Default)] + struct SnapshotContent { + input: String, + output: Vec<(String, FormatOptions)>, } -} - -#[derive(Debug, Deserialize, Serialize)] -pub struct Options { - cases: Vec, -} -#[derive(Debug, Default)] -struct SnapshotContent { - input: String, - output: Vec<(String, FormatOptions)>, -} + impl SnapshotContent { + pub fn add_output(&mut self, content: &str, options: FormatOptions) { + self.output.push((String::from(content), options)) + } -impl SnapshotContent { - pub fn add_output(&mut self, content: &str, options: FormatOptions) { - self.output.push((String::from(content), options)) - } + pub fn set_input(&mut self, content: &str) { + self.input = String::from(content); + } - pub fn set_input(&mut self, content: &str) { - self.input = String::from(content); - } + pub fn snap_content(&mut self) -> String { + let mut output = String::new(); + output.push_str("# Input"); + output.push('\n'); + output.push_str(self.input.as_str()); + output.push_str("\n=============================\n"); + + output.push_str("# Outputs\n"); + let iter = self.output.iter(); + for (index, (content, options)) in iter.enumerate() { + let formal_index = index + 1; + output.push_str(format!("## Output {formal_index}\n").as_str()); + output.push_str("-----\n"); + output.push_str(format!("{}", options).as_str()); + output.push_str("-----\n"); + output.push_str(content.as_str()); + } - pub fn snap_content(&mut self) -> String { - let mut output = String::new(); - output.push_str("# Input"); - output.push('\n'); - output.push_str(self.input.as_str()); - output.push_str("\n=============================\n"); - - output.push_str("# Outputs\n"); - let iter = self.output.iter(); - for (index, (content, options)) in iter.enumerate() { - let formal_index = index + 1; - output.push_str(format!("## Output {formal_index}\n").as_str()); - output.push_str("-----\n"); - output.push_str(format!("{}", options).as_str()); - output.push_str("-----\n"); - output.push_str(content.as_str()); + output } - - output } -} -/// [insta.rs](https://insta.rs/docs) snapshot testing -/// -/// For better development workflow, run -/// `cargo watch -i '*.new' -x 'test -p rome_formatter formatter'` -/// -/// To review and commit the snapshots, `cargo install cargo-insta`, and run -/// `cargo insta review` or `cargo insta accept` -/// -/// The input and the expected output are stored as dedicated files in the `tests/specs` directory where -/// the input file name is `{spec_name}.json` and the output file name is `{spec_name}.json.snap`. -/// -/// Specs can be grouped in directories by specifying the directory name in the spec name. Examples: -/// -/// # Examples -/// -/// * `json/null` -> input: `tests/specs/json/null.json`, expected output: `tests/specs/json/null.json.snap` -/// * `null` -> input: `tests/specs/null.json`, expected output: `tests/specs/null.json.snap` -pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, file_type: &str) { - let app = App::new(); - let file_path = &spec_input_file; - let spec_input_file = Path::new(spec_input_file); - - assert!( - spec_input_file.is_file(), - "The input '{}' must exist and be a file.", - spec_input_file.display() - ); - - let mut rome_path = RomePath::new(file_path); - if app.can_format(&rome_path) { - let mut snapshot_content = SnapshotContent::default(); - let buffer = rome_path.get_buffer_from_file(); - let syntax = if file_type == "module" { - Syntax::default().module() - } else { - Syntax::default() - }; - - let input = fs::read_to_string(file_path).unwrap(); - snapshot_content.set_input(input.as_str()); - - let root = parse(buffer.as_str(), 0, syntax).syntax(); - let formatted_result = format(FormatOptions::default(), &root); - let file_name = spec_input_file.file_name().unwrap().to_str().unwrap(); - // we ignore the error for now - let result = formatted_result.unwrap(); - - snapshot_content.add_output(result.as_code(), FormatOptions::default()); - - let test_directory = PathBuf::from(test_directory); - let options_path = test_directory.join("options.json"); - if options_path.exists() { - let mut options_path = RomePath::new(options_path.display().to_string().as_str()); - // SAFETY: we checked its existence already, we assume we have rights to read it - let options: Options = - serde_json::from_str(options_path.get_buffer_from_file().as_str()).unwrap(); - - for test_case in options.cases { - let options = test_case.clone(); - let formatted_result = format(test_case.into(), &root).unwrap(); - snapshot_content.add_output(formatted_result.as_code(), options.into()); + /// [insta.rs](https://insta.rs/docs) snapshot testing + /// + /// For better development workflow, run + /// `cargo watch -i '*.new' -x 'test -p rome_formatter formatter'` + /// + /// To review and commit the snapshots, `cargo install cargo-insta`, and run + /// `cargo insta review` or `cargo insta accept` + /// + /// The input and the expected output are stored as dedicated files in the `tests/specs` directory where + /// the input file name is `{spec_name}.json` and the output file name is `{spec_name}.json.snap`. + /// + /// Specs can be grouped in directories by specifying the directory name in the spec name. Examples: + /// + /// # Examples + /// + /// * `json/null` -> input: `tests/specs/json/null.json`, expected output: `tests/specs/json/null.json.snap` + /// * `null` -> input: `tests/specs/null.json`, expected output: `tests/specs/null.json.snap` + pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, file_type: &str) { + let app = App::new(); + let file_path = &spec_input_file; + let spec_input_file = Path::new(spec_input_file); + + assert!( + spec_input_file.is_file(), + "The input '{}' must exist and be a file.", + spec_input_file.display() + ); + + let mut rome_path = RomePath::new(file_path); + if app.can_format(&rome_path) { + let mut snapshot_content = SnapshotContent::default(); + let buffer = rome_path.get_buffer_from_file(); + let syntax = if file_type == "module" { + Syntax::default().module() + } else { + Syntax::default() + }; + + let input = fs::read_to_string(file_path).unwrap(); + snapshot_content.set_input(input.as_str()); + + let root = parse(buffer.as_str(), 0, syntax).syntax(); + let formatted_result = format(FormatOptions::default(), &root); + let file_name = spec_input_file.file_name().unwrap().to_str().unwrap(); + // we ignore the error for now + let result = formatted_result.unwrap(); + + snapshot_content.add_output(result.as_code(), FormatOptions::default()); + + let test_directory = PathBuf::from(test_directory); + let options_path = test_directory.join("options.json"); + if options_path.exists() { + #[cfg(feature = "test")] + { + let mut options_path = + RomePath::new(options_path.display().to_string().as_str()); + // SAFETY: we checked its existence already, we assume we have rights to read it + let options: Options = + serde_json::from_str(options_path.get_buffer_from_file().as_str()).unwrap(); + + for test_case in options.cases { + let options = test_case.clone(); + let formatted_result = format(test_case.into(), &root).unwrap(); + snapshot_content.add_output(formatted_result.as_code(), options.into()); + } + } } - } - insta::with_settings!({ - prepend_module_to_snapshot => false, - snapshot_path => spec_input_file.parent().unwrap(), - }, { - insta::assert_snapshot!(file_name, snapshot_content.snap_content(), file_name); - }); + insta::with_settings!({ + prepend_module_to_snapshot => false, + snapshot_path => spec_input_file.parent().unwrap(), + }, { + insta::assert_snapshot!(file_name, snapshot_content.snap_content(), file_name); + }); + } } } diff --git a/crates/rome_formatter/tests/spec_tests.rs b/crates/rome_formatter/tests/spec_tests.rs index 0823605eb00..588ffca6d12 100644 --- a/crates/rome_formatter/tests/spec_tests.rs +++ b/crates/rome_formatter/tests/spec_tests.rs @@ -3,12 +3,16 @@ mod spec_test; mod formatter { mod js_module { + #[cfg(feature = "test")] use crate::spec_test; - tests_macros::gen_tests! {"tests/specs/js/module/**/**/**/*.js", spec_test::run, "module"} + #[cfg(feature = "test")] + tests_macros::gen_tests! {"tests/specs/js/module/**/**/**/*.js", spec_test::test_formatter::run, "module"} } mod js_script { + #[cfg(feature = "test")] use crate::spec_test; - tests_macros::gen_tests! {"tests/specs/js/script/**/**/**/*.js", spec_test::run, "script"} + #[cfg(feature = "test")] + tests_macros::gen_tests! {"tests/specs/js/script/**/**/**/*.js", spec_test::test_formatter::run, "script"} } } From c622e8da6813afca605dde299fb78cdd7bd4534b Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 4 Feb 2022 15:53:19 +0000 Subject: [PATCH 04/10] change mapping solution for options --- crates/rome_formatter/Cargo.toml | 7 +- crates/rome_formatter/src/lib.rs | 2 - crates/rome_formatter/tests/spec_test.rs | 262 ++++++++++++---------- crates/rome_formatter/tests/spec_tests.rs | 8 +- 4 files changed, 151 insertions(+), 128 deletions(-) diff --git a/crates/rome_formatter/Cargo.toml b/crates/rome_formatter/Cargo.toml index f88c8541624..403a537f29d 100644 --- a/crates/rome_formatter/Cargo.toml +++ b/crates/rome_formatter/Cargo.toml @@ -12,12 +12,9 @@ rome_path = { version = "0.0.0", path = "../rome_path" } rome_core = { version = "0.0.0", path = "../rome_core" } cfg-if = "1.0.0" thiserror = "1.0.30" -serde = { version = "1", features = ["derive"] } -serde_json = "1" [dev-dependencies] +serde = { version = "1", features = ["derive"] } +serde_json = "1" tests_macros = { path = "../tests_macros" } insta = "1.10.0" - -[features] -test = ["serde_json/default", "serde/derive"] diff --git a/crates/rome_formatter/src/lib.rs b/crates/rome_formatter/src/lib.rs index 75cc2b0d747..f2c4a685e78 100644 --- a/crates/rome_formatter/src/lib.rs +++ b/crates/rome_formatter/src/lib.rs @@ -117,7 +117,6 @@ impl From<&SyntaxError> for FormatError { } #[derive(Debug, Eq, PartialEq, Clone, Copy)] -#[cfg_attr(feature = "test", derive(serde::Serialize, serde::Deserialize))] pub enum IndentStyle { /// Tab Tab, @@ -154,7 +153,6 @@ impl Display for IndentStyle { } #[derive(Debug, Clone, Copy)] -#[cfg_attr(feature = "test", derive(serde::Serialize, serde::Deserialize))] pub struct FormatOptions { /// The indent style pub indent_style: IndentStyle, diff --git a/crates/rome_formatter/tests/spec_test.rs b/crates/rome_formatter/tests/spec_test.rs index 6d32b0d80a7..7d46f49e607 100644 --- a/crates/rome_formatter/tests/spec_test.rs +++ b/crates/rome_formatter/tests/spec_test.rs @@ -1,130 +1,162 @@ -#[cfg(feature = "test")] -pub mod test_formatter { - use rome_core::App; - use rome_formatter::{format, FormatOptions}; - use rome_path::RomePath; - use rslint_parser::{parse, Syntax}; - use serde::{Deserialize, Serialize}; - use std::fmt::Debug; - use std::fs; - use std::path::{Path, PathBuf}; - - #[derive(Debug, Deserialize, Serialize)] - pub struct Options { - cases: Vec, - } +use rome_core::App; +use rome_formatter::{format, FormatOptions, IndentStyle}; +use rome_path::RomePath; +use rslint_parser::{parse, Syntax}; +use serde::{Deserialize, Serialize}; +use std::fmt::Debug; +use std::fs; +use std::path::{Path, PathBuf}; + +#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] +pub enum SerializableIndentStyle { + /// Tab + Tab, + /// Space, with its quantity + Space(u8), +} - #[derive(Debug, Default)] - struct SnapshotContent { - input: String, - output: Vec<(String, FormatOptions)>, +impl From for IndentStyle { + fn from(test: SerializableIndentStyle) -> Self { + match test { + SerializableIndentStyle::Tab => IndentStyle::Tab, + SerializableIndentStyle::Space(s) => IndentStyle::Space(s), + } } +} - impl SnapshotContent { - pub fn add_output(&mut self, content: &str, options: FormatOptions) { - self.output.push((String::from(content), options)) - } +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct SerializableFormatOptions { + /// The indent style + pub indent_style: Option, - pub fn set_input(&mut self, content: &str) { - self.input = String::from(content); + /// What's the max width of a line. Defaults to 80 + pub line_width: Option, +} + +impl From for FormatOptions { + fn from(test: SerializableFormatOptions) -> Self { + Self { + indent_style: test + .indent_style + .map_or_else(|| IndentStyle::Tab, |value| value.into()), + line_width: test.line_width.unwrap_or(80), } + } +} - pub fn snap_content(&mut self) -> String { - let mut output = String::new(); - output.push_str("# Input"); - output.push('\n'); - output.push_str(self.input.as_str()); - output.push_str("\n=============================\n"); - - output.push_str("# Outputs\n"); - let iter = self.output.iter(); - for (index, (content, options)) in iter.enumerate() { - let formal_index = index + 1; - output.push_str(format!("## Output {formal_index}\n").as_str()); - output.push_str("-----\n"); - output.push_str(format!("{}", options).as_str()); - output.push_str("-----\n"); - output.push_str(content.as_str()); - } +#[derive(Debug, Deserialize, Serialize)] +pub struct TestOptions { + cases: Vec, +} - output +#[derive(Debug, Default)] +struct SnapshotContent { + input: String, + output: Vec<(String, FormatOptions)>, +} + +impl SnapshotContent { + pub fn add_output(&mut self, content: &str, options: FormatOptions) { + self.output.push((String::from(content), options)) + } + + pub fn set_input(&mut self, content: &str) { + self.input = String::from(content); + } + + pub fn snap_content(&mut self) -> String { + let mut output = String::new(); + output.push_str("# Input"); + output.push('\n'); + output.push_str(self.input.as_str()); + output.push_str("\n=============================\n"); + + output.push_str("# Outputs\n"); + let iter = self.output.iter(); + for (index, (content, options)) in iter.enumerate() { + let formal_index = index + 1; + output.push_str(format!("## Output {formal_index}\n").as_str()); + output.push_str("-----\n"); + output.push_str(format!("{}", options).as_str()); + output.push_str("-----\n"); + output.push_str(content.as_str()); } + + output } +} - /// [insta.rs](https://insta.rs/docs) snapshot testing - /// - /// For better development workflow, run - /// `cargo watch -i '*.new' -x 'test -p rome_formatter formatter'` - /// - /// To review and commit the snapshots, `cargo install cargo-insta`, and run - /// `cargo insta review` or `cargo insta accept` - /// - /// The input and the expected output are stored as dedicated files in the `tests/specs` directory where - /// the input file name is `{spec_name}.json` and the output file name is `{spec_name}.json.snap`. - /// - /// Specs can be grouped in directories by specifying the directory name in the spec name. Examples: - /// - /// # Examples - /// - /// * `json/null` -> input: `tests/specs/json/null.json`, expected output: `tests/specs/json/null.json.snap` - /// * `null` -> input: `tests/specs/null.json`, expected output: `tests/specs/null.json.snap` - pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, file_type: &str) { - let app = App::new(); - let file_path = &spec_input_file; - let spec_input_file = Path::new(spec_input_file); - - assert!( - spec_input_file.is_file(), - "The input '{}' must exist and be a file.", - spec_input_file.display() - ); - - let mut rome_path = RomePath::new(file_path); - if app.can_format(&rome_path) { - let mut snapshot_content = SnapshotContent::default(); - let buffer = rome_path.get_buffer_from_file(); - let syntax = if file_type == "module" { - Syntax::default().module() - } else { - Syntax::default() - }; - - let input = fs::read_to_string(file_path).unwrap(); - snapshot_content.set_input(input.as_str()); - - let root = parse(buffer.as_str(), 0, syntax).syntax(); - let formatted_result = format(FormatOptions::default(), &root); - let file_name = spec_input_file.file_name().unwrap().to_str().unwrap(); - // we ignore the error for now - let result = formatted_result.unwrap(); - - snapshot_content.add_output(result.as_code(), FormatOptions::default()); - - let test_directory = PathBuf::from(test_directory); - let options_path = test_directory.join("options.json"); - if options_path.exists() { - #[cfg(feature = "test")] - { - let mut options_path = - RomePath::new(options_path.display().to_string().as_str()); - // SAFETY: we checked its existence already, we assume we have rights to read it - let options: Options = - serde_json::from_str(options_path.get_buffer_from_file().as_str()).unwrap(); - - for test_case in options.cases { - let options = test_case.clone(); - let formatted_result = format(test_case.into(), &root).unwrap(); - snapshot_content.add_output(formatted_result.as_code(), options.into()); - } +/// [insta.rs](https://insta.rs/docs) snapshot testing +/// +/// For better development workflow, run +/// `cargo watch -i '*.new' -x 'test -p rome_formatter formatter'` +/// +/// To review and commit the snapshots, `cargo install cargo-insta`, and run +/// `cargo insta review` or `cargo insta accept` +/// +/// The input and the expected output are stored as dedicated files in the `tests/specs` directory where +/// the input file name is `{spec_name}.json` and the output file name is `{spec_name}.json.snap`. +/// +/// Specs can be grouped in directories by specifying the directory name in the spec name. Examples: +/// +/// # Examples +/// +/// * `json/null` -> input: `tests/specs/json/null.json`, expected output: `tests/specs/json/null.json.snap` +/// * `null` -> input: `tests/specs/null.json`, expected output: `tests/specs/null.json.snap` +pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, file_type: &str) { + let app = App::new(); + let file_path = &spec_input_file; + let spec_input_file = Path::new(spec_input_file); + + assert!( + spec_input_file.is_file(), + "The input '{}' must exist and be a file.", + spec_input_file.display() + ); + + let mut rome_path = RomePath::new(file_path); + if app.can_format(&rome_path) { + let mut snapshot_content = SnapshotContent::default(); + let buffer = rome_path.get_buffer_from_file(); + let syntax = if file_type == "module" { + Syntax::default().module() + } else { + Syntax::default() + }; + + let input = fs::read_to_string(file_path).unwrap(); + snapshot_content.set_input(input.as_str()); + + let root = parse(buffer.as_str(), 0, syntax).syntax(); + let formatted_result = format(FormatOptions::default(), &root); + let file_name = spec_input_file.file_name().unwrap().to_str().unwrap(); + // we ignore the error for now + let result = formatted_result.unwrap(); + + snapshot_content.add_output(result.as_code(), FormatOptions::default()); + + let test_directory = PathBuf::from(test_directory); + let options_path = test_directory.join("options.json"); + if options_path.exists() { + { + let mut options_path = RomePath::new(options_path.display().to_string().as_str()); + // SAFETY: we checked its existence already, we assume we have rights to read it + let options: TestOptions = + serde_json::from_str(options_path.get_buffer_from_file().as_str()).unwrap(); + + for test_case in options.cases { + let options = test_case.clone(); + let formatted_result = format(test_case.into(), &root).unwrap(); + snapshot_content.add_output(formatted_result.as_code(), options.into()); } } - - insta::with_settings!({ - prepend_module_to_snapshot => false, - snapshot_path => spec_input_file.parent().unwrap(), - }, { - insta::assert_snapshot!(file_name, snapshot_content.snap_content(), file_name); - }); } + + insta::with_settings!({ + prepend_module_to_snapshot => false, + snapshot_path => spec_input_file.parent().unwrap(), + }, { + insta::assert_snapshot!(file_name, snapshot_content.snap_content(), file_name); + }); } } diff --git a/crates/rome_formatter/tests/spec_tests.rs b/crates/rome_formatter/tests/spec_tests.rs index 588ffca6d12..0823605eb00 100644 --- a/crates/rome_formatter/tests/spec_tests.rs +++ b/crates/rome_formatter/tests/spec_tests.rs @@ -3,16 +3,12 @@ mod spec_test; mod formatter { mod js_module { - #[cfg(feature = "test")] use crate::spec_test; - #[cfg(feature = "test")] - tests_macros::gen_tests! {"tests/specs/js/module/**/**/**/*.js", spec_test::test_formatter::run, "module"} + tests_macros::gen_tests! {"tests/specs/js/module/**/**/**/*.js", spec_test::run, "module"} } mod js_script { - #[cfg(feature = "test")] use crate::spec_test; - #[cfg(feature = "test")] - tests_macros::gen_tests! {"tests/specs/js/script/**/**/**/*.js", spec_test::test_formatter::run, "script"} + tests_macros::gen_tests! {"tests/specs/js/script/**/**/**/*.js", spec_test::run, "script"} } } From 82d6fd48be6deb71c33a258d88f076b294eb90b7 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 4 Feb 2022 15:56:42 +0000 Subject: [PATCH 05/10] rebase --- .../tests/specs/js/module/function/function.js.snap | 11 ++++++++--- .../tests/specs/js/module/statement/for_of.js.snap | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/rome_formatter/tests/specs/js/module/function/function.js.snap b/crates/rome_formatter/tests/specs/js/module/function/function.js.snap index 33f19fe337c..2322fae1e89 100644 --- a/crates/rome_formatter/tests/specs/js/module/function/function.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/function/function.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 159 expression: function.js --- @@ -38,8 +38,13 @@ function directives() { "use strict"; } ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 +----- function foo() {} async function foo(a) { await x; diff --git a/crates/rome_formatter/tests/specs/js/module/statement/for_of.js.snap b/crates/rome_formatter/tests/specs/js/module/statement/for_of.js.snap index 52dedab2d6f..d8765ba261f 100644 --- a/crates/rome_formatter/tests/specs/js/module/statement/for_of.js.snap +++ b/crates/rome_formatter/tests/specs/js/module/statement/for_of.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_formatter/tests/spec_test.rs -assertion_line: 57 +assertion_line: 159 expression: for_of.js --- @@ -14,8 +14,13 @@ for (const aVeryLongVariableNameToEnforceLineBreaksaVeryLongVariableNameToEnforc for await ( const a of b ) {} ---- -# Output +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 +----- for (a of b) {} for (let a of b) {} From 293ebbca660c842ad9dc3dff19300d6a68f37f6b Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 4 Feb 2022 17:13:11 +0000 Subject: [PATCH 06/10] use remote derive from serde --- CONTRIBUTING.md | 15 ++---- crates/rome_formatter/tests/spec_test.rs | 46 +++++++------------ .../import_meta_expression/options.json | 8 +--- 3 files changed, 24 insertions(+), 45 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 746f6677da9..25f0a39a534 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -239,15 +239,10 @@ the cases you need to verify. If we needed to follow the previous example: 3. The content would be something like: ```json { - "cases": [ - { - "line_width": 120, - "indent_style": {"Space": 4} - } - ] + "line_width": 120, + "indent_style": {"Space": 4} } ```` -4. the `cases` keyword is mandatory; -5. then each object of the array will contain the matrix of options you'd want to test. -In this case the test suite will run a **second test case** with `line_width` to 120 and `ident_style` with 4 spaces -6. when the test suite is run, you will have two outputs in your snapshot: the default one and the custom one \ No newline at end of file +4. The file will contain the options to pass the formatter. +In this case, the test suite will run a **second test case** with `line_width` to 120 and `ident_style` with 4 spaces +5. when the test suite is run, you will have two outputs in your snapshot: the default one and the custom one \ No newline at end of file diff --git a/crates/rome_formatter/tests/spec_test.rs b/crates/rome_formatter/tests/spec_test.rs index 7d46f49e607..0180908f294 100644 --- a/crates/rome_formatter/tests/spec_test.rs +++ b/crates/rome_formatter/tests/spec_test.rs @@ -8,6 +8,7 @@ use std::fs; use std::path::{Path, PathBuf}; #[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] +#[serde(remote = "IndentStyle")] pub enum SerializableIndentStyle { /// Tab Tab, @@ -15,40 +16,26 @@ pub enum SerializableIndentStyle { Space(u8), } -impl From for IndentStyle { - fn from(test: SerializableIndentStyle) -> Self { - match test { - SerializableIndentStyle::Tab => IndentStyle::Tab, - SerializableIndentStyle::Space(s) => IndentStyle::Space(s), - } - } -} - -#[derive(Debug, Deserialize, Serialize, Clone)] +#[derive(Debug, Deserialize, Serialize, Clone, Copy)] +#[serde(remote = "FormatOptions")] pub struct SerializableFormatOptions { /// The indent style - pub indent_style: Option, + #[serde(with = "SerializableIndentStyle")] + pub indent_style: IndentStyle, /// What's the max width of a line. Defaults to 80 - pub line_width: Option, + pub line_width: u16, } impl From for FormatOptions { fn from(test: SerializableFormatOptions) -> Self { Self { - indent_style: test - .indent_style - .map_or_else(|| IndentStyle::Tab, |value| value.into()), - line_width: test.line_width.unwrap_or(80), + indent_style: test.indent_style, + line_width: test.line_width, } } } -#[derive(Debug, Deserialize, Serialize)] -pub struct TestOptions { - cases: Vec, -} - #[derive(Debug, Default)] struct SnapshotContent { input: String, @@ -141,14 +128,15 @@ pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, fi { let mut options_path = RomePath::new(options_path.display().to_string().as_str()); // SAFETY: we checked its existence already, we assume we have rights to read it - let options: TestOptions = - serde_json::from_str(options_path.get_buffer_from_file().as_str()).unwrap(); - - for test_case in options.cases { - let options = test_case.clone(); - let formatted_result = format(test_case.into(), &root).unwrap(); - snapshot_content.add_output(formatted_result.as_code(), options.into()); - } + let input = options_path.get_buffer_from_file(); + let mut de = serde_json::Deserializer::from_str(input.as_str()); + + let options: FormatOptions = + SerializableFormatOptions::deserialize(&mut de).unwrap(); + + let copy_options = options; + let formatted_result = format(options, &root).unwrap(); + snapshot_content.add_output(formatted_result.as_code(), copy_options); } } diff --git a/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json index 7df0ee8ca0c..8ab62d6dc66 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json +++ b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json @@ -1,8 +1,4 @@ { - "cases": [ - { - "line_width": 120, - "indent_style": {"Space": 4} - } - ] + "line_width": 120, + "indent_style": {"Space": 4} } \ No newline at end of file From e07d4183d5484a7b77e68d5dcd46d8a607edf287 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 7 Feb 2022 08:44:47 +0000 Subject: [PATCH 07/10] use conversation to support multiple cases --- CONTRIBUTING.md | 15 ++++-- crates/rome_formatter/tests/spec_test.rs | 52 ++++++++++++------- .../import_meta_expression/options.json | 8 ++- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 25f0a39a534..633a83dfd74 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -239,10 +239,15 @@ the cases you need to verify. If we needed to follow the previous example: 3. The content would be something like: ```json { - "line_width": 120, - "indent_style": {"Space": 4} + "cases": [ + { + "line_width": 120, + "indent_style": {"Space": 4} + } + ] } ```` -4. The file will contain the options to pass the formatter. -In this case, the test suite will run a **second test case** with `line_width` to 120 and `ident_style` with 4 spaces -5. when the test suite is run, you will have two outputs in your snapshot: the default one and the custom one \ No newline at end of file +4. the `cases` keyword is mandatory; +5. then each object of the array will contain the matrix of options you'd want to test. + In this case the test suite will run a **second test case** with `line_width` to 120 and `ident_style` with 4 spaces +6. when the test suite is run, you will have two outputs in your snapshot: the default one and the custom one \ No newline at end of file diff --git a/crates/rome_formatter/tests/spec_test.rs b/crates/rome_formatter/tests/spec_test.rs index 0180908f294..962ea39aa60 100644 --- a/crates/rome_formatter/tests/spec_test.rs +++ b/crates/rome_formatter/tests/spec_test.rs @@ -8,7 +8,6 @@ use std::fs; use std::path::{Path, PathBuf}; #[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] -#[serde(remote = "IndentStyle")] pub enum SerializableIndentStyle { /// Tab Tab, @@ -16,26 +15,40 @@ pub enum SerializableIndentStyle { Space(u8), } +impl From for IndentStyle { + fn from(test: SerializableIndentStyle) -> Self { + match test { + SerializableIndentStyle::Tab => IndentStyle::Tab, + SerializableIndentStyle::Space(spaces) => IndentStyle::Space(spaces), + } + } +} + #[derive(Debug, Deserialize, Serialize, Clone, Copy)] -#[serde(remote = "FormatOptions")] pub struct SerializableFormatOptions { /// The indent style - #[serde(with = "SerializableIndentStyle")] - pub indent_style: IndentStyle, + pub indent_style: Option, /// What's the max width of a line. Defaults to 80 - pub line_width: u16, + pub line_width: Option, } impl From for FormatOptions { fn from(test: SerializableFormatOptions) -> Self { Self { - indent_style: test.indent_style, - line_width: test.line_width, + indent_style: test + .indent_style + .map_or_else(|| IndentStyle::Tab, |value| value.into()), + line_width: test.line_width.unwrap_or(80), } } } +#[derive(Debug, Deserialize, Serialize)] +struct TestOptions { + cases: Vec, +} + #[derive(Debug, Default)] struct SnapshotContent { input: String, @@ -43,12 +56,12 @@ struct SnapshotContent { } impl SnapshotContent { - pub fn add_output(&mut self, content: &str, options: FormatOptions) { - self.output.push((String::from(content), options)) + pub fn add_output(&mut self, content: impl Into, options: FormatOptions) { + self.output.push((content.into(), options)) } - pub fn set_input(&mut self, content: &str) { - self.input = String::from(content); + pub fn set_input(&mut self, content: impl Into) { + self.input = content.into(); } pub fn snap_content(&mut self) -> String { @@ -128,15 +141,14 @@ pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, fi { let mut options_path = RomePath::new(options_path.display().to_string().as_str()); // SAFETY: we checked its existence already, we assume we have rights to read it - let input = options_path.get_buffer_from_file(); - let mut de = serde_json::Deserializer::from_str(input.as_str()); - - let options: FormatOptions = - SerializableFormatOptions::deserialize(&mut de).unwrap(); - - let copy_options = options; - let formatted_result = format(options, &root).unwrap(); - snapshot_content.add_output(formatted_result.as_code(), copy_options); + let options: TestOptions = + serde_json::from_str(options_path.get_buffer_from_file().as_str()).unwrap(); + + for test_case in options.cases { + let options = test_case.clone(); + let formatted_result = format(test_case.into(), &root).unwrap(); + snapshot_content.add_output(formatted_result.as_code(), options.into()); + } } } diff --git a/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json index 8ab62d6dc66..7df0ee8ca0c 100644 --- a/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json +++ b/crates/rome_formatter/tests/specs/js/module/expression/import_meta_expression/options.json @@ -1,4 +1,8 @@ { - "line_width": 120, - "indent_style": {"Space": 4} + "cases": [ + { + "line_width": 120, + "indent_style": {"Space": 4} + } + ] } \ No newline at end of file From 0a575484cb730ddd3ab699114bddd2a70a13d75d Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 7 Feb 2022 09:56:07 +0000 Subject: [PATCH 08/10] clippy --- crates/rome_formatter/tests/spec_test.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rome_formatter/tests/spec_test.rs b/crates/rome_formatter/tests/spec_test.rs index 962ea39aa60..a289e6c0ea9 100644 --- a/crates/rome_formatter/tests/spec_test.rs +++ b/crates/rome_formatter/tests/spec_test.rs @@ -145,9 +145,9 @@ pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, fi serde_json::from_str(options_path.get_buffer_from_file().as_str()).unwrap(); for test_case in options.cases { - let options = test_case.clone(); - let formatted_result = format(test_case.into(), &root).unwrap(); - snapshot_content.add_output(formatted_result.as_code(), options.into()); + let format_options: FormatOptions = test_case.into(); + let formatted_result = format(format_options, &root).unwrap(); + snapshot_content.add_output(formatted_result.as_code(), format_options); } } } From a36293346951502b9feeab2dd29bee53f66df499 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 8 Feb 2022 11:30:51 +0000 Subject: [PATCH 09/10] fix: merge --- Cargo.lock | 2 ++ crates/rome_formatter/tests/prettier_tests.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 0d2b6d89df3..8351c87808f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1266,6 +1266,8 @@ dependencies = [ "rome_rowan", "rslint_errors", "rslint_parser", + "serde", + "serde_json", "similar", "tests_macros", "thiserror", diff --git a/crates/rome_formatter/tests/prettier_tests.rs b/crates/rome_formatter/tests/prettier_tests.rs index da56d4a3c71..2f07f5cff33 100644 --- a/crates/rome_formatter/tests/prettier_tests.rs +++ b/crates/rome_formatter/tests/prettier_tests.rs @@ -18,7 +18,7 @@ static REPORTER: DiffReport = DiffReport::new(); tests_macros::gen_tests! {"tests/specs/prettier/**/*.js", test_snapshot, "script"} -fn test_snapshot(input: &'static str, _: &str, _: &str) { +fn test_snapshot(input: &'static str, _: &str, _: &str, _: &str) { if input.contains("typescript") || input.contains("jsx") || input.contains("flow") From 59945e478986ec734d2a5d65e16d4a4317e093dc Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 9 Feb 2022 08:46:43 +0000 Subject: [PATCH 10/10] chore: code review --- crates/rome_formatter/tests/spec_tests.rs | 4 ++-- crates/tests_macros/src/lib.rs | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/crates/rome_formatter/tests/spec_tests.rs b/crates/rome_formatter/tests/spec_tests.rs index 0823605eb00..7f75907a624 100644 --- a/crates/rome_formatter/tests/spec_tests.rs +++ b/crates/rome_formatter/tests/spec_tests.rs @@ -4,11 +4,11 @@ mod formatter { mod js_module { use crate::spec_test; - tests_macros::gen_tests! {"tests/specs/js/module/**/**/**/*.js", spec_test::run, "module"} + tests_macros::gen_tests! {"tests/specs/js/module/**/*.js", spec_test::run, "module"} } mod js_script { use crate::spec_test; - tests_macros::gen_tests! {"tests/specs/js/script/**/**/**/*.js", spec_test::run, "script"} + tests_macros::gen_tests! {"tests/specs/js/script/**/*.js", spec_test::run, "script"} } } diff --git a/crates/tests_macros/src/lib.rs b/crates/tests_macros/src/lib.rs index 33bde00a637..19f1e46b818 100644 --- a/crates/tests_macros/src/lib.rs +++ b/crates/tests_macros/src/lib.rs @@ -75,10 +75,7 @@ impl Arguments { let file_stem = path.file_stem()?; let file_stem = file_stem.to_str()?; let test_name = file_stem.to_snake(); - let mut ancestors = path.ancestors(); - // the first one will yield the path to the current file - ancestors.next(); - let test_directory = ancestors.next().unwrap().display().to_string(); + let test_directory = path.parent().unwrap().display().to_string(); let test_full_path = path.display().to_string(); let extension = match path.extension() {