0

I went through the eslint doc list wanting to find a rule to give warning / error or even better auto fix to have a return infront of res sometimes people only do res.json({blah}) instead return res.json({blah}) personally really prefer having a return in front.

Did I miss the rule in eslint when I go through the list or there isn't such rule available?

Thanks in advance for any suggestions.

Dora
  • 6,776
  • 14
  • 51
  • 99
  • 1
    You don't need a `return` statement with `res.whatever` unless you're trying to do an early return, that's why out of the box `ESLint` won't have a rule for this case. Unless you can find a plugin for it that follows this approach, you might need to create a custom rule/plugin if you want `ESLint` to pick this up. – goto Aug 27 '20 at 10:43
  • @goto1 got it, it's just everyone's writing is different, some does include return some don't so trying to make it consistent in a way...I guess my best approch is search show to custom a eslint plug in eh – Dora Aug 27 '20 at 10:51
  • 1
    If you're doing an early return, then it makes sense to have it there, but if your'e not, then it makes no difference. Middleware functions don't return anything, they either call `res` or `next`, so the `return` statement makes no difference, and the people that use the `return` statement without the need for an early return are doing an unnecessary step, most likely because they saw it somewhere and think that it's needed. – goto Aug 27 '20 at 10:57

0 Answers0