silvermine/eslint-config-silvermine

Can not enforce our standard for chained function calls like promises or underscore chains

jthomerson opened this issue · 1 comments

I haven't found a rule yet that will enforce our standard of indenting chained method calls by one line. Our coding standards require chained function calls to look like this:

   return Q(something)
      .then(function(result) {
         return doSomething(result);
      })
      .then(function(result) {
         return doSomethingElse(result);
      })
      .fail(function(err) {
         logging.error('there was an error', err, err.stack);
      })
      .done();

// or this:

   _.chain(list).pluck('property').sortBy('sortNum')
      .filter(function(val) {
         return val === 42;
      })
      .uniq()
      .value();

As shown above, chains on the same line are okay. But if it's going to pass something that is multi-line as an argument - like these function calls - then it needs to start on the next line. As soon as something starts on the next line, then it should be indented multiple levels. All subsequent chained functions - even if they do not take arguments or have functions (like the call to uniq or done) - should then be on new lines, also indented. This keeps the start of the chain clearly a parent of all of the child processes in the chain and keeps it from appearing as if the chained actions are siblings with the thing that started the chain.

We need a way to enforce that. We may also need to clarify a bit more when it is that you must start something on a newline as opposed to allowing the chain to be on a single line.

Fixed with 57d827c