question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow single chained methods to be placed on same line

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Bram-Zijpcommented, 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;
    });

0reactions
bitwisemancommented, Aug 15, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrapping chained method calls on a separate line in Intellij for ...
Go to Settings -> Editor -> Code style -> Java and select the Wrapping and Braces tab, then scroll to Chained method calls...
Read more >
newline-per-chained-call - ESLint - Pluggable JavaScript Linter
This rule requires a newline after each call in a method chain or deep member access. Computed property accesses such as instance[something] are...
Read more >
Method Chaining In Java with Examples - GeeksforGeeks
Method Chaining is the practice of calling different methods in a single line instead of calling other methods with the same object ...
Read more >
Method chaining - Wikipedia
Method chaining, also known as named parameter idiom, is a common syntax for invoking multiple method calls in object-oriented programming languages.
Read more >
Java Method Chaining Tutorial - Use Multiple Methods in One ...
Full Java Course: https://course.alexlorenlee.com/courses/learn-java-fastIf you're new to programming, I HIGHLY RECOMMEND solving challenges ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found