Open AlexHaxe opened 7 years ago
would this also allow to forbid use of using anonymous functions instead of short lambdas? :D
It could act as an anonymous function style check, where it enforces either short lambdas or anonymous functions. For short lambdas it could make exceptions to allow anon functions when they use a curly body.
Writing a check that will detect if an anon function with curly body should be rewritten using short lambdas is a bit more involved. It's easy if there is only a return expression inside curlies, but beyond that one would have to identify cases, where it makes sense to use arrow syntax instead of anon functions.
FWIW, I think forbidding anon functions in favor of short lambdas is a bad idea. There are some special cases where arrow functions don't work well due to their implied return or the inability to specify the return type.
True... maybe not forbid, but just configurable to be shown as a info/warning log :)
well, a checkstyle violation is as good as forbidding something, because the only way to get rid of it is either to suppress it, or to fix your code to be compliant.
So if you run anon function style check with options to enforce arrow syntax, then any place not using arrow notation is in violation of that check and will produce an info, warn or error message (depending on severity setting).
I am not sure how easy it would be to detect cases where arrow syntax can't or shouldn't be used in order to let them pass as compliant.
Ah indeed.
People can also just convert anon functions where short lambda's couldn't be used into actual functions.
Some people might want to prevent developers from using short lambdas.
Not sure what opposite of this check should look like, should it enforce use of short lambdas, e.g. mark every anonymous function as violation? Or should we split it into two individual checks?