DEV Community

sabyanna
sabyanna

Posted on

Multiple line array functions without 'return'

What to do when lintern tells you that the line is too long, but you only have one line of code to return.

Problem:

So I have a line of code:

const  someLongName = aLotOfstuff.filter(longStuff  =>  longStuff.longField === 'some very long string);
Enter fullscreen mode Exit fullscreen mode

Linter warns me that this line is longer than it should be, so I need to break it up somehow. I could go with thee return route:

const  someLongName = aLotOfstuff.filter(longStuff  =>  {
    return longStuff.longField === 'some very long string);
});
Enter fullscreen mode Exit fullscreen mode

but that's not nice is it? I want to avoid using the unnecessary 'return'.

Solution:

So how can I do that? Youn can just use brackets:

const  someLongName = aLotOfstuff.filter(longStuff  =>  (
    longStuff.longField === 'some very long string);
));
Enter fullscreen mode Exit fullscreen mode

Top comments (0)