Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upIndentation of callbacks #480
Comments
This comment has been minimized.
This comment has been minimized.
|
This is probably a bug in eslint. If you're interested in getting this fixed, I recommend opening an issue on their bug tracker: https://github.com/eslint/eslint The rule we use is: Honestly, though, if I were you, I'd name the function in an argument list that long, so you can just refer to it in the list. Cleaner than inlining it. |
feross
closed this
Apr 1, 2016
feross
added
the
bug
label
Apr 1, 2016
This comment has been minimized.
This comment has been minimized.
|
Is it a bug though? I think that the first example looks wrong since the function body is indented the same as the parameter list. I think that it should be indented one more step... someFunction('very', 'very', 'long', 'parameters',
'list', 'and', 'the', 'callback', function () {
console.log('yep')
}) |
This comment has been minimized.
This comment has been minimized.
|
Well, maybe it's a little far-fetched example. So here is the actual code: fst.transition(INIT, [isCmd('get'), doHavePermissions(),
isActive()], STARTED, function * (next) {
// ...
})It's a finite state transducer rule which says "If the state is INIT and the message complies to the list of filters, go to the state STARTED and execute following middleware". The array of filter can be long sometimes, but inlining it makes the rule easy to reason about. So, what I'm trying to say is that this scenario is still common. Btw, I actually like the @LinusU suggestion. This is a way to go. However, allowing this as well as the second example from the post is not very intuitive. |
baygeldin commentedMar 31, 2016
Hi. This piece of code throws me an error of wrong indentation:
While this is OK:
However it's not very readable, especially when there are some real code with really long parameters written in multiple lines. I ran into this when I've been writing some middleware for koa.
I thought that maybe #208 is related to this, but it seems like it's something different.