Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Sep 16, 2022
1 parent 81c802d commit ef9db3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
23 changes: 0 additions & 23 deletions crates/rome_js_formatter/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,29 +1090,6 @@ fn handle_import_export_specifier_comment(

_ => CommentPlacement::Default(comment),
}

// if (
// enclosingNode?.type === "ImportSpecifier" ||
// enclosingNode?.type === "ExportSpecifier"
// ) {
// addLeadingComment(enclosingNode, comment);
// return true;
// }
//
// const isImportDeclaration =
// precedingNode?.type === "ImportSpecifier" &&
// enclosingNode?.type === "ImportDeclaration";
// const isExportDeclaration =
// precedingNode?.type === "ExportSpecifier" &&
// enclosingNode?.type === "ExportNamedDeclaration";
// if (
// (isImportDeclaration || isExportDeclaration) &&
// hasNewline(text, locEnd(comment))
// ) {
// addTrailingComment(precedingNode, comment);
// return true;
// }
// return false;
}

fn place_leading_statement_comment(
Expand Down
19 changes: 19 additions & 0 deletions crates/rome_js_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ where
{
}

/// Rule for formatting a JavaScript [AstNode].
pub trait FormatNodeRule<N>
where
N: AstNode<Language = JsLanguage>,
Expand All @@ -434,6 +435,7 @@ where
self.fmt_trailing_comments(node, f)
}

/// Formats the node without comments. Ignores any suppression comments.
fn fmt_node(&self, node: &N, f: &mut JsFormatter) -> FormatResult<()> {
if self.needs_parentheses(node) {
write!(
Expand All @@ -458,25 +460,42 @@ where
false
}

/// Returns `true` if the node has a suppression comment and should use the same formatting as in the source document.
fn is_suppressed(&self, node: &N, f: &JsFormatter) -> bool {
f.context().comments().is_suppressed(node.syntax())
}

/// Formats the [leading comments](rome_formatter::comments#leading-comments) of the node.
///
/// You may want to override this method if you want to manually handle the formatting of comments
/// inside of the `fmt_fields` method or customize the formatting of the leading comments.
fn fmt_leading_comments(&self, node: &N, f: &mut JsFormatter) -> FormatResult<()> {
format_leading_comments(node.syntax()).fmt(f)
}

/// Formats the [dangling comments](rome_formatter::comments#dangling-comments) of the node.
///
/// You should override this method if the node handled by this rule can have dangling comments because the
/// default implementation formats the dangling comments at the end of the node, which isn't ideal but ensures that
/// no comments are dropped.
///
/// A node can have dangling comments if all its children are tokens or if all node childrens are optional.
fn fmt_dangling_comments(&self, node: &N, f: &mut JsFormatter) -> FormatResult<()> {
format_dangling_comments(node.syntax())
.with_soft_block_indent()
.fmt(f)
}

/// Formats the [trailing comments](rome_formatter::comments#trailing-comments) of the node.
///
/// You may want to override this method if you want to manually handle the formatting of comments
/// inside of the `fmt_fields` method or customize the formatting of the trailing comments.
fn fmt_trailing_comments(&self, node: &N, f: &mut JsFormatter) -> FormatResult<()> {
format_trailing_comments(node.syntax()).fmt(f)
}
}

/// Rule for formatting an unknown node.
pub trait FormatUnknownNodeRule<N>
where
N: AstNode<Language = JsLanguage>,
Expand Down

0 comments on commit ef9db3e

Please sign in to comment.