getify / eslint-plugin-proper-arrows

ESLint rules to ensure proper arrow function definitions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extend definition of trivial to include comparisons

opened this issue · comments

It would be nice to allow x => x < 0 and x => x > 0 as trivial functions, with other comparison operators too. These cannot ever throw and don't really need fancy names or parameters.

The boolean operators && and || should be allowed too IMHO.

Note that this does not include all arithmetic expressions, as for example x / y could still throw.

These feel very "not trivial" to me, not in the complexity sense but in the readability sense, especially the comparison operators like >, >=, <, and <=, given how visually similar those are to the => arrow designator.

Added a comment under #28 that mostly covers this, but I think it'd be fair to include these in the trivial category because I don't think it's reasonable to have to apply a name or more-complicated parameter name to functions that are just doing comparisons.

I replied in the other thread to explain my thinking around "trivial". The more I think about it the more x => x <= y is absolutely not "trivial" IMO, for the reasons stated there.