Rule proposal: no-functions-without-parameters
jfmengels opened this issue · 1 comments
jfmengels commented
Rule proposal: Forbid functions that do not take parameters.
Functions that do not take parameters are either
- using
arguments
to do some odd behavior. There is a different rule for that, but still - has side-causes : uses variables besides closure variables or parameters
- always return the same value: The function call could be replaced by the value itself.
I do wonder about methods that are not assigned, like for the following example
const count = values
.map(() => 1)
.reduce((a, b) => a + b, 0);
This should be allowed, and I think that having the function not be assigned and not declared on its own (i.e., passed as an expression) should be allowed, but I'm not sure whether this should be behind a flag or not.
If people are watching, would gladly get some feedback on this :)
cobaltt7 commented
const count = values .map(() => 1) .reduce((a, b) => a + b, 0);
A better use case would be using .sort
and Math.random
to randomize an array like so: arr.sort(() => Math.random() - 0.5)