From ca53a383f69645474f339e8db558101730bae8c6 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 23 Sep 2022 08:20:38 +0200 Subject: [PATCH] Fix codegen and node api tests --- crates/rome_formatter/src/formatter.rs | 1 + crates/rome_formatter/src/lib.rs | 2 +- npm/rome/tests/daemon/formatContent.test.mjs | 14 +++++--------- xtask/codegen/src/generate_bindings.rs | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/crates/rome_formatter/src/formatter.rs b/crates/rome_formatter/src/formatter.rs index a357e626206..ec6a8f1db3a 100644 --- a/crates/rome_formatter/src/formatter.rs +++ b/crates/rome_formatter/src/formatter.rs @@ -201,6 +201,7 @@ impl<'buf, Context> Formatter<'buf, Context> { match elements.len() { 0 => None, // Doesn't get cheaper than calling clone, use the element directly + // SAFETY: Safe because of the `len == 1` check in the match arm. 1 => Some(elements.pop().unwrap()), _ => Some(FormatElement::Interned(Interned::new(elements))), } diff --git a/crates/rome_formatter/src/lib.rs b/crates/rome_formatter/src/lib.rs index cd315fbe6c9..cccb1794d2a 100644 --- a/crates/rome_formatter/src/lib.rs +++ b/crates/rome_formatter/src/lib.rs @@ -578,7 +578,7 @@ impl std::fmt::Display for FormatError { fmt, "formatting range {input:?} is larger than syntax tree {tree:?}" ), - FormatError::InvalidDocument(error) => std::write!(fmt, "Invalid document: {error}\n\n This is an internal Rome error. Please open an issue https://github.com/rome/tools/issues."), + FormatError::InvalidDocument(error) => std::write!(fmt, "Invalid document: {error}\n\n This is an internal Rome error. Please report if necessary."), } } } diff --git a/npm/rome/tests/daemon/formatContent.test.mjs b/npm/rome/tests/daemon/formatContent.test.mjs index 1574614051d..629bbadd4cd 100644 --- a/npm/rome/tests/daemon/formatContent.test.mjs +++ b/npm/rome/tests/daemon/formatContent.test.mjs @@ -49,7 +49,7 @@ describe("Rome Deamon formatter", async () => { expect(result.content).toEqual("function f() {}\n"); expect(result.diagnostics).toEqual([]); expect(result.ir).toMatchInlineSnapshot( - '"[\\"function\\", \\" \\", \\"f\\", group([\\"(\\", \\")\\"]), \\" \\", \\"{\\", \\"}\\", hard_line_break]"', + '"[\\"function f\\", group([\\"()\\"]), \\" {}\\", hard_line_break]"', ); }); @@ -75,16 +75,12 @@ describe("Rome Deamon formatter", async () => { expect(result.ir).toMatchInlineSnapshot( ` "[ - group([\\"let\\", \\" \\", \\"a\\"]), + group([\\"let a\\"]), \\";\\", hard_line_break, - \\"function\\", - \\" \\", - \\"g\\", - group([\\"(\\", \\")\\"]), - \\" \\", - \\"{\\", - \\"}\\", + \\"function g\\", + group([\\"()\\"]), + \\" {}\\", hard_line_break ]" `, diff --git a/xtask/codegen/src/generate_bindings.rs b/xtask/codegen/src/generate_bindings.rs index 1c9dcd6790d..2d39e8e1ad0 100644 --- a/xtask/codegen/src/generate_bindings.rs +++ b/xtask/codegen/src/generate_bindings.rs @@ -396,7 +396,7 @@ pub(crate) fn generate_workspace_bindings(mode: Mode) -> Result<()> { .build(); let formatted = format_node(JsFormatOptions::new(SourceType::ts()), module.syntax()).unwrap(); - let printed = formatted.print(); + let printed = formatted.print().unwrap(); let code = printed.into_code(); update(&bindings_path, &code, &mode)?;