Skip to content

Commit

Permalink
Fix for #835 and #836
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Mar 4, 2021
1 parent da580de commit c8c7192
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

### Changed

- [#835](https://github.com/prettier/plugin-ruby/issues/835) - valscion, kddeisz - Array splat operator should not get moved by leading comments.
- [#836](https://github.com/prettier/plugin-ruby/issues/836) - valscion, kddeisz - Array splat operator should not get moved by trailing comments.

## [1.5.3] - 2021-02-28

### Changed
Expand Down
9 changes: 8 additions & 1 deletion src/ruby/nodes/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,16 @@ function printArgsAddStar(path, opts, print) {
// *values
// ]
//
// or if we have an array like:
//
// [
// *values # comment
// ]
//
// then we need to make sure we don't accidentally prepend the operator
// before the comment.
docs[1].parts[2] = concat(["*", docs[1].parts[2]]);
const index = node.body[1].comments.filter(({ leading }) => leading).length;
docs[1].parts[index] = concat(["*", docs[1].parts[index]]);
} else {
// If we don't have any comments, we can just prepend the operator
docs[1] = concat(["*", docs[1]]);
Expand Down
15 changes: 15 additions & 0 deletions test/js/ruby/nodes/method.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,28 @@ describe("method", () => {
const content = ruby(`
foo(
# comment
# another comment
# even more comment
*values
)
`);

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

test("with trailing comments", () => {
const content = ruby(`
foo(
# comment
# another comment
*values # a trailing comment
# a whole other comment
)
`);

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

test("with block", () => expect("foo(*bar, &block)").toMatchFormat());

test("with comments and block", () => {
Expand Down

0 comments on commit c8c7192

Please sign in to comment.