@@ -36,6 +36,12 @@ const settings = {
3636const ruleTester = new RuleTester ( { parserOptions } ) ;
3737ruleTester . run ( 'jsx-key' , rule , {
3838 valid : parsers . all ( [
39+ {
40+ code : `
41+ [1, 2, 3].map((item) => {
42+ return item === 'bar' ? <div key={item}>{item}</div> : <span key={item}>{item}</span>;
43+ })` ,
44+ } ,
3945 { code : 'fn()' } ,
4046 { code : '[1, 2, 3].map(function () {})' } ,
4147 { code : '<App />;' } ,
@@ -207,6 +213,57 @@ ruleTester.run('jsx-key', rule, {
207213 } ,
208214 ] ) ,
209215 invalid : parsers . all ( [
216+ {
217+ code : `
218+ [1, 2, 3].map((item) => {
219+ return item === 'bar' ? <div>{item}</div> : <span>{item}</span>;
220+ })` ,
221+ errors : [
222+ { messageId : 'missingIterKey' } ,
223+ { messageId : 'missingIterKey' } ,
224+ ] ,
225+ } ,
226+ {
227+ code : `
228+ [1, 2, 3].map(function(item) {
229+ return item === 'bar' ? <div>{item}</div> : <span>{item}</span>;
230+ })` ,
231+ errors : [
232+ { messageId : 'missingIterKey' } ,
233+ { messageId : 'missingIterKey' } ,
234+ ] ,
235+ } ,
236+ {
237+ code : `
238+ Array.from([1, 2, 3], (item) => {
239+ return item === 'bar' ? <div>{item}</div> : <span>{item}</span>;
240+ })` ,
241+ errors : [
242+ { messageId : 'missingIterKey' } ,
243+ { messageId : 'missingIterKey' } ,
244+ ] ,
245+ } ,
246+ {
247+ code : `
248+ import { Fragment } from 'react';
249+
250+ const ITEMS = ['bar', 'foo'];
251+
252+ export default function BugIssue() {
253+ return (
254+ <Fragment>
255+ {ITEMS.map((item) => {
256+ return item === 'bar' ? <div>{item}</div> : <span>{item}</span>;
257+ })}
258+ </Fragment>
259+ );
260+ }
261+ ` ,
262+ errors : [
263+ { messageId : 'missingIterKey' } ,
264+ { messageId : 'missingIterKey' } ,
265+ ] ,
266+ } ,
210267 {
211268 code : '[<App />];' ,
212269 errors : [ { messageId : 'missingArrayKey' } ] ,
0 commit comments