From 5b6740c98784b9ecb64842e8053923d1eeb491be Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 29 Aug 2022 16:57:57 +0200 Subject: [PATCH] feat(rome_js_formatter): Indent Doc comments This PR adds support for indenting js doc comments. ```javascript /* * a comment */ ``` Becomes ```javascript /* * a comment * ``` The PR introduces a new `LeadingCommentRule` type on the `CstFormatContext` that is used to format any leading comment. This allows languages to implement formatting of a comment's content, something that wasn't possible before. ## Tests **Average compatibility**: 83.70 -> 84.04
Definition $$average = \frac\{\sum_{file}^\{files}compatibility_\{file}}\{files}$$
**Compatible lines**: 80.79 -> 81.22 --- crates/rome_formatter/src/lib.rs | 3 + crates/rome_formatter/src/token.rs | 10 +- crates/rome_js_formatter/src/comments.rs | 134 ++++++++++++++++++ crates/rome_js_formatter/src/context.rs | 56 +------- crates/rome_js_formatter/src/lib.rs | 4 +- .../src/utils/binary_like_expression.rs | 2 +- .../comment-in-the-middle.js.snap | 64 --------- .../binary-expressions-parens.js.snap | 53 ------- .../specs/prettier/js/comments/jsx.js.snap | 18 +-- .../multi-comments-on-same-line.js.snap | 64 ++------- .../js/comments/single-star-jsdoc.js.snap | 77 +++------- .../js/comments/trailing-jsdocs.js.snap | 78 +++++----- .../js/empty-paren-comment/class.js.snap | 46 ------ .../test-declarations/angular_async.js.snap | 22 +-- .../angular_fakeAsync.js.snap | 22 +-- .../angular_waitForAsync.js.snap | 22 +-- .../angularjs_inject.js.snap | 22 +-- .../comments/abstract_class.ts.snap | 53 ------- .../typescript/comments/methods.ts.snap | 110 +++----------- 19 files changed, 267 insertions(+), 593 deletions(-) create mode 100644 crates/rome_js_formatter/src/comments.rs delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/comment-in-the-middle.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/comments/binary-expressions-parens.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/class.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/comments/abstract_class.ts.snap diff --git a/crates/rome_formatter/src/lib.rs b/crates/rome_formatter/src/lib.rs index 6b79acfa71cc..e2ee88d0b461 100644 --- a/crates/rome_formatter/src/lib.rs +++ b/crates/rome_formatter/src/lib.rs @@ -237,6 +237,9 @@ pub trait CstFormatContext: FormatContext { type Language: Language; type Style: CommentStyle; + /// Rule for formatting leading comments. + type LeadingCommentRule: FormatRule, Context = Self> + Default; + /// Customizes how comments are formatted #[deprecated(note = "Prefer FormatLanguage::comment_style")] fn comment_style(&self) -> Self::Style; diff --git a/crates/rome_formatter/src/token.rs b/crates/rome_formatter/src/token.rs index c4be014663e8..52149c994d96 100644 --- a/crates/rome_formatter/src/token.rs +++ b/crates/rome_formatter/src/token.rs @@ -1,8 +1,8 @@ use crate::comments::CommentStyle; use crate::prelude::*; use crate::{ - format_args, write, Argument, Arguments, CommentKind, CstFormatContext, GroupId, LastTokenKind, - SourceComment, + format_args, write, Argument, Arguments, CommentKind, CstFormatContext, FormatRefWithRule, + GroupId, LastTokenKind, SourceComment, }; use rome_rowan::{Language, SyntaxToken, SyntaxTriviaPiece}; @@ -682,6 +682,7 @@ where .context() .comment_style() .get_comment_kind(comment.piece()); + last_inline_comment = comment_kind.is_inline() && lines_after == 0; let format_content = format_with(|f| { @@ -691,7 +692,10 @@ where write!(f, [space()])?; }; - write!(f, [comment.piece()])?; + let format_comment = + FormatRefWithRule::new(comment, C::LeadingCommentRule::default()); + + write!(f, [format_comment])?; match comment_kind { CommentKind::Line => match lines_after { diff --git a/crates/rome_js_formatter/src/comments.rs b/crates/rome_js_formatter/src/comments.rs new file mode 100644 index 000000000000..67c188e067b8 --- /dev/null +++ b/crates/rome_js_formatter/src/comments.rs @@ -0,0 +1,134 @@ +use crate::prelude::*; +use rome_formatter::{format_args, write}; +use rome_formatter::{CommentKind, CommentStyle, SourceComment}; +use rome_js_syntax::suppression::{parse_suppression_comment, SuppressionCategory}; +use rome_js_syntax::{JsLanguage, JsSyntaxKind}; +use rome_rowan::{SyntaxTriviaPieceComments, TextLen}; + +#[derive(Default)] +pub struct FormatJsLeadingComment; + +impl FormatRule> for FormatJsLeadingComment { + type Context = JsFormatContext; + + fn fmt( + &self, + comment: &SourceComment, + f: &mut Formatter, + ) -> FormatResult<()> { + if is_doc_comment(comment.piece()) { + let mut source_offset = comment.piece().text_range().start(); + + for (index, line) in comment.piece().text().lines().enumerate() { + if index == 0 { + write!(f, [dynamic_text(line.trim_end(), source_offset)])?; + } else { + write!( + f, + [align( + 1, + &format_args![ + hard_line_break(), + dynamic_text(line.trim(), source_offset) + ] + )] + )?; + } + source_offset += line.text_len(); + } + + Ok(()) + } else { + write!(f, [comment.piece()]) + } + } +} + +/// Returns `true` if `comment` is a multi line block comment: +/// +/// # Examples +/// +/// ## Doc Comments +/// +/// ```javascript +/// /** +/// * Multiline doc comment +/// */ +/// +/// /* +/// * With single star +/// */ +/// ``` +/// +/// ## Non Doc Comments +/// +/// ```javascript +/// /** has no line break */ +/// +/// /* +/// * +/// this line doesn't start with a star +/// */ +/// ``` +/// +fn is_doc_comment(comment: &SyntaxTriviaPieceComments) -> bool { + if !comment.has_newline() { + return false; + } + + let text = comment.text(); + + text.lines().enumerate().all(|(index, line)| { + if index == 0 { + line.starts_with("/*") + } else { + line.trim_start().starts_with('*') + } + }) +} + +#[derive(Eq, PartialEq, Copy, Clone, Debug, Default)] +pub struct JsCommentStyle; + +impl CommentStyle for JsCommentStyle { + fn is_suppression(&self, text: &str) -> bool { + parse_suppression_comment(text) + .flat_map(|suppression| suppression.categories) + .any(|(category, _)| category == SuppressionCategory::Format) + } + + fn get_comment_kind(&self, comment: &SyntaxTriviaPieceComments) -> CommentKind { + if comment.text().starts_with("/*") { + if comment.has_newline() { + CommentKind::Block + } else { + CommentKind::InlineBlock + } + } else { + CommentKind::Line + } + } + + fn is_group_start_token(&self, kind: JsSyntaxKind) -> bool { + matches!( + kind, + JsSyntaxKind::L_PAREN + | JsSyntaxKind::L_BRACK + | JsSyntaxKind::L_CURLY + | JsSyntaxKind::DOLLAR_CURLY + ) + } + + fn is_group_end_token(&self, kind: JsSyntaxKind) -> bool { + matches!( + kind, + JsSyntaxKind::R_BRACK + | JsSyntaxKind::R_CURLY + | JsSyntaxKind::R_PAREN + | JsSyntaxKind::COMMA + | JsSyntaxKind::SEMICOLON + | JsSyntaxKind::DOT + | JsSyntaxKind::EOF + ) + } +} diff --git a/crates/rome_js_formatter/src/context.rs b/crates/rome_js_formatter/src/context.rs index 5b2234d0bd6c..93f4dd117245 100644 --- a/crates/rome_js_formatter/src/context.rs +++ b/crates/rome_js_formatter/src/context.rs @@ -1,11 +1,10 @@ +use crate::comments::{FormatJsLeadingComment, JsCommentStyle}; use rome_formatter::printer::PrinterOptions; use rome_formatter::{ - CommentKind, CommentStyle, Comments, CstFormatContext, FormatContext, FormatOptions, - IndentStyle, LineWidth, TransformSourceMap, + Comments, CstFormatContext, FormatContext, FormatOptions, IndentStyle, LineWidth, + TransformSourceMap, }; -use rome_js_syntax::suppression::{parse_suppression_comment, SuppressionCategory}; -use rome_js_syntax::{JsLanguage, JsSyntaxKind, SourceType}; -use rome_rowan::SyntaxTriviaPieceComments; +use rome_js_syntax::{JsLanguage, SourceType}; use std::fmt; use std::fmt::Debug; use std::rc::Rc; @@ -66,6 +65,7 @@ impl FormatContext for JsFormatContext { impl CstFormatContext for JsFormatContext { type Language = JsLanguage; type Style = JsCommentStyle; + type LeadingCommentRule = FormatJsLeadingComment; fn comment_style(&self) -> Self::Style { JsCommentStyle @@ -172,52 +172,6 @@ impl fmt::Display for JsFormatOptions { } } -#[derive(Eq, PartialEq, Copy, Clone, Debug, Default)] -pub struct JsCommentStyle; - -impl CommentStyle for JsCommentStyle { - fn is_suppression(&self, text: &str) -> bool { - parse_suppression_comment(text) - .flat_map(|suppression| suppression.categories) - .any(|(category, _)| category == SuppressionCategory::Format) - } - - fn get_comment_kind(&self, comment: &SyntaxTriviaPieceComments) -> CommentKind { - if comment.text().starts_with("/*") { - if comment.has_newline() { - CommentKind::Block - } else { - CommentKind::InlineBlock - } - } else { - CommentKind::Line - } - } - - fn is_group_start_token(&self, kind: JsSyntaxKind) -> bool { - matches!( - kind, - JsSyntaxKind::L_PAREN - | JsSyntaxKind::L_BRACK - | JsSyntaxKind::L_CURLY - | JsSyntaxKind::DOLLAR_CURLY - ) - } - - fn is_group_end_token(&self, kind: JsSyntaxKind) -> bool { - matches!( - kind, - JsSyntaxKind::R_BRACK - | JsSyntaxKind::R_CURLY - | JsSyntaxKind::R_PAREN - | JsSyntaxKind::COMMA - | JsSyntaxKind::SEMICOLON - | JsSyntaxKind::DOT - | JsSyntaxKind::EOF - ) - } -} - #[derive(Debug, Eq, PartialEq, Clone, Copy)] #[cfg_attr( feature = "serde", diff --git a/crates/rome_js_formatter/src/lib.rs b/crates/rome_js_formatter/src/lib.rs index 2f877af77b4d..c0e287ea6822 100644 --- a/crates/rome_js_formatter/src/lib.rs +++ b/crates/rome_js_formatter/src/lib.rs @@ -253,6 +253,7 @@ mod check_reformat; #[rustfmt::skip] mod generated; pub(crate) mod builders; +mod comments; pub mod context; mod parentheses; pub(crate) mod separated; @@ -271,7 +272,8 @@ use rome_rowan::TextRange; use rome_rowan::{AstNode, SyntaxNode}; use crate::builders::{format_parenthesize, format_suppressed_node}; -use crate::context::{JsCommentStyle, JsFormatContext, JsFormatOptions}; +use crate::comments::JsCommentStyle; +use crate::context::{JsFormatContext, JsFormatOptions}; use crate::cst::FormatJsSyntaxNode; use crate::syntax_rewriter::transform; use std::iter::FusedIterator; diff --git a/crates/rome_js_formatter/src/utils/binary_like_expression.rs b/crates/rome_js_formatter/src/utils/binary_like_expression.rs index a732fa15dd56..da1b683e3453 100644 --- a/crates/rome_js_formatter/src/utils/binary_like_expression.rs +++ b/crates/rome_js_formatter/src/utils/binary_like_expression.rs @@ -66,7 +66,7 @@ use crate::parentheses::{ is_arrow_function_body, is_callee, is_member_object, is_spread, is_tag, NeedsParentheses, }; -use crate::context::JsCommentStyle; +use crate::comments::JsCommentStyle; use crate::js::expressions::static_member_expression::JsAnyStaticMemberLike; use crate::utils::assignment_like::has_leading_own_line_comment; use rome_rowan::{declare_node_union, AstNode, SyntaxResult}; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/comment-in-the-middle.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/comment-in-the-middle.js.snap deleted file mode 100644 index 9d5e8c2aae19..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/comment-in-the-middle.js.snap +++ /dev/null @@ -1,64 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -var a = -/** - * bla bla bla - * @type {string | - * number - * } -* bla bla bla - */ -//2 - ((window['s'])).toString(); -console.log(a.foo()); -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,11 +1,11 @@ - var a = - /** -- * bla bla bla -- * @type {string | -- * number -- * } -- * bla bla bla -- */ -+ * bla bla bla -+ * @type {string | -+ * number -+ * } -+* bla bla bla -+ */ - //2 - (window["s"]).toString(); - console.log(a.foo()); -``` - -# Output - -```js -var a = - /** - * bla bla bla - * @type {string | - * number - * } -* bla bla bla - */ - //2 - (window["s"]).toString(); -console.log(a.foo()); -``` - - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/binary-expressions-parens.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/binary-expressions-parens.js.snap deleted file mode 100644 index 5eb92b14cc61..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/binary-expressions-parens.js.snap +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -Math.min( - ( - /* $FlowFixMe(>=0.38.0 site=www) - Flow error detected during the - * deployment of v0.38.0. To see the error, remove this comment and - * run flow */ - document.body.scrollHeight - - (window.scrollY + window.innerHeight) - ) - devsite_footer_height, - 0, -) -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,7 +1,7 @@ - Math.min( - /* $FlowFixMe(>=0.38.0 site=www) - Flow error detected during the -- * deployment of v0.38.0. To see the error, remove this comment and -- * run flow */ -+ * deployment of v0.38.0. To see the error, remove this comment and -+ * run flow */ - document.body.scrollHeight - - (window.scrollY + window.innerHeight) - - devsite_footer_height, -``` - -# Output - -```js -Math.min( - /* $FlowFixMe(>=0.38.0 site=www) - Flow error detected during the - * deployment of v0.38.0. To see the error, remove this comment and - * run flow */ - document.body.scrollHeight - - (window.scrollY + window.innerHeight) - - devsite_footer_height, - 0, -); -``` - - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.snap index 6e5f1b7db0c4..1525ff06e4d7 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/jsx.js.snap @@ -208,7 +208,7 @@ onClick={() => {}}> } ; -@@ -62,19 +60,21 @@ +@@ -62,13 +60,15 @@
{/** * JSDoc-y comment in JSX. I wonder what will happen to it? @@ -222,19 +222,11 @@ onClick={() => {}}> + /** * Another JSDoc comment in JSX. - */} -+ */ ++ */ + }
;
{}} - >
; - @@ -90,20 +90,15 @@ {foo} ; @@ -334,14 +326,14 @@ onClick={() => {}}> { /** * Another JSDoc comment in JSX. - */ + */ } ;
{}} >
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.snap index 67ea71b502dd..04de32a96c78 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/multi-comments-on-same-line.js.snap @@ -102,12 +102,7 @@ a;/* ```diff --- Prettier +++ Rome -@@ -12,19 +12,18 @@ - a; - /* - 1*/ /*2*/ /*3 -- */ -+*/ +@@ -16,15 +16,14 @@ b; a; /* @@ -128,49 +123,6 @@ a;/* /*========= First two on same line =========*/ a; -@@ -44,19 +43,19 @@ - /* - 1*/ /*2*/ - /*3 -- */ -+*/ - b; - - a; /* - 1*/ /*2*/ - /*3 -- */ -+*/ - b; - - a; /* - 1*/ /*2*/ - /*3 -- */ b; -+*/ b; - - /*========= Last two on same line =========*/ - a; -@@ -76,16 +75,16 @@ - /* - 1*/ - /*2*/ /*3 -- */ -+*/ - b; - - a; /* - 1*/ - /*2*/ /*3 -- */ -+*/ - b; - - a; /* - 1*/ - /*2*/ /*3 -- */ b; -+*/ b; ``` # Output @@ -190,7 +142,7 @@ a; a; /* 1*/ /*2*/ /*3 -*/ + */ b; a; /* @@ -221,19 +173,19 @@ a; /* 1*/ /*2*/ /*3 -*/ + */ b; a; /* 1*/ /*2*/ /*3 -*/ + */ b; a; /* 1*/ /*2*/ /*3 -*/ b; + */ b; /*========= Last two on same line =========*/ a; @@ -253,19 +205,19 @@ a; /* 1*/ /*2*/ /*3 -*/ + */ b; a; /* 1*/ /*2*/ /*3 -*/ + */ b; a; /* 1*/ /*2*/ /*3 -*/ b; + */ b; ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/single-star-jsdoc.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/single-star-jsdoc.js.snap index 511fab0c6446..480a21d665c3 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/single-star-jsdoc.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/single-star-jsdoc.js.snap @@ -43,49 +43,14 @@ if(true) { ```diff --- Prettier +++ Rome -@@ -4,27 +4,26 @@ - - if (true) { - /* -- * Oh no -- */ -+ * Oh no -+ */ +@@ -7,7 +7,6 @@ + * Oh no + */ } - /** first line -- * second line -- * third line */ -+* second line -+ * third line */ - - /* first line -- * second line -- * third line */ -+* second line -+ * third line */ - - /*! first line -- *second line -- * third line */ -+*second line -+ * third line */ - - /*! -- * Extracted from vue codebase -- * https://github.com/vuejs/vue/blob/cfd73c2386623341fdbb3ac636c4baf84ea89c2c/src/compiler/parser/html-parser.js -- * HTML Parser By John Resig (ejohn.org) -- * Modified by Juriy "kangax" Zaytsev -- * Original code by Erik Arvidsson, Mozilla Public License -- * http://erik.eae.net/simplehtmlparser/simplehtmlparser.js -- */ -+* Extracted from vue codebase -+* https://github.com/vuejs/vue/blob/cfd73c2386623341fdbb3ac636c4baf84ea89c2c/src/compiler/parser/html-parser.js -+* HTML Parser By John Resig (ejohn.org) -+* Modified by Juriy "kangax" Zaytsev -+* Original code by Erik Arvidsson, Mozilla Public License -+* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js -+*/ + * second line + * third line */ ``` # Output @@ -97,34 +62,34 @@ if(true) { if (true) { /* - * Oh no - */ + * Oh no + */ } /** first line -* second line - * third line */ + * second line + * third line */ /* first line -* second line - * third line */ + * second line + * third line */ /*! first line -*second line - * third line */ + *second line + * third line */ /*! -* Extracted from vue codebase -* https://github.com/vuejs/vue/blob/cfd73c2386623341fdbb3ac636c4baf84ea89c2c/src/compiler/parser/html-parser.js -* HTML Parser By John Resig (ejohn.org) -* Modified by Juriy "kangax" Zaytsev -* Original code by Erik Arvidsson, Mozilla Public License -* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js -*/ + * Extracted from vue codebase + * https://github.com/vuejs/vue/blob/cfd73c2386623341fdbb3ac636c4baf84ea89c2c/src/compiler/parser/html-parser.js + * HTML Parser By John Resig (ejohn.org) + * Modified by Juriy "kangax" Zaytsev + * Original code by Erik Arvidsson, Mozilla Public License + * http://erik.eae.net/simplehtmlparser/simplehtmlparser.js + */ ``` # Lines exceeding max width of 80 characters ``` - 24: * https://github.com/vuejs/vue/blob/cfd73c2386623341fdbb3ac636c4baf84ea89c2c/src/compiler/parser/html-parser.js + 24: * https://github.com/vuejs/vue/blob/cfd73c2386623341fdbb3ac636c4baf84ea89c2c/src/compiler/parser/html-parser.js ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.snap index 1fbf2ca99b0a..9a97acc9e76a 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/trailing-jsdocs.js.snap @@ -35,47 +35,35 @@ const CONNECTION_STATUS = exports.CONNECTION_STATUS = { ```diff --- Prettier +++ Rome -@@ -4,24 +4,19 @@ +@@ -4,12 +4,9 @@ CONNECTING: Object.freeze({ kind: "CONNECTING" }), NOT_CONNECTED: Object.freeze({ kind: "NOT_CONNECTED" }), }); - -/* A comment */ -/** -- * A type that can be written to a buffer. ++/* A comment */ /** + * A type that can be written to a buffer. - */ -/** -- * Describes the connection status of a ReactiveSocket/DuplexConnection. -- * - NOT_CONNECTED: no connection established or pending. -- * - CONNECTING: when `connect()` has been called but a connection is not yet -- * established. -- * - CONNECTED: when a connection is established. -- * - CLOSED: when the connection has been explicitly closed via `close()`. -- * - ERROR: when the connection has been closed for any other reason. ++ */ /** + * Describes the connection status of a ReactiveSocket/DuplexConnection. + * - NOT_CONNECTED: no connection established or pending. + * - CONNECTING: when `connect()` has been called but a connection is not yet +@@ -17,11 +14,9 @@ + * - CONNECTED: when a connection is established. + * - CLOSED: when the connection has been explicitly closed via `close()`. + * - ERROR: when the connection has been closed for any other reason. - */ -/** -- * A contract providing different interaction models per the [ReactiveSocket protocol] -- * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). ++ */ /** + * A contract providing different interaction models per the [ReactiveSocket protocol] + * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). - */ -/** -- * A single unit of data exchanged between the peers of a `ReactiveSocket`. -- */ -+/* A comment */ /** -+* A type that can be written to a buffer. -+*/ /** -+* Describes the connection status of a ReactiveSocket/DuplexConnection. -+* - NOT_CONNECTED: no connection established or pending. -+* - CONNECTING: when `connect()` has been called but a connection is not yet -+* established. -+* - CONNECTED: when a connection is established. -+* - CLOSED: when the connection has been explicitly closed via `close()`. -+* - ERROR: when the connection has been closed for any other reason. -+*/ /** -+* A contract providing different interaction models per the [ReactiveSocket protocol] -+* (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). -+*/ /** -+* A single unit of data exchanged between the peers of a `ReactiveSocket`. -+*/ ++ */ /** + * A single unit of data exchanged between the peers of a `ReactiveSocket`. + */ ``` # Output @@ -88,26 +76,26 @@ const CONNECTION_STATUS = (exports.CONNECTION_STATUS = { NOT_CONNECTED: Object.freeze({ kind: "NOT_CONNECTED" }), }); /* A comment */ /** -* A type that can be written to a buffer. -*/ /** -* Describes the connection status of a ReactiveSocket/DuplexConnection. -* - NOT_CONNECTED: no connection established or pending. -* - CONNECTING: when `connect()` has been called but a connection is not yet -* established. -* - CONNECTED: when a connection is established. -* - CLOSED: when the connection has been explicitly closed via `close()`. -* - ERROR: when the connection has been closed for any other reason. -*/ /** -* A contract providing different interaction models per the [ReactiveSocket protocol] -* (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). -*/ /** -* A single unit of data exchanged between the peers of a `ReactiveSocket`. -*/ + * A type that can be written to a buffer. + */ /** + * Describes the connection status of a ReactiveSocket/DuplexConnection. + * - NOT_CONNECTED: no connection established or pending. + * - CONNECTING: when `connect()` has been called but a connection is not yet + * established. + * - CONNECTED: when a connection is established. + * - CLOSED: when the connection has been explicitly closed via `close()`. + * - ERROR: when the connection has been closed for any other reason. + */ /** + * A contract providing different interaction models per the [ReactiveSocket protocol] + * (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md). + */ /** + * A single unit of data exchanged between the peers of a `ReactiveSocket`. + */ ``` # Lines exceeding max width of 80 characters ``` - 18: * A contract providing different interaction models per the [ReactiveSocket protocol] + 18: * A contract providing different interaction models per the [ReactiveSocket protocol] ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/class.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/class.js.snap deleted file mode 100644 index 1af88394015e..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/class.js.snap +++ /dev/null @@ -1,46 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -class x { - /** - * Set of default settings to be applied to model fetch calls in DAO layer. - */ - static get defaultSettings() { - } -} -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,6 +1,6 @@ - class x { - /** -- * Set of default settings to be applied to model fetch calls in DAO layer. -- */ -+ * Set of default settings to be applied to model fetch calls in DAO layer. -+ */ - static get defaultSettings() {} - } -``` - -# Output - -```js -class x { - /** - * Set of default settings to be applied to model fetch calls in DAO layer. - */ - static get defaultSettings() {} -} -``` - - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_async.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_async.js.snap index 692db4282e2c..d3534f830b75 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_async.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_async.js.snap @@ -47,7 +47,7 @@ function x() { async(() => {}) } ```diff --- Prettier +++ Rome -@@ -1,28 +1,38 @@ +@@ -1,22 +1,32 @@ -beforeEach(async(() => { - // code -})); @@ -91,17 +91,7 @@ function x() { async(() => {}) } +); /* -- * isTestCall(parent) should only be called when parent exists -- * and parent.type is CallExpression. This test makes sure that -- * no errors are thrown when calling isTestCall(parent) -- */ -+* isTestCall(parent) should only be called when parent exists -+* and parent.type is CallExpression. This test makes sure that -+* no errors are thrown when calling isTestCall(parent) -+*/ - function x() { - async(() => {}); - } + * isTestCall(parent) should only be called when parent exists ``` # Output @@ -138,10 +128,10 @@ it( ); /* -* isTestCall(parent) should only be called when parent exists -* and parent.type is CallExpression. This test makes sure that -* no errors are thrown when calling isTestCall(parent) -*/ + * isTestCall(parent) should only be called when parent exists + * and parent.type is CallExpression. This test makes sure that + * no errors are thrown when calling isTestCall(parent) + */ function x() { async(() => {}); } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_fakeAsync.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_fakeAsync.js.snap index 86c3f1f7cee4..085068a6a9e8 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_fakeAsync.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_fakeAsync.js.snap @@ -37,7 +37,7 @@ function x() { fakeAsync(() => {}) } ```diff --- Prettier +++ Rome -@@ -1,27 +1,42 @@ +@@ -1,21 +1,36 @@ -beforeEach(fakeAsync(() => { - // code -})); @@ -87,17 +87,7 @@ function x() { fakeAsync(() => {}) } +); /* -- * isTestCall(parent) should only be called when parent exists -- * and parent.type is CallExpression. This test makes sure that -- * no errors are thrown when calling isTestCall(parent) -- */ -+* isTestCall(parent) should only be called when parent exists -+* and parent.type is CallExpression. This test makes sure that -+* no errors are thrown when calling isTestCall(parent) -+*/ - function x() { - fakeAsync(() => {}); - } + * isTestCall(parent) should only be called when parent exists ``` # Output @@ -138,10 +128,10 @@ it( ); /* -* isTestCall(parent) should only be called when parent exists -* and parent.type is CallExpression. This test makes sure that -* no errors are thrown when calling isTestCall(parent) -*/ + * isTestCall(parent) should only be called when parent exists + * and parent.type is CallExpression. This test makes sure that + * no errors are thrown when calling isTestCall(parent) + */ function x() { fakeAsync(() => {}); } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_waitForAsync.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_waitForAsync.js.snap index a985a3b5e40e..7a28521b6a1d 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_waitForAsync.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_waitForAsync.js.snap @@ -37,7 +37,7 @@ function x() { waitForAsync(() => {}) } ```diff --- Prettier +++ Rome -@@ -1,27 +1,42 @@ +@@ -1,21 +1,36 @@ -beforeEach(waitForAsync(() => { - // code -})); @@ -87,17 +87,7 @@ function x() { waitForAsync(() => {}) } +); /* -- * isTestCall(parent) should only be called when parent exists -- * and parent.type is CallExpression. This test makes sure that -- * no errors are thrown when calling isTestCall(parent) -- */ -+* isTestCall(parent) should only be called when parent exists -+* and parent.type is CallExpression. This test makes sure that -+* no errors are thrown when calling isTestCall(parent) -+*/ - function x() { - waitForAsync(() => {}); - } + * isTestCall(parent) should only be called when parent exists ``` # Output @@ -138,10 +128,10 @@ it( ); /* -* isTestCall(parent) should only be called when parent exists -* and parent.type is CallExpression. This test makes sure that -* no errors are thrown when calling isTestCall(parent) -*/ + * isTestCall(parent) should only be called when parent exists + * and parent.type is CallExpression. This test makes sure that + * no errors are thrown when calling isTestCall(parent) + */ function x() { waitForAsync(() => {}); } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angularjs_inject.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angularjs_inject.js.snap index e5b6b6870b80..7ca3bdc562ca 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angularjs_inject.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angularjs_inject.js.snap @@ -39,7 +39,7 @@ function x() { inject(() => {}) } ```diff --- Prettier +++ Rome -@@ -1,31 +1,41 @@ +@@ -1,25 +1,35 @@ -beforeEach(inject(($fooService, $barService) => { - // code -})); @@ -92,17 +92,7 @@ function x() { inject(() => {}) } +); /* -- * isTestCall(parent) should only be called when parent exists -- * and parent.type is CallExpression. This test makes sure that -- * no errors are thrown when calling isTestCall(parent) -- */ -+* isTestCall(parent) should only be called when parent exists -+* and parent.type is CallExpression. This test makes sure that -+* no errors are thrown when calling isTestCall(parent) -+*/ - function x() { - inject(() => {}); - } + * isTestCall(parent) should only be called when parent exists ``` # Output @@ -142,10 +132,10 @@ it( ); /* -* isTestCall(parent) should only be called when parent exists -* and parent.type is CallExpression. This test makes sure that -* no errors are thrown when calling isTestCall(parent) -*/ + * isTestCall(parent) should only be called when parent exists + * and parent.type is CallExpression. This test makes sure that + * no errors are thrown when calling isTestCall(parent) + */ function x() { inject(() => {}); } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/abstract_class.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/abstract_class.ts.snap deleted file mode 100644 index 6eec4d3a8f26..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/abstract_class.ts.snap +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -abstract class AbstractRule { - /** - * @deprecated - * Failures will be filtered based on `tslint:disable` comments by tslint. - * This method now does nothing. - */ - filterFailures() {} -} -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,8 +1,8 @@ - abstract class AbstractRule { - /** -- * @deprecated -- * Failures will be filtered based on `tslint:disable` comments by tslint. -- * This method now does nothing. -- */ -+ * @deprecated -+ * Failures will be filtered based on `tslint:disable` comments by tslint. -+ * This method now does nothing. -+ */ - filterFailures() {} - } -``` - -# Output - -```js -abstract class AbstractRule { - /** - * @deprecated - * Failures will be filtered based on `tslint:disable` comments by tslint. - * This method now does nothing. - */ - filterFailures() {} -} -``` - - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/methods.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/methods.ts.snap index 7b20f8d9900e..198dd71b9bfc 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/methods.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/methods.ts.snap @@ -62,71 +62,7 @@ export class Point { ```diff --- Prettier +++ Rome -@@ -1,49 +1,49 @@ - export class Point { - /** -- * Does something. -- */ -+ * Does something. -+ */ - foo() {} - - /** -- * Does something else. -- */ -+ * Does something else. -+ */ - bar() {} - - /** -- * Does -- * something -- * much -- * better -- * than -- * the -- * rest. -- */ -+ * Does -+ * something -+ * much -+ * better -+ * than -+ * the -+ * rest. -+ */ - baz() {} - - /** -- * Buzz-Fizz. -- * Note: This is indented too far. -- */ -+ * Buzz-Fizz. -+ * Note: This is indented too far. -+ */ - fizzBuzz() {} - - /** -- * Turns the given string into pig-latin. -- */ -+ * Turns the given string into pig-latin. -+ */ - pigLatinize(value: string) { - /** -- * This is a block comment inside of a method. -- */ -+ * This is a block comment inside of a method. -+ */ - } - - /** -- * One -- * Two -+ * One -+ * Two - * Three -- * Four -+* Four +@@ -43,7 +43,7 @@ */ mismatchedIndentation() {} @@ -142,46 +78,46 @@ export class Point { ```js export class Point { /** - * Does something. - */ + * Does something. + */ foo() {} /** - * Does something else. - */ + * Does something else. + */ bar() {} /** - * Does - * something - * much - * better - * than - * the - * rest. - */ + * Does + * something + * much + * better + * than + * the + * rest. + */ baz() {} /** - * Buzz-Fizz. - * Note: This is indented too far. - */ + * Buzz-Fizz. + * Note: This is indented too far. + */ fizzBuzz() {} /** - * Turns the given string into pig-latin. - */ + * Turns the given string into pig-latin. + */ pigLatinize(value: string) { /** - * This is a block comment inside of a method. - */ + * This is a block comment inside of a method. + */ } /** - * One - * Two + * One + * Two * Three -* Four + * Four */ mismatchedIndentation() {}