diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index edfc7d30c8c..d357815789e 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -120,7 +120,7 @@ jobs: - name: Build TypeScript code run: | pnpm --prefix npm/backend-jsonrpc i - pnpm --prefix npm/backend-jsonrpc run build + pnpm --prefix npm/backend-jsonrpc run build pnpm --prefix npm/rome run build:wasm-node pnpm --prefix npm/rome i pnpm --prefix npm/rome run build @@ -175,7 +175,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: codegen-schema - - name: Run the schema codegen + - name: Run the bindings codegen uses: actions-rs/cargo@v1 with: command: codegen-bindings @@ -188,4 +188,4 @@ jobs: if [[ `git status --porcelain` ]]; then git status exit 1 - fi \ No newline at end of file + fi diff --git a/crates/rome_formatter/src/lib.rs b/crates/rome_formatter/src/lib.rs index 6b79acfa71c..e2ee88d0b46 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 c4be014663e..52149c994d9 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 00000000000..711350197d5 --- /dev/null +++ b/crates/rome_js_formatter/src/comments.rs @@ -0,0 +1,160 @@ +use crate::prelude::*; +use rome_formatter::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(); + + let mut lines = comment.piece().text().lines(); + + // SAFETY: Safe, `is_doc_comment` only returns `true` for multiline comments + let first_line = lines.next().unwrap(); + write!(f, [dynamic_text(first_line.trim_end(), source_offset)])?; + + source_offset += first_line.text_len(); + + // Indent the remaining lines by one space so that all `*` are aligned. + write!( + f, + [align( + 1, + &format_once(|f| { + for line in lines { + write!( + f, + [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 +/// +/// ``` +/// # use rome_js_parser::parse_module; +/// # use rome_js_syntax::JsLanguage; +/// # use rome_rowan::{Direction, SyntaxTriviaPieceComments}; +/// use rome_js_formatter::comments::is_doc_comment; +/// +/// # fn parse_comment(source: &str) -> SyntaxTriviaPieceComments { +/// # let root = parse_module(source, 0).tree(); +/// # root +/// # .eof_token() +/// # .expect("Root to have an EOF token") +/// # .leading_trivia() +/// # .pieces() +/// # .filter_map(|piece| piece.as_comments()) +/// # .next() +/// # .expect("Source to contain a comment.") +/// # } +/// +/// assert!(is_doc_comment(&parse_comment(r#" +/// /** +/// * Multiline doc comment +/// */ +/// "#))); +/// +/// assert!(is_doc_comment(&parse_comment(r#" +/// /* +/// * Single star +/// */ +/// "#))); +/// +/// +/// // Non doc-comments +/// assert!(!is_doc_comment(&parse_comment(r#"/** has no line break */"#))); +/// +/// assert!(!is_doc_comment(&parse_comment(r#" +/// /* +/// * +/// this line doesn't start with a star +/// */ +/// "#))); +/// ``` +pub 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 5b2234d0bd6..93f4dd11724 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 2f877af77b4..f411a369032 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; +pub 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/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 9d5e8c2aae1..00000000000 --- 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 5eb92b14cc6..00000000000 --- 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 6e5f1b7db0c..1525ff06e4d 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 67ea71b502d..04de32a96c7 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 511fab0c644..480a21d665c 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 1fbf2ca99b0..9a97acc9e76 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 1af88394015..00000000000 --- 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 692db4282e2..d3534f830b7 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 86c3f1f7cee..085068a6a9e 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 a985a3b5e40..7a28521b6a1 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 e5b6b6870b8..7ca3bdc562c 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 6eec4d3a8f2..00000000000 --- 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 7b20f8d9900..198dd71b9bf 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() {} diff --git a/npm/backend-jsonrpc/src/workspace.ts b/npm/backend-jsonrpc/src/workspace.ts index bf6a83d46a4..947ae0bb422 100644 --- a/npm/backend-jsonrpc/src/workspace.ts +++ b/npm/backend-jsonrpc/src/workspace.ts @@ -13,38 +13,38 @@ export interface UpdateSettingsParams { configuration: Configuration; } /** - * The configuration that is contained inside the file `rome.json` - */ + * The configuration that is contained inside the file `rome.json` + */ export interface Configuration { /** - * The configuration of the formatter + * The configuration of the formatter */ formatter?: FormatterConfiguration; /** - * Specific configuration for the JavaScript language + * Specific configuration for the JavaScript language */ javascript?: JavascriptConfiguration; /** - * The configuration for the linter + * The configuration for the linter */ linter?: LinterConfiguration; } export interface FormatterConfiguration { enabled?: boolean; /** - * Stores whether formatting should be allowed to proceed if a given file has syntax errors + * Stores whether formatting should be allowed to proceed if a given file has syntax errors */ formatWithErrors?: boolean; /** - * The size of the indentation, 2 by default + * The size of the indentation, 2 by default */ indentSize?: number; /** - * The indent style. + * The indent style. */ indentStyle?: PlainIndentStyle; /** - * What's the max width of a line. Defaults to 80. + * What's the max width of a line. Defaults to 80. */ lineWidth?: LineWidth; } @@ -59,11 +59,11 @@ If defined here, they should not emit diagnostics. } export interface LinterConfiguration { /** - * if `false`, it disables the feature and the linter won't be executed. `true` by default + * if `false`, it disables the feature and the linter won't be executed. `true` by default */ enabled?: boolean; /** - * List of rules + * List of rules */ rules?: Rules; } @@ -76,11 +76,11 @@ The allowed range of values is 1..=320 export type LineWidth = number; export interface JavascriptFormatter { /** - * When properties in objects are quoted. Defaults to asNeeded. + * When properties in objects are quoted. Defaults to asNeeded. */ quoteProperties?: QuoteProperties; /** - * The style for quotes. Defaults to double. + * The style for quotes. Defaults to double. */ quoteStyle?: QuoteStyle; } @@ -88,7 +88,7 @@ export interface Rules { js?: Js; jsx?: Jsx; /** - * It enables the lint rules recommended by Rome. `true` by default. + * It enables the lint rules recommended by Rome. `true` by default. */ recommended?: boolean; regex?: Regex; @@ -98,25 +98,25 @@ export type QuoteProperties = "asNeeded" | "preserve"; export type QuoteStyle = "double" | "single"; export interface Js { /** - * It enables the recommended rules for this group + * It enables the recommended rules for this group */ recommended?: boolean; } export interface Jsx { /** - * It enables the recommended rules for this group + * It enables the recommended rules for this group */ recommended?: boolean; } export interface Regex { /** - * It enables the recommended rules for this group + * It enables the recommended rules for this group */ recommended?: boolean; } export interface Ts { /** - * It enables the recommended rules for this group + * It enables the recommended rules for this group */ recommended?: boolean; } @@ -157,8 +157,8 @@ export interface PullDiagnosticsResult { diagnostics: Diagnostic[]; } /** - * A diagnostic message that can give information like errors or warnings. - */ + * A diagnostic message that can give information like errors or warnings. + */ export interface Diagnostic { children: SubDiagnostic[]; code?: string; @@ -173,16 +173,16 @@ export interface Diagnostic { title: MarkupBuf; } /** - * Everything that can be added to a diagnostic, like a suggestion that will be displayed under the actual error. - */ + * Everything that can be added to a diagnostic, like a suggestion that will be displayed under the actual error. + */ export interface SubDiagnostic { msg: MarkupBuf; severity: Severity; span: FileSpan; } /** - * A note or help that is displayed under the diagnostic. - */ + * A note or help that is displayed under the diagnostic. + */ export interface Footer { msg: MarkupBuf; severity: Severity; @@ -194,8 +194,8 @@ These are ordered in the following way: */ export type Severity = "Help" | "Note" | "Warning" | "Error" | "Bug"; /** - * A Suggestion that is provided by rslint, and can be reported to the user, and can be automatically applied if it has the right [`Applicability`]. - */ + * A Suggestion that is provided by rslint, and can be reported to the user, and can be automatically applied if it has the right [`Applicability`]. + */ export interface CodeSuggestion { applicability: Applicability; labels: TextRangeSchema[]; @@ -203,22 +203,22 @@ export interface CodeSuggestion { span: FileSpan; style: SuggestionStyle; /** - * If the `FileId` is `None`, it's in the same file as his parent. + * If the `FileId` is `None`, it's in the same file as his parent. */ substitution: SuggestionChange; } export type DiagnosticTag = "Unnecessary" | "Deprecated" | "Both"; export type MarkupBuf = MarkupNodeBuf[]; /** - * A range that is indexed in a specific file. - */ + * A range that is indexed in a specific file. + */ export interface FileSpan { file: number; range: TextRangeSchema; } /** - * Indicates how a tool should manage this suggestion. - */ + * Indicates how a tool should manage this suggestion. + */ export type Applicability = | "Always" | "MaybeIncorrect" @@ -241,14 +241,14 @@ Must not overlap with other `InDel`s */ export interface Indel { /** - * Refers to offsets in the original text + * Refers to offsets in the original text */ delete: TextRangeSchema; insert: string; } /** - * Enumeration of all the supported markup elements - */ + * Enumeration of all the supported markup elements + */ export type MarkupElement = | "Emphasis" | "Dim" @@ -282,15 +282,15 @@ export interface Printed { verbatim_ranges: TextRangeSchema[]; } /** - * Lightweight sourcemap marker between source and output tokens - */ + * Lightweight sourcemap marker between source and output tokens + */ export interface SourceMarker { /** - * Position of the marker in the output code + * Position of the marker in the output code */ dest: number; /** - * Position of the marker in the original source + * Position of the marker in the original source */ source: number; } @@ -307,30 +307,30 @@ export interface FixFileParams { path: RomePath; } /** - * Which fixes should be applied during the analyzing phase - */ + * Which fixes should be applied during the analyzing phase + */ export type FixFileMode = "SafeFixes" | "SafeAndSuggestedFixes"; export interface FixFileResult { /** - * List of all the code actions applied to the file + * List of all the code actions applied to the file */ actions: FixAction[]; /** - * New source code for the file with all fixes applied + * New source code for the file with all fixes applied */ code: string; /** - * number of skipped suggested fixes + * number of skipped suggested fixes */ skipped_suggested_fixes: number; } export interface FixAction { /** - * Source range at which this action was applied + * Source range at which this action was applied */ range: TextRangeSchema; /** - * Name of the rule that emitted this code action + * Name of the rule that emitted this code action */ rule_name: string; } @@ -341,11 +341,11 @@ export interface RenameParams { } export interface RenameResult { /** - * List of text edit operations to apply on the source code + * List of text edit operations to apply on the source code */ indels: Indel[]; /** - * Range of source code modified by this rename operation + * Range of source code modified by this rename operation */ range: TextRangeSchema; } diff --git a/npm/rome/src/nodeWasm.ts b/npm/rome/src/nodeWasm.ts index ed5ec099ff9..4133355e398 100644 --- a/npm/rome/src/nodeWasm.ts +++ b/npm/rome/src/nodeWasm.ts @@ -10,8 +10,8 @@ export class NodeWasm { } /** - * It creates a new instance of a workspace connected to the WebAssembly backend - */ + * It creates a new instance of a workspace connected to the WebAssembly backend + */ public static async loadWebAssembly(): Promise { return new NodeWasm(await NodeWasm.loadWorkspace()); } diff --git a/website/playground/workers-site/index.js b/website/playground/workers-site/index.js index 9a01c98121d..a82e2faff0d 100644 --- a/website/playground/workers-site/index.js +++ b/website/playground/workers-site/index.js @@ -26,9 +26,9 @@ async function handleEvent(event) { let options = {}; /** - * You can add custom logic to how we fetch your assets - * by configuring the function `mapRequestToAsset` - */ + * You can add custom logic to how we fetch your assets + * by configuring the function `mapRequestToAsset` + */ // options.mapRequestToAsset = handlePrefix(/^\/docs/) try { diff --git a/website/src/_includes/scripts/index.js b/website/src/_includes/scripts/index.js index b1cebc986cd..fe287ca880a 100644 --- a/website/src/_includes/scripts/index.js +++ b/website/src/_includes/scripts/index.js @@ -386,12 +386,12 @@ class Manager { } /** - * Intercept link clicks, if they are just hashes on the current page then - * just scroll - * - * @param {MouseEvent} event - * @param {HTMLElement} target - */ + * Intercept link clicks, if they are just hashes on the current page then + * just scroll + * + * @param {MouseEvent} event + * @param {HTMLElement} target + */ handleAnchorClick(event, target) { let href = target.getAttribute("href"); if (href === undefined) {