eslint-plugin-lodash
eslint-plugin-lodash copied to clipboard
False positive for prefer-lodash-chain with _.range?
I have this function to produce nPoints of data on a curve:
const generateData = (nPoints: number) =>
_.range(0, nPoints).map(i => {
// Inverse tanh on (-0.9, +0.9); just something to get a distribution.
const x = (1.9 * i) / nPoints - 0.95;
const atanh = Math.log1p(x) - Math.log1p(-x);
return {row: i, atanh};
});
The prefer-lodash-chain rule flags this because of the _.range followed by the map. It's not clear what I'm supposed to replace this with, though. It would have to be something like _(_.range(0, nPoints)).map(...).value(), which doesn't seem like an improvement.
@danvk You can you _.times instead. https://lodash.com/docs/4.17.15#times
_.range(0, nPoints).map(i => {
_.times(nPoints, i => {