Skip to content

Commit d5ce354

Browse files
committed
chore: update schema.json to have jsx.multiLineParens changes
1 parent 0765f22 commit d5ce354

File tree

5 files changed

+34
-27
lines changed

5 files changed

+34
-27
lines changed

deployment/schema.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@
6262
},
6363
"jsx.multiLineParens": {
6464
"description": "Surrounds the top-most JSX element or fragment in parentheses when it spans multiple lines.",
65-
"type": "boolean",
66-
"default": true,
65+
"type": "string",
66+
"default": "prefer",
6767
"oneOf": [{
68-
"const": true,
69-
"description": ""
68+
"const": "never",
69+
"description": "Never wrap JSX with parentheses."
7070
}, {
71-
"const": false,
72-
"description": ""
71+
"const": "prefer",
72+
"description": "Prefer wrapping with parentheses in most scenarios, except in function arguments and JSX attributes."
73+
}, {
74+
"const": "always",
75+
"description": "Always wrap JSX with parentheses if it spans multiple lines."
7376
}]
7477
},
7578
"newLineKind": {

src/configuration/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl ConfigurationBuilder {
6565
.tagged_template_space_before_literal(false)
6666
.conditional_expression_prefer_single_line(true)
6767
.quote_style(QuoteStyle::PreferDouble)
68-
.jsx_multi_line_parens(JsxMultiLineParensStyle::Prefer)
68+
.jsx_multi_line_parens(JsxMultiLineParens::Prefer)
6969
.ignore_node_comment_text("deno-fmt-ignore")
7070
.ignore_file_comment_text("deno-fmt-ignore-file")
7171
.module_sort_import_declarations(SortOrder::Maintain)
@@ -117,8 +117,8 @@ impl ConfigurationBuilder {
117117
/// Whether to surround a JSX element or fragment with parentheses
118118
/// when it's the top JSX node and it spans multiple lines.
119119
///
120-
/// Default: true
121-
pub fn jsx_multi_line_parens(&mut self, value: JsxMultiLineParensStyle) -> &mut Self {
120+
/// Default: `JsxMultiLineParens::Prefer`
121+
pub fn jsx_multi_line_parens(&mut self, value: JsxMultiLineParens) -> &mut Self {
122122
self.insert("jsx.multiLineParens", value.to_string().into())
123123
}
124124

@@ -939,7 +939,7 @@ mod tests {
939939
/* common */
940940
.quote_style(QuoteStyle::AlwaysDouble)
941941
.jsx_quote_style(JsxQuoteStyle::PreferSingle)
942-
.jsx_multi_line_parens(JsxMultiLineParensStyle::Never)
942+
.jsx_multi_line_parens(JsxMultiLineParens::Never)
943943
.semi_colons(SemiColons::Prefer)
944944
.brace_position(BracePosition::NextLine)
945945
.next_control_flow_position(NextControlFlowPosition::SameLine)

src/configuration/resolve_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn resolve_config(config: ConfigKeyMap, global_config: &GlobalConfiguration)
7777
arrow_function_use_parentheses: get_value(&mut config, "arrowFunction.useParentheses", UseParentheses::Maintain, &mut diagnostics),
7878
binary_expression_line_per_expression: get_value(&mut config, "binaryExpression.linePerExpression", false, &mut diagnostics),
7979
jsx_quote_style: get_value(&mut config, "jsx.quoteStyle", quote_style.to_jsx_quote_style(), &mut diagnostics),
80-
jsx_multi_line_parens: get_value(&mut config, "jsx.multiLineParens", JsxMultiLineParensStyle::Prefer, &mut diagnostics),
80+
jsx_multi_line_parens: get_value(&mut config, "jsx.multiLineParens", JsxMultiLineParens::Prefer, &mut diagnostics),
8181
member_expression_line_per_expression: get_value(&mut config, "memberExpression.linePerExpression", false, &mut diagnostics),
8282
type_literal_separator_kind_single_line: get_value(
8383
&mut config,

src/configuration/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ generate_str_to_from![JsxQuoteStyle, [PreferDouble, "preferDouble"], [PreferSing
210210
/// when it's the top JSX node and it spans multiple lines.
211211
#[derive(Clone, PartialEq, Copy, Serialize, Deserialize)]
212212
#[serde(rename_all = "camelCase")]
213-
pub enum JsxMultiLineParensStyle {
213+
pub enum JsxMultiLineParens {
214214
/// Never wrap JSX with parentheses.
215215
Never,
216216
/// Prefer wrapping with parentheses in most scenarios, except in function
@@ -220,7 +220,7 @@ pub enum JsxMultiLineParensStyle {
220220
Always,
221221
}
222222

223-
generate_str_to_from![JsxMultiLineParensStyle, [Never, "never"], [Prefer, "prefer"], [Always, "always"]];
223+
generate_str_to_from![JsxMultiLineParens, [Never, "never"], [Prefer, "prefer"], [Always, "always"]];
224224

225225
/// Whether to use semi-colons or commas.
226226
#[derive(Clone, PartialEq, Copy, Serialize, Deserialize)]
@@ -270,7 +270,7 @@ pub struct Configuration {
270270
#[serde(rename = "jsx.quoteStyle")]
271271
pub jsx_quote_style: JsxQuoteStyle,
272272
#[serde(rename = "jsx.multiLineParens")]
273-
pub jsx_multi_line_parens: JsxMultiLineParensStyle,
273+
pub jsx_multi_line_parens: JsxMultiLineParens,
274274
#[serde(rename = "memberExpression.linePerExpression")]
275275
pub member_expression_line_per_expression: bool,
276276
#[serde(rename = "typeLiteral.separatorKind.singleLine")]

src/parsing/parser.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,7 +3048,7 @@ fn handle_jsx_surrounding_parens<'a>(inner_items: PrintItems, context: &mut Cont
30483048
}
30493049
}
30503050

3051-
if context.parent().is::<JSXExprContainer>() && context.config.jsx_multi_line_parens != JsxMultiLineParensStyle::Always {
3051+
if context.parent().is::<JSXExprContainer>() && context.config.jsx_multi_line_parens != JsxMultiLineParens::Always {
30523052
return surround_with_newlines_indented_if_multi_line(inner_items, context.config.indent_width);
30533053
}
30543054

@@ -3093,7 +3093,7 @@ fn handle_jsx_surrounding_parens<'a>(inner_items: PrintItems, context: &mut Cont
30933093
}
30943094

30953095
fn is_jsx_paren_expr_handled_node(node: &Node, context: &Context) -> bool {
3096-
if context.config.jsx_multi_line_parens == JsxMultiLineParensStyle::Never {
3096+
if context.config.jsx_multi_line_parens == JsxMultiLineParens::Never {
30973097
return false;
30983098
}
30993099

@@ -3118,7 +3118,7 @@ fn is_jsx_paren_expr_handled_node(node: &Node, context: &Context) -> bool {
31183118
parent = parent.parent().unwrap();
31193119
}
31203120

3121-
if context.config.jsx_multi_line_parens == JsxMultiLineParensStyle::Always {
3121+
if context.config.jsx_multi_line_parens == JsxMultiLineParens::Always {
31223122
return true;
31233123
}
31243124

@@ -7947,18 +7947,11 @@ fn jsx_space_separator(previous_node: &Node, current_node: &Node, context: &Cont
79477947
}
79487948
}
79497949

7950-
fn get_quote_char(context: &Context) -> String {
7951-
return match context.config.quote_style {
7952-
QuoteStyle::PreferDouble | QuoteStyle::AlwaysDouble => "\"".to_string(),
7953-
QuoteStyle::PreferSingle | QuoteStyle::AlwaysSingle => "'".to_string()
7954-
};
7955-
}
7956-
79577950
fn jsx_force_space_with_newline_if_either_node_multi_line(previous_node: &Node, current_node: &Node, context: &Context) -> PrintItems {
79587951
let previous_node_info_range = get_node_info_range(previous_node, context);
79597952
let current_node_info_range = get_node_info_range(current_node, context);
79607953
let spaces_between_count = node_helpers::count_spaces_between_jsx_children(previous_node, current_node, &context.module);
7961-
let jsx_space_expr_text = format!("{{{}{}{}}}", get_quote_char(context), " ".repeat(spaces_between_count), get_quote_char(context));
7954+
let jsx_space_expr_text = get_jsx_space_text(spaces_between_count, context);
79627955
if_true_or(
79637956
"jsxIsLastChildMultiLine",
79647957
move |condition_context| {
@@ -8005,7 +7998,7 @@ fn jsx_space_separator(previous_node: &Node, current_node: &Node, context: &Cont
80057998

80067999
if spaces_between_count > 1 {
80078000
items.push_signal(Signal::PossibleNewLine);
8008-
items.push_string(format!("{{{}{}{}}}", get_quote_char(context), " ".repeat(spaces_between_count), get_quote_char(context)));
8001+
items.push_string(get_jsx_space_text(spaces_between_count, context));
80098002
items.push_signal(Signal::PossibleNewLine);
80108003
return items;
80118004
}
@@ -8045,7 +8038,7 @@ fn jsx_space_separator(previous_node: &Node, current_node: &Node, context: &Cont
80458038
true_path: {
80468039
let mut items = PrintItems::new();
80478040
items.push_signal(Signal::PossibleNewLine);
8048-
items.push_string(format!("{{{} {}}}", get_quote_char(context), get_quote_char(context)));
8041+
items.push_string(get_jsx_space_text(1, context));
80498042
items.push_signal(Signal::NewLine);
80508043
Some(items)
80518044
},
@@ -8058,6 +8051,17 @@ fn jsx_space_separator(previous_node: &Node, current_node: &Node, context: &Cont
80588051
}
80598052
}
80608053

8054+
fn get_jsx_space_text(spaces_between_count: usize, context: &Context) -> String {
8055+
format!("{{{}{}{}}}", get_quote_char(context), " ".repeat(spaces_between_count), get_quote_char(context))
8056+
}
8057+
8058+
fn get_quote_char(context: &Context) -> String {
8059+
return match context.config.quote_style {
8060+
QuoteStyle::PreferDouble | QuoteStyle::AlwaysDouble => "\"".to_string(),
8061+
QuoteStyle::PreferSingle | QuoteStyle::AlwaysSingle => "'".to_string(),
8062+
};
8063+
}
8064+
80618065
#[inline]
80628066
fn parse_assignment<'a>(expr: Node<'a>, op: &str, context: &mut Context<'a>) -> PrintItems {
80638067
parse_assignment_op_to(expr, op, op, context)

0 commit comments

Comments
 (0)