Skip to content
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

break_chained_methods behaviour #809

Open
marekkaczkowski opened this issue Nov 18, 2015 · 3 comments
Open

break_chained_methods behaviour #809

marekkaczkowski opened this issue Nov 18, 2015 · 3 comments

Comments

@marekkaczkowski
Copy link

There shoud be option to set max num of chained methods before breaking it:

Eg:

"break_chained_methods": 2

this.$("#fileName").val().addClass("disabled")
    .prop("disabled", true)

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.

@joaobarcia
Copy link

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

@bitwiseman
Copy link
Member

@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.

@joaobarcia
Copy link

joaobarcia commented Aug 16, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants