forked from biomejs/biome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lint/noArrayIndexKey): false negative in template literals (biome…
- Loading branch information
1 parent
a15397c
commit e39e1b1
Showing
8 changed files
with
553 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 66 additions & 42 deletions
108
crates/biome_js_analyze/tests/specs/suspicious/noArrayIndexKey/invalid.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,134 @@ | ||
import { Children, cloneElement } from "react"; | ||
|
||
something.forEach((Element, index) => { | ||
<Component key={index}>foo</Component>; | ||
<Component key={index}>foo</Component>; | ||
}); | ||
something.forEach((element, index, array) => { | ||
<Component key={index}>foo</Component>; | ||
<Component key={index}>foo</Component>; | ||
}); | ||
things.filter((thing, index) => { | ||
otherThings.push(<Hello key={index}>foo</Hello>); | ||
otherThings.push(<Hello key={index}>foo</Hello>); | ||
}); | ||
|
||
something.forEach((Element, index) => { | ||
<Component key={index} />; | ||
<Component key={index} />; | ||
}); | ||
something.forEach((element, index, array) => { | ||
<Component key={index} />; | ||
<Component key={index} />; | ||
}); | ||
things.filter((thing, index) => { | ||
otherThings.push(<Hello key={index} />); | ||
otherThings.push(<Hello key={index} />); | ||
}); | ||
things.reduce( | ||
(collection, thing, index) => collection.concat(<Hello key={index} />), | ||
[] | ||
(collection, thing, index) => collection.concat(<Hello key={index} />), | ||
[] | ||
); | ||
|
||
React.Children.map(this.props.children, (child, index) => | ||
React.cloneElement(child, { key: index }) | ||
React.cloneElement(child, { key: index }) | ||
); | ||
|
||
React.Children.forEach(this.props.children, function (child, index) { | ||
return React.cloneElement(child, { key: index }); | ||
return React.cloneElement(child, { key: index }); | ||
}); | ||
|
||
Children.map(this.props.children, (child, index) => | ||
cloneElement(child, { key: index }) | ||
cloneElement(child, { key: index }) | ||
); | ||
|
||
Children.forEach(this.props.children, function (child, index) { | ||
return cloneElement(child, { key: index }); | ||
return cloneElement(child, { key: index }); | ||
}); | ||
|
||
Children.forEach(this.props.children, function (child, index) { | ||
const foo = cloneElement(child, { key: index }); | ||
return foo; | ||
const foo = cloneElement(child, { key: index }); | ||
return foo; | ||
}); | ||
|
||
function Test(props) { | ||
return Children.map(props.children, function (child, index) { | ||
return cloneElement(child, { key: index }); | ||
}); | ||
return Children.map(props.children, function (child, index) { | ||
return cloneElement(child, { key: index }); | ||
}); | ||
} | ||
|
||
things.map((thing, index) => React.cloneElement(thing, { key: index })); | ||
|
||
things.flatMap((thing, index) => { | ||
return <Component key={index} />; | ||
return <Component key={index} />; | ||
}); | ||
|
||
Array.from(things, (thing, index) => { | ||
return <Component key={index} />; | ||
return <Component key={index} />; | ||
}); | ||
|
||
const mapping = { | ||
foo: () => things.map((_, index) => <Component key={index} />), | ||
foo: () => things.map((_, index) => <Component key={index} />), | ||
}; | ||
|
||
class A extends React.Component { | ||
renderThings = () => things.map((_, index) => <Component key={index} />); | ||
renderThings = () => things.map((_, index) => <Component key={index} />); | ||
} | ||
|
||
const Component1 = () => things.map((_, index) => <Component key={index} />); | ||
|
||
const Component2 = () => things.map((_, index) => <Component key={index} />); | ||
|
||
function Component3() { | ||
return things.map((_, index) => <Component key={index} />); | ||
return things.map((_, index) => <Component key={index} />); | ||
} | ||
|
||
function Component4() { | ||
let elements = things.map((_, index) => <Component key={index} />); | ||
if (condition) { | ||
elements = others.map((_, index) => <Component key={index} />); | ||
} | ||
return elements; | ||
let elements = things.map((_, index) => <Component key={index} />); | ||
if (condition) { | ||
elements = others.map((_, index) => <Component key={index} />); | ||
} | ||
return elements; | ||
} | ||
|
||
function Component5({ things }) { | ||
const elements = useMemo( | ||
() => things.map((_, index) => <Component key={index} />), | ||
[things] | ||
); | ||
return elements; | ||
const elements = useMemo( | ||
() => things.map((_, index) => <Component key={index} />), | ||
[things] | ||
); | ||
return elements; | ||
} | ||
|
||
function Component6({ things }) { | ||
const elements = useMemo( | ||
() => things.map((_, index) => <Component key={index} />), | ||
[things] | ||
); | ||
return elements; | ||
const elements = useMemo( | ||
() => things.map((_, index) => <Component key={index} />), | ||
[things] | ||
); | ||
return elements; | ||
} | ||
|
||
function Component7() { | ||
return ( | ||
<HoC> | ||
{({ things }) => things.map((_, index) => <Component key={index} />)} | ||
</HoC> | ||
); | ||
return ( | ||
<HoC> | ||
{({ things }) => things.map((_, index) => <Component key={index} />)} | ||
</HoC> | ||
); | ||
} | ||
|
||
function Component8() { | ||
return ( | ||
<HoC> | ||
{({ things }) => things.map((_, index) => <Component key={`test-key-${index}`} />)} | ||
</HoC> | ||
); | ||
} | ||
|
||
function Component9() { | ||
return ( | ||
<HoC> | ||
{({ things }) => things.map((_, index) => <Component key={"test" + index} />)} | ||
</HoC> | ||
); | ||
} | ||
|
||
function Component10() { | ||
return ( | ||
<HoC> | ||
{({ things }) => things.map((_, index) => <Component key={"test" + index + "test"} />)} | ||
</HoC> | ||
); | ||
} |
Oops, something went wrong.