Skip to content

Commit 7ec9752

Browse files
authored
feat: add catchClause.spaceAround (#608)
1 parent 90a5d64 commit 7ec9752

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

deployment/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,9 @@
868868
"arrayPattern.spaceAround": {
869869
"$ref": "#/definitions/spaceAround"
870870
},
871+
"catchClause.spaceAround": {
872+
"$ref": "#/definitions/spaceAround"
873+
},
871874
"doWhileStatement.spaceAround": {
872875
"$ref": "#/definitions/spaceAround"
873876
},

src/configuration/builder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,10 @@ impl ConfigurationBuilder {
10081008
self.insert("arrayPattern.spaceAround", value.into())
10091009
}
10101010

1011+
pub fn catch_clause_space_around(&mut self, value: bool) -> &mut Self {
1012+
self.insert("catchClause.spaceAround", value.into())
1013+
}
1014+
10111015
pub fn do_while_statement_space_around(&mut self, value: bool) -> &mut Self {
10121016
self.insert("doWhileStatement.spaceAround", value.into())
10131017
}
@@ -1252,6 +1256,7 @@ mod tests {
12521256
.arguments_space_around(true)
12531257
.array_expression_space_around(true)
12541258
.array_pattern_space_around(true)
1259+
.catch_clause_space_around(true)
12551260
.do_while_statement_space_around(true)
12561261
.for_in_statement_space_around(true)
12571262
.for_of_statement_space_around(true)
@@ -1264,7 +1269,7 @@ mod tests {
12641269
.while_statement_space_around(true);
12651270

12661271
let inner_config = config.get_inner_config();
1267-
assert_eq!(inner_config.len(), 178);
1272+
assert_eq!(inner_config.len(), 179);
12681273
let diagnostics = resolve_config(inner_config, &Default::default()).diagnostics;
12691274
assert_eq!(diagnostics.len(), 0);
12701275
}

src/configuration/resolve_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ pub fn resolve_config(config: ConfigKeyMap, global_config: &GlobalConfiguration)
309309
arguments_space_around: get_value(&mut config, "arguments.spaceAround", space_around, &mut diagnostics),
310310
array_expression_space_around: get_value(&mut config, "arrayExpression.spaceAround", space_around, &mut diagnostics),
311311
array_pattern_space_around: get_value(&mut config, "arrayPattern.spaceAround", space_around, &mut diagnostics),
312+
catch_clause_space_around: get_value(&mut config, "catchClause.spaceAround", space_around, &mut diagnostics),
312313
do_while_statement_space_around: get_value(&mut config, "doWhileStatement.spaceAround", space_around, &mut diagnostics),
313314
for_in_statement_space_around: get_value(&mut config, "forInStatement.spaceAround", space_around, &mut diagnostics),
314315
for_of_statement_space_around: get_value(&mut config, "forOfStatement.spaceAround", space_around, &mut diagnostics),

src/configuration/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ pub struct Configuration {
610610
pub array_expression_space_around: bool,
611611
#[serde(rename = "arrayPattern.spaceAround")]
612612
pub array_pattern_space_around: bool,
613+
#[serde(rename = "catchClause.spaceAround")]
614+
pub catch_clause_space_around: bool,
613615
#[serde(rename = "doWhileStatement.spaceAround")]
614616
pub do_while_statement_space_around: bool,
615617
#[serde(rename = "forInStatement.spaceAround")]

src/generation/generate.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,13 @@ fn gen_catch_clause<'a>(node: &CatchClause<'a>, context: &mut Context<'a>) -> Pr
722722

723723
if let Some(param) = &node.param {
724724
items.push_str(" (");
725+
if context.config.catch_clause_space_around {
726+
items.push_str(" ");
727+
}
725728
items.extend(gen_node(param.into(), context));
729+
if context.config.catch_clause_space_around {
730+
items.push_str(" ");
731+
}
726732
items.push_str(")");
727733
}
728734
items.push_info(end_header_ln);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
~~ catchClause.spaceAround: true ~~
2+
== should output without param ==
3+
try{
4+
a;
5+
} catch
6+
{
7+
b;
8+
}
9+
10+
[expect]
11+
try {
12+
a;
13+
} catch {
14+
b;
15+
}
16+
17+
== should output with param ==
18+
try{
19+
a;
20+
}
21+
catch(ex){
22+
b;
23+
}
24+
25+
[expect]
26+
try {
27+
a;
28+
} catch ( ex ) {
29+
b;
30+
}
31+
32+
== should output with type on param ==
33+
try {
34+
a
35+
} catch ( ex :unknown ) {
36+
}
37+
38+
[expect]
39+
try {
40+
a;
41+
} catch ( ex: unknown ) {
42+
}

0 commit comments

Comments
 (0)