File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
crates/oxc_linter/src/rules/unicorn Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,9 @@ impl Rule for SwitchCaseBraces {
96
96
}
97
97
98
98
fn run < ' a > ( & self , node : & AstNode < ' a > , ctx : & LintContext < ' a > ) {
99
+ let switch_clause_regex =
100
+ Regex :: new ( r#"(case|default)\s*(`.+`|'.+'|".+"|[^:]*):"# ) . unwrap ( ) ;
101
+
99
102
let AstKind :: SwitchStatement ( switch) = node. kind ( ) else {
100
103
return ;
101
104
} ;
@@ -143,9 +146,10 @@ impl Rule for SwitchCaseBraces {
143
146
} ;
144
147
145
148
if self . always_braces && missing_braces {
146
- let regex = Regex :: new ( r#"(case|default)\s*(`.+`|'.+'|".+"|[^:]*):"# ) . unwrap ( ) ;
147
- let colon_end =
148
- u32:: try_from ( regex. find ( ctx. source_range ( case. span ) ) . unwrap ( ) . end ( ) ) . unwrap ( ) ;
149
+ let colon_end = u32:: try_from (
150
+ switch_clause_regex. find ( ctx. source_range ( case. span ) ) . unwrap ( ) . end ( ) ,
151
+ )
152
+ . unwrap ( ) ;
149
153
let span = Span :: sized ( case. span . start , colon_end) ;
150
154
ctx. diagnostic_with_fix (
151
155
switch_case_braces_diagnostic_missing_braces ( span) ,
You can’t perform that action at this time.
0 commit comments