Open marekkaczkowski opened 8 years ago
Definitely, this would be extremely useful. It is also the recommendation of AirBnB Javascript guidelines: https://github.com/airbnb/javascript#whitespace--chains
Use indentation when making long method chains (more than 2 method chains)
And makes all sense in terms of readibility
@joaobarcia
This is an interesting guideline. In this "good" example:
$('#items')
.find('.selected')
.highlight()
.end()
.find('.open')
.updateCount();
How are the indents for .hightlight()
and .end()
determined to be 4 instead of 2? If anything there have been more requests for unindenting - see #482.
@bitwiseman I think they are increasing identation after each selector to make it easier to check what is being 'highlighted' and 'updated the count'.
But if that should be done or not is probably a whole other question by itself :P
Nevertheless, the part of "break chain if chain longer than x" I believe would be quite useful.
There shoud be option to set max num of chained methods before breaking it:
Eg:
I see no sense in breaking when there is only 1 meth (it's not a chain in this case :)). So maybe default behaviour should be: if there is more than 1 chained meth then perform breaking.