@@ -68,11 +68,10 @@ impl Rule for PreferArrayFlatMap {
6868 }
6969
7070 if let Some ( first_arg) = flat_call_expr. arguments . first ( ) {
71- if let Argument :: NumericLiteral ( number_lit) = first_arg {
72- if number_lit. raw . as_ref ( ) . unwrap ( ) != "1" {
73- return ;
74- }
75- } else {
71+ // Strict comparison of `f64`s with `==` is appropriate here, because `lit.value` is derived
72+ // from a literal value in source, not from a calculation which might introduce imprecision
73+ #[ expect( clippy:: float_cmp) ]
74+ if !matches ! ( first_arg, Argument :: NumericLiteral ( lit) if lit. value == 1.0 ) {
7675 return ;
7776 }
7877 }
@@ -107,6 +106,9 @@ fn test() {
107106 ( "const bar = [[1],[2],[3]].flat()" , None ) ,
108107 ( "const bar = [1,2,3].map(i => [i]).sort().flat()" , None ) ,
109108 ( "const bar = [[1],[2],[3]].map(i => [i]).flat(2)" , None ) ,
109+ ( "const bar = [[1],[2],[3]].map(i => [i]).flat(2.0)" , None ) ,
110+ ( "const bar = [[1],[2],[3]].map(i => [i]).flat(0.9999999999999999)" , None ) ,
111+ ( "const bar = [[1],[2],[3]].map(i => [i]).flat(1.000000000000001)" , None ) ,
110112 ( "const bar = [[1],[2],[3]].map(i => [i]).flat(1, null)" , None ) ,
111113 ( "const bar = [[1],[2],[3]].map(i => [i]).flat(Infinity)" , None ) ,
112114 ( "const bar = [[1],[2],[3]].map(i => [i]).flat(Number.POSITIVE_INFINITY)" , None ) ,
@@ -117,11 +119,15 @@ fn test() {
117119 ( "const bar = [[1],[2],[3]].map(i => [i]).flat(+1)" , None ) ,
118120 ( "const bar = [[1],[2],[3]].map(i => [i]).flat(foo)" , None ) ,
119121 ( "const bar = [[1],[2],[3]].map(i => [i]).flat(foo.bar)" , None ) ,
120- ( "const bar = [[1],[2],[3]].map(i => [i]).flat(1.00)" , None ) ,
121122 ] ;
122123
123124 let fail = vec ! [
124125 ( "const bar = [[1],[2],[3]].map(i => [i]).flat()" , None ) ,
126+ ( "const bar = [[1],[2],[3]].map(i => [i]).flat(1)" , None ) ,
127+ ( "const bar = [[1],[2],[3]].map(i => [i]).flat(1.0)" , None ) ,
128+ ( "const bar = [[1],[2],[3]].map(i => [i]).flat(1.00)" , None ) ,
129+ ( "const bar = [[1],[2],[3]].map(i => [i]).flat(0.99999999999999999)" , None ) ,
130+ ( "const bar = [[1],[2],[3]].map(i => [i]).flat(1.0000000000000001)" , None ) ,
125131 ( "const bar = [[1],[2],[3]].map(i => [i]).flat(1,)" , None ) ,
126132 ( "const bar = [1,2,3].map(i => [i]).flat()" , None ) ,
127133 ( "const bar = [1,2,3].map((i) => [i]).flat()" , None ) ,
0 commit comments