From d303628ef8fbf8eb70fb14bc3b2709f2fea1112c Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Mon, 4 Jul 2022 23:58:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/analyzers/no_comment_text.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/rome_js_analyze/src/analyzers/no_comment_text.rs b/crates/rome_js_analyze/src/analyzers/no_comment_text.rs index 210c5ad3a09..fa072634528 100644 --- a/crates/rome_js_analyze/src/analyzers/no_comment_text.rs +++ b/crates/rome_js_analyze/src/analyzers/no_comment_text.rs @@ -70,7 +70,14 @@ impl Rule for NoCommentText { fn action(ctx: &RuleContext, _: &Self::State) -> Option { let Ast(node) = ctx.query(); - let normalized_jsx_text = node.text(); + let normalized_comment = format!( + "/*{}*/", + node.text() + .trim_start_matches("/**") + .trim_start_matches("//") + .trim_start_matches("/*") + .trim_end_matches("*/") + ); let root = ctx.root().replace_node( JsxAnyChild::JsxText(node.clone()), JsxAnyChild::JsxExpressionChild( @@ -78,15 +85,7 @@ impl Rule for NoCommentText { make::token(T!['{']).with_trailing_trivia( [( TriviaPieceKind::MultiLineComment, - format!( - "/*{}*/", - normalized_jsx_text - .trim_start_matches("/**") - .trim_start_matches("//") - .trim_start_matches("/*") - .trim_end_matches("*/") - ) - .as_str(), + normalized_comment.as_str(), )] .into_iter(), ),