File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed
crates/oxc_linter/src/rules/unicorn Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change 1- use lazy_regex:: Regex ;
21use oxc_ast:: { AstKind , ast:: Statement } ;
32use oxc_diagnostics:: OxcDiagnostic ;
43use oxc_macros:: declare_oxc_lint;
@@ -104,9 +103,6 @@ impl Rule for SwitchCaseBraces {
104103 return ;
105104 }
106105
107- let switch_clause_regex =
108- Regex :: new ( r#"(?:case|default)\s*(?:`[^`]+`|'[^']+'|"[^"]+"|[^:]*):"# ) . unwrap ( ) ;
109-
110106 for case in & switch. cases {
111107 if case. consequent . is_empty ( ) {
112108 continue ;
@@ -146,11 +142,13 @@ impl Rule for SwitchCaseBraces {
146142 } ;
147143
148144 if self . always_braces && missing_braces {
149- let colon_end = u32:: try_from (
150- switch_clause_regex. find ( ctx. source_range ( case. span ) ) . unwrap ( ) . end ( ) ,
145+ let colon = u32:: try_from (
146+ ctx. source_range ( Span :: new ( case. span . start , case. consequent [ 0 ] . span ( ) . start ) )
147+ . rfind ( ':' )
148+ . unwrap ( ) ,
151149 )
152150 . unwrap ( ) ;
153- let span = Span :: sized ( case. span . start , colon_end ) ;
151+ let span = Span :: sized ( case. span . start , colon + 1 ) ;
154152 ctx. diagnostic_with_fix (
155153 switch_case_braces_diagnostic_missing_braces ( span) ,
156154 |fixer| {
You can’t perform that action at this time.
0 commit comments