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

Commit

Permalink
Code review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Aug 3, 2022
1 parent b29668a commit 3940b57
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn parenthesis_can_be_omitted(node: &JsParenthesizedExpression) -> SyntaxResult<

if let Some(parent) = &parent {
match parent.kind() {
// The formatting of the return or throw argument takes care of adding parens if necessary
// The formatting of the return or throw argument takes care of adding parentheses if necessary
JsSyntaxKind::JS_RETURN_STATEMENT | JsSyntaxKind::JS_THROW_STATEMENT => {
return Ok(true)
}
Expand Down Expand Up @@ -180,9 +180,8 @@ fn parenthesis_can_be_omitted(node: &JsParenthesizedExpression) -> SyntaxResult<
return Ok(false);
}

if let Some(parent) = &parent {
if JsAnyBinaryLikeExpression::can_cast(parent.kind()) {
let binary_like = JsAnyBinaryLikeExpression::unwrap_cast(parent.clone());
if let Some(parent) = parent {
if let Some(binary_like) = JsAnyBinaryLikeExpression::cast(parent) {
let operator = binary_like.operator()?;

if !binary_argument_needs_parens(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl FormatNodeRule<JsSequenceExpression> for FormatJsSequenceExpression {
let mut is_nested = false;
let mut first_non_sequence_or_paren_parent = None;

// Skip 1 because ancestor starts with the current node but we're interested in the parent
for parent in node.syntax().ancestors().skip(1) {
if parent.kind() == JS_SEQUENCE_EXPRESSION {
is_nested = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ impl Format<JsFormatContext> for FormatReturnOrThrowArgument<'_> {
}
}

/// Tests if the passed in argument has any leading comments. This is the case if
/// * the argument's first token has a leading comment
/// * the argument is a parenthesized expression and the inner expression has a leading comment.
fn has_argument_leading_comments(argument: &JsAnyExpression) -> SyntaxResult<bool> {
if matches!(argument, JsAnyExpression::JsxTagExpression(_)) {
// JSX formatting takes care of adding parens
Expand All @@ -90,8 +93,7 @@ fn has_argument_leading_comments(argument: &JsAnyExpression) -> SyntaxResult<boo

let result = match argument {
JsAnyExpression::JsParenthesizedExpression(inner) => {
inner.syntax().has_leading_comments()
|| has_argument_leading_comments(&inner.expression()?)?
has_argument_leading_comments(&inner.expression()?)?
}
_ => false,
};
Expand Down

0 comments on commit 3940b57

Please sign in to comment.