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

feat(rome_js_formatter): Conditional JSX Chain layout #3150

Merged
merged 3 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::prelude::*;
use crate::utils::JsAnyConditional;
use crate::utils::{ConditionalJsxChain, JsAnyConditional};
use rome_formatter::FormatRuleWithOptions;

use crate::parentheses::{
is_binary_like_left_or_right, is_conditional_test, is_spread,
Expand All @@ -8,15 +9,29 @@ use crate::parentheses::{
use rome_js_syntax::{JsConditionalExpression, JsSyntaxKind, JsSyntaxNode};

#[derive(Debug, Clone, Default)]
pub struct FormatJsConditionalExpression;
pub struct FormatJsConditionalExpression {
jsx_chain: ConditionalJsxChain,
}

impl FormatRuleWithOptions<JsConditionalExpression> for FormatJsConditionalExpression {
type Options = ConditionalJsxChain;

fn with_options(mut self, options: Self::Options) -> Self {
self.jsx_chain = options;
self
}
}

impl FormatNodeRule<JsConditionalExpression> for FormatJsConditionalExpression {
fn fmt_fields(
&self,
node: &JsConditionalExpression,
formatter: &mut JsFormatter,
) -> FormatResult<()> {
JsAnyConditional::from(node.clone()).fmt(formatter)
JsAnyConditional::from(node.clone())
.format()
.with_options(self.jsx_chain)
.fmt(formatter)
}

fn needs_parentheses(&self, item: &JsConditionalExpression) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_js_formatter/src/ts/types/conditional_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl FormatNodeRule<TsConditionalType> for FormatTsConditionalType {
node: &TsConditionalType,
formatter: &mut JsFormatter,
) -> FormatResult<()> {
JsAnyConditional::from(node.clone()).fmt(formatter)
JsAnyConditional::from(node.clone()).format().fmt(formatter)
}

fn needs_parentheses(&self, item: &TsConditionalType) -> bool {
Expand Down
Loading