-
-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
func-style
like rule
#3
Comments
When writing in ES5, I prefer the So I'm rather against enforcing it. |
Arrow functions would be excluded (that's an option even in ESLints plugin). |
With arrow function excluded... then maybe yeah. var fn = _.curry(function (...) { ... }); But yeah, why not. |
The eslint rule (in The ESLint behavior makes sense to me, but it doesn't make an exception for variables that are later reassigned. That is a rare occurrence, but if you are already in the habit of using function declarations, then Jumping back to arrow functions for a second: I think they should only be allowed for simple functions with implicit returns // OK
var square = x => x * x;
// NOT OK
var complexFunc = (x, y) => {
if (x) {
return y * 2;
} else {
return y * 3;
}
}
// I would prefer
function complexFunc(x, y) {
if (x) {
return y * 2;
} else {
return y * 3;
}
} Exceptions for arrow funcs should be made if they use any of |
A bit dated, but: https://kangax.github.io/nfe/ |
Why? I prefer arrow functions for everything as they're lexically scoped (no dumb implicit |
Well, if you don't need the lexical binding there's no advantage. Actually there may be a performance hit if arrow functions are transpiled (to accommodate the binding, etc) - though that might not even true - not sure if Babel is smart enough to avoid binding if it isn't needed. Still, I am not dogmatic about it. This came up because I noticed we're mixing styles across the AVA codebase, and was wondering if there's a good set of rules we can use to describe our preferred style (whatever that is). |
Yes, I like to figure out a good default we can enforce for this too. I don't feel super strongly either way, just slightly prefer arrow functions. Also nested function declarations looks messy and having everything as variables looks cleaner and more consistent. // @vdemedes @novemberborn @SamVerschueren
Still the advantage of
Node.js 4 supports arrow functions though. So I don't see it as a big problem going forward. |
I tend to use a mix of syntaxes. E.g. in In other files where there are few declarations I'm more likely to use If I'd have to choose I'd prefer |
I agree that ES2015 exports should use a normal function. This: export function foo() {} Looks better than this: export const foo = () => {} |
Related to this (old-ish) issue, I've recently implemented and submitted related PR to eslint, not realizing it had no chance of being accepted: eslint#16159 . I too prefer the declaration style, with the exception where reassignment is desired, where fat arrow functions look better to me. The current |
See: http://eslint.org/docs/rules/func-style
My personal preference is to prefer
declaration
style, as it allows hoisting (and just looks better to me). The only issue is when you want to reassign:ESLint's
func-style
rule does not accommodate the above exception when preferring declarations, so it is impractical to enforce.Note:
You can get around ELint's rule by doing this:
But that feels impractical.
Do we feel it's worth enforcing
func-style
in XO? Should we use the builtin plugin to do so, or make our own that is a bit more permissive.The text was updated successfully, but these errors were encountered: