--- source: crates/biome_js_analyze/tests/spec_tests.rs expression: invalid.jsx --- # Input ```jsx import React from "react"; [, , ]; [...[, ], ]; [, xyz ? : , ]; [<>, <>, <>]; data.map(x => {x}); data.map(x => <>{x}); data.forEach(x => data1.push(<>{x})); Array.from([1, 2, 3], (x) => {x}); Array.from([1, 2, 3], (x) => { return {x} }); [React.createElement("h1"), React.createElement("h1"), React.createElement("h1")]; data.map(c => React.createElement("h1")); React.Children.map(c => React.cloneElement(c)); (

{data.map(x =>

{x}

)}) (

{[

,

,

]}) (

{[

, xyz, abc?

: bcd]}) (

{data.map(c =>

)}) (

{data.map(c => xyz)}

) (

{data.map(c => (

))}) ``` # Diagnostics ``` invalid.jsx:3:2 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 1 │ import React from "react"; 2 │ > 3 │ [, , ]; │ ^^^^^^^^^ 4 │ 5 │ [...[, ], ]; i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:3:13 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 1 │ import React from "react"; 2 │ > 3 │ [, , ]; │ ^^^^^^^^^ 4 │ 5 │ [...[, ], ]; i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:3:24 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 1 │ import React from "react"; 2 │ > 3 │ [, , ]; │ ^^^^^^^^^ 4 │ 5 │ [...[, ], ]; i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:5:29 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 3 │ [, , ]; 4 │ > 5 │ [...[, ], ]; │ ^^^^^^^^^ 6 │ 7 │ [, xyz ? : , ]; i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:5:6 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 3 │ [, , ]; 4 │ > 5 │ [...[, ], ]; │ ^^^^^^^^^ 6 │ 7 │ [, xyz ? : , ]; i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:5:17 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 3 │ [, , ]; 4 │ > 5 │ [...[, ], ]; │ ^^^^^^^^^ 6 │ 7 │ [, xyz ? : , ]; i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:7:2 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 5 │ [...[, ], ]; 6 │ > 7 │ [, xyz ? : , ]; │ ^^^^^^^^^ 8 │ 9 │ [<>, <>, <>]; i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:7:41 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 5 │ [...[, ], ]; 6 │ > 7 │ [, xyz ? : , ]; │ ^^^^^^^^^ 8 │ 9 │ [<>, <>, <>]; i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:9:2 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 7 │ [, xyz ? : , ]; 8 │ > 9 │ [<>, <>, <>]; │ ^^^^^ 10 │ 11 │ data.map(x => {x}); i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:9:9 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 7 │ [, xyz ? : , ]; 8 │ > 9 │ [<>, <>, <>]; │ ^^^^^ 10 │ 11 │ data.map(x => {x}); i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:9:16 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 7 │ [, xyz ? : , ]; 8 │ > 9 │ [<>, <>, <>]; │ ^^^^^ 10 │ 11 │ data.map(x => {x}); i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:11:15 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 9 │ [<>, <>, <>]; 10 │ > 11 │ data.map(x => {x}); │ ^^^^^^^ 12 │ 13 │ data.map(x => <>{x}); i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:13:15 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 11 │ data.map(x => {x}); 12 │ > 13 │ data.map(x => <>{x}); │ ^^^^^^^^ 14 │ 15 │ data.forEach(x => data1.push(<>{x})); i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:17:30 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 15 │ data.forEach(x => data1.push(<>{x})); 16 │ > 17 │ Array.from([1, 2, 3], (x) => {x}); │ ^^^^^^^ 18 │ 19 │ Array.from([1, 2, 3], (x) => { i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:20:9 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 19 │ Array.from([1, 2, 3], (x) => { > 20 │ return {x} │ ^^^^^^^ 21 │ }); 22 │ i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:23:21 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 21 │ }); 22 │ > 23 │ [React.createElement("h1"), React.createElement("h1"), React.createElement("h1")]; │ ^^^^^^ 24 │ 25 │ data.map(c => React.createElement("h1")); i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:23:48 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 21 │ }); 22 │ > 23 │ [React.createElement("h1"), React.createElement("h1"), React.createElement("h1")]; │ ^^^^^^ 24 │ 25 │ data.map(c => React.createElement("h1")); i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:23:75 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 21 │ }); 22 │ > 23 │ [React.createElement("h1"), React.createElement("h1"), React.createElement("h1")]; │ ^^^^^^ 24 │ 25 │ data.map(c => React.createElement("h1")); i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:25:34 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 23 │ [React.createElement("h1"), React.createElement("h1"), React.createElement("h1")]; 24 │ > 25 │ data.map(c => React.createElement("h1")); │ ^^^^^^ 26 │ 27 │ React.Children.map(c => React.cloneElement(c)); i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:27:43 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 25 │ data.map(c => React.createElement("h1")); 26 │ > 27 │ React.Children.map(c => React.cloneElement(c)); │ ^^^ 28 │ 29 │ (

{data.map(x =>

{x}

)}) i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:29:21 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 27 │ React.Children.map(c => React.cloneElement(c)); 28 │ > 29 │ (

{data.map(x =>

{x}

)}) │ ^^^^ 30 │ 31 │ (

{[

,

,

]}) i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:31:8 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 29 │ (

{data.map(x =>

{x}

)}) 30 │ > 31 │ (

{[

,

,

]}) │ ^^^^ 32 │ 33 │ (

{[

, xyz, abc?

: bcd]}) i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:31:19 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 29 │ (

{data.map(x =>

{x}

)}) 30 │ > 31 │ (

{[

,

,

]}) │ ^^^^ 32 │ 33 │ (

{[

, xyz, abc?

: bcd]}) i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:31:30 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 29 │ (

{data.map(x =>

{x}

)}) 30 │ > 31 │ (

{[

,

,

]}) │ ^^^^ 32 │ 33 │ (

{[

, xyz, abc?

: bcd]}) i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:33:8 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 31 │ (

{[

,

,

]}) 32 │ > 33 │ (

{[

, xyz, abc?

: bcd]}) │ ^^^^ 34 │ 35 │ (

{data.map(c =>

)}) i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:33:19 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Cannot determine whether this child has the required key prop. 31 │ (

{[

,

,

]}) 32 │ > 33 │ (

{[

, xyz, abc?

: bcd]}) │ ^^^ 34 │ 35 │ (

{data.map(c =>

)}) i Either return a JSX expression, or suppress this instance if you determine it is safe. i Check the React documentation for why a key prop is required. ``` ``` invalid.jsx:33:24 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Cannot determine whether this child has the required key prop. 31 │ (

{[

,

,

]}) 32 │ > 33 │ (

{[

, xyz, abc?

: bcd]}) │ ^^^^^^^^^^^^^^^^^^^ 34 │ 35 │ (

{data.map(c =>

)}) i Either return a JSX expression, or suppress this instance if you determine it is safe. i Check the React documentation for why a key prop is required. ``` ``` invalid.jsx:35:21 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 33 │ (

{[

, xyz, abc?

: bcd]}) 34 │ > 35 │ (

{data.map(c =>

)}) │ ^^^^ 36 │ 37 │ (

{data.map(c => xyz)}

) i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ``` ``` invalid.jsx:37:21 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Cannot determine whether this child has the required key prop. 35 │ (

{data.map(c =>

)}) 36 │ > 37 │ (

{data.map(c => xyz)}

) │ ^^^ 38 │ 39 │ (

{data.map(c => (

))}) i Either return a JSX expression, or suppress this instance if you determine it is safe. i Check the React documentation for why a key prop is required. ``` ``` invalid.jsx:39:22 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Missing key property for this element in iterable. 37 │ (

{data.map(c => xyz)}

) 38 │ > 39 │ (

{data.map(c => (

))}) │ ^^^^ i The order of the items may change, and having a key can help React identify which item was moved. i Check the React documentation. ```