electrovir / prettier-plugin-multiline-arrays

Prettier plugin to force array elements to wrap onto new lines.
https://www.npmjs.com/package/prettier-plugin-multiline-arrays
Creative Commons Zero v1.0 Universal
135 stars 6 forks source link

An unnecessary empty line gets added when a comment is present in a JSON array #14

Closed giact closed 2 years ago

giact commented 2 years ago

When a JSON like this is Prettied...

{
  "data": [
    "one",
    // comment
    "two"
  ]
}

... it gets formatted into this:

{
  "data": [
    "one",
    // comment
    "two"

  ]
}

I added a test for it here:

giact/prettier-plugin-multiline-arrays@07e6eba1f815db65e0d6443dc78fedfcde857675

eric-coker commented 2 years ago

Related issue is that if there are no elements in the array but there is a comment, the plugin errors out:

{
  "data": [
    // comment
  ]
}

Error output: Found "[" but first indent child was not a line.

electrovir commented 2 years ago

Thanks both of you for the feedback! The fix for these are in progress now. @eric-coker I've already figured out a valid fix for your issue. @giact I'm still working on a fix for your issue.

Unless some other big issue comes up, the next release of this package should have the fix for both of these issues. I will update this issue when that gets out.

electrovir commented 2 years ago

Resolved in the now-published version v1.1.1. Please re-open this ticket if that does not work for you! (All test are passing though so I think we're good.)

eric-coker commented 2 years ago

Awesome. Thanks for the great plugin!

giact commented 2 years ago

I have been using it for a few days, and no other issues with comments inside arrays, so far. Thanks for the fix! 👍🏻