@@ -88,7 +88,7 @@ declare_oxc_lint!(
8888 Eqeqeq ,
8989 eslint,
9090 pedantic,
91- conditional_fix
91+ conditional_fix_dangerous ,
9292) ;
9393
9494impl Rule for Eqeqeq {
@@ -166,20 +166,23 @@ impl Rule for Eqeqeq {
166166 Span :: new ( operator_start, operator_end)
167167 } ;
168168
169- // If the comparison is a `typeof` comparison or both sides are literals with the same type, then it's safe to fix.
170- if is_type_of_binary_bool || are_literals_and_same_type_bool {
171- ctx. diagnostic_with_fix (
172- eqeqeq_diagnostic ( operator, preferred_operator, operator_span) ,
173- |fixer| {
174- let start = binary_expr. left . span ( ) . end ;
175- let end = binary_expr. right . span ( ) . start ;
176- let span = Span :: new ( start, end) ;
177- fixer. replace ( span, preferred_operator_with_padding)
178- } ,
179- ) ;
169+ let fix_kind = if is_type_of_binary_bool || are_literals_and_same_type_bool {
170+ FixKind :: SafeFix
180171 } else {
181- ctx. diagnostic ( eqeqeq_diagnostic ( operator, preferred_operator, operator_span) ) ;
182- }
172+ FixKind :: DangerousFix
173+ } ;
174+
175+ ctx. diagnostic_with_fix_of_kind (
176+ eqeqeq_diagnostic ( operator, preferred_operator, operator_span) ,
177+ fix_kind,
178+ |fixer| {
179+ let start = binary_expr. left . span ( ) . end ;
180+ let end = binary_expr. right . span ( ) . start ;
181+ let span = Span :: new ( start, end) ;
182+
183+ fixer. replace ( span, preferred_operator_with_padding)
184+ } ,
185+ ) ;
183186 }
184187}
185188
@@ -300,9 +303,8 @@ fn test() {
300303 ( "'foo'=='foo'" , "'foo' === 'foo'" , None ) ,
301304 ( "typeof a == b" , "typeof a === b" , None ) ,
302305 ( "1000 != 1000" , "1000 !== 1000" , None ) ,
303- // The following cases will not be fixed
304- ( "(1000 + 1) != 1000" , "(1000 + 1) != 1000" , None ) ,
305- ( "a == b" , "a == b" , None ) ,
306+ ( "(1000 + 1) != 1000" , "(1000 + 1) !== 1000" , None ) ,
307+ ( "a == b" , "a === b" , None ) ,
306308 ] ;
307309
308310 Tester :: new ( Eqeqeq :: NAME , Eqeqeq :: PLUGIN , pass, fail) . expect_fix ( fix) . test_and_snapshot ( ) ;
0 commit comments