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

Allow single chained methods to be placed on same line #293

Open
Qantas94Heavy opened this issue Jun 13, 2013 · 6 comments
Open

Allow single chained methods to be placed on same line #293

Qantas94Heavy opened this issue Jun 13, 2013 · 6 comments

Comments

@Qantas94Heavy
Copy link

I'd like an option to allow single chained methods to be placed on same line, as in if there is only two calls, then those two are placed on the same line. Here are some examples of code that doesn't really look good with the current "break lines on chained methods" option:

this._foo = new Date()
    .getTime();

$(document)
    .ready(function () {
        // function code here
    });

Would this be feasible or is this just too much work for little gain?

@bitwiseman
Copy link
Member

You can turn off "break lines on chained methods", and then turn on "preserve newlines". This won't enforce the structure, but it will preserve what you have:

// input - expected to be unchanged after beautify
this._foo = new Date().getTime().milliseconds();

// other input - also expected to be unchanged
this._foo = new Date().getTime()
    .milliseconds();

Combine this with line wraps and you should get reasonable chains. If what I'm describing doesn't sound sufficient, could you give some more extensive examples? Include input, current output, and what you'd like to see.

@gilazo
Copy link

gilazo commented Feb 13, 2015

I believe I'm experiencing something similar.

I have the following code:

angular
    .module("app", []);

When I run beautify I get the following:

angular.module("app", []);

I want my first example to be unaffected by beautifying.

Any tips or hints?

@bitwiseman
Copy link
Member

@gilazo - set break_chained_methods option to true.

@Bram-Zijp
Copy link

Bram-Zijp commented Sep 6, 2016

I have the same issue and turning off "break lines on chained methods" is not possible for in my case.
Input:

daisy.chain().me().please();

undefined._foo = new Date().getTime();

$(document).ready(function () {
    // function code here
});

$('foo').on('focus blur', function () {
    var foo = bar;
}).on('click', function () {
    var bar = foo;
});

output:

daisy.chain()
    .me()
    .please();

undefined._foo = new Date()
    .getTime();

$(document)
    .ready(function() {
        // function code here
    });

$('foo')
    .on('focus blur', function() {
        var foo = bar;
    })
    .on('click', function() {
        var bar = foo;
    });

desired output:

// i can live with this:
daisy.chain()
    .me()
    .please();
// i believe this is the latest convention:
daisy
    .chain()
    .me()
    .please();


undefined._foo = new Date().getTime();

$(document).ready(function() {
    // function code here
});

$('foo')
    .on('focus blur', function() {
        var foo = bar;
    })
    .on('click', function() {
        var bar = foo;
    });

@joaobarcia
Copy link

Related to #809 ?

@bitwiseman
Copy link
Member

@joaobarcia - Sure. #809 would be the more flexible setting.

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

5 participants