Skip to content

Commit

Permalink
Fix for #929
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Sep 29, 2021
1 parent 6114fcb commit 882f548
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
- [#957](https://github.com/prettier/plugin-ruby/issues/957) - azz, kddnewton - Make it so that the format pragma does not have to be on the first line of the file.
- [#895](https://github.com/prettier/plugin-ruby/issues/895) - rsslldnphy, kddnewton - Ensure quotes are properly escaped in the content of a hash value for HAML attributes.
- [#900](https://github.com/prettier/plugin-ruby/issues/900) - rsslldnphy, kddnewton - Ensure that in a HAML line where you have interpolation inside of a tag content that you print it properly.
- [#929](https://github.com/prettier/plugin-ruby/issues/929) - ryanb, kddnewton - Deeply nested blocks should not break their call chains.

## [1.6.1] - 2021-06-30

Expand Down
16 changes: 16 additions & 0 deletions src/ruby/nodes/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,22 @@ export const printMethodAddBlock: Plugin.Printer<ChainedMethodAddBlock> = (
(node.chain || 0) >= 3 &&
node.breakDoc
) {
// This is pretty specialized behavior. Basically if we're at the top of a
// chain but we've only had method calls without arguments and now we have
// a method call with a block, then we're effectively trying to call a
// method with arguments that is nested under a bunch of stuff. So we group
// together to first part to make it so just the block breaks. This looks
// like, for example:
//
// Rails.application.routes.draw do
// root 'articles#index'
// resources :articles
// end
//
if (node.callChain === node.chain) {
return [group(indent(node.breakDoc)), group(blockDoc)];
}

return ifBreak(group(indent(node.breakDoc.concat(blockDoc))), [
callDoc,
blockDoc
Expand Down
10 changes: 1 addition & 9 deletions test/js/ruby/nodes/calls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,7 @@ describe("calls", () => {
end
`);

const expected = ruby(`
aaa
.bbb
.ccc
.ddd
.eee { ${block} }
`);

return expect(content).toChangeFormat(expected);
return expect(content).toMatchFormat();
});

test("tons of calls that fit on one line", () => {
Expand Down

0 comments on commit 882f548

Please sign in to comment.