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.

Long chains of method calls should be formatted one per line

See original GitHub issue

Input

Person
  .select('people.id, people.name, comments.text')
  .joins(:comments)
  .where('comments.created_at > ?', 1.week.ago)

Current output

Person.select('people.id, people.name, comments.text').joins(:comments).where(
  'comments.created_at > ?', 1.week.ago
)

Expected output

Person
  .select('people.id, people.name, comments.text')
  .joins(:comments)
  .where('comments.created_at > ?', 1.week.ago)

or maybe

Person.select('people.id, people.name, comments.text')
      .joins(:comments)
      .where('comments.created_at > ?', 1.week.ago)

I’d be willing to help implement this change if we decide it’s a good idea, however I’d need a little guidance on how to go about doing that.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:33
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
kddnewtoncommented, Dec 2, 2020

Hot damn. This is finally closed. It’ll be out in the next release.

I’d imagine there will be more follow up on it, but we can open new issues.

5reactions
AluisioASGcommented, May 29, 2019

It seems like this could help with another case:

Input

requested_locale_tags.map { |locale_tag| TwitterCldr::Shared::Locale.parse(locale_tag) }.reject { |locale| locale.language == 'und' }

Current Output

requested_locale_tags.map do |locale_tag|
  TwitterCldr::Shared::Locale.parse(locale_tag)
end.reject { |locale| locale.language == 'und' }

Expected output

requested_locale_tags
  .map { |locale_tag| TwitterCldr::Shared::Locale.parse(locale_tag) }
  .reject { |locale| locale.language == 'und' }

Using the expected output as input yields the same result.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: Formatting Chained Methods - Ken Goettler
Chained method calls might be too long for a single line. ... To keep a chained method compliant with a 79-character line length,...
Read more >
Chained method calls indentation style in Python [duplicate]
This is a case where a line continuation character is preferred to open parentheses. ShortName.objects.distinct() \ .filter().values() ...
Read more >
JavaScript Code Styling Best Practices — Method Calls and ...
In this article, we'll look at formatting chain of method calls, the use of the Array constructor and the use of other less...
Read more >
489444 – [Formatter] Chained method calls when ... - Bugs
Various builder libraries would automatically format one .withX(x) per line with this convention as well, and Stream objects do the right thing by...
Read more >
C# at Google Style Guide | styleguide
For function definitions and calls, if the arguments do not all fit on one line they should be broken up onto multiple lines,...
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