pin-github-action icon indicating copy to clipboard operation
pin-github-action copied to clipboard

Format YAML without conflict with `prettier`

Open MPV opened this issue 2 years ago • 3 comments

Hi, Would it be possible to output YAML in a way that doesn't clash with prettier?

pin-github-actions wants files formatted like this:

-    needs: [changed-files]
+    needs: [ changed-files ]

prettier formats them back like this:

-    needs: [ changed-files ]
+    needs: [changed-files]

MPV avatar Nov 24 '23 13:11 MPV

I'm facing a similar issue - more generally I would expect this tool to not change formatting whatsoever. Going for prettier formatting might clash with other formatters (or configurations) used elsewhere.

I'm encountering the following specific unexpected reformatting:

  example: >
-   sit amet justo donec enim diam vulputate ut pharetra sit amet aliquam id diam
-   maecenas ultricies mi eget mauris pharetra et ultrices neque ornare aenean
+   sit amet justo donec enim diam vulputate ut pharetra sit amet aliquam id diam maecenas ultricies mi eget mauris pharetra et ultrices neque ornare aenean

ericcornelissen avatar Dec 19 '23 08:12 ericcornelissen

more generally I would expect this tool to not change formatting whatsoever.

I agree. 🙂

MPV avatar Dec 20 '23 16:12 MPV

Unfortunately this is a side effect of parsing the YAML file, then serializing it again. We could try parsing to get the data, then using search + replace on the source file to maintain formatting but that could be brittle.

If anyone wants to try raising a PR with that approach to preserve formatting, I'd be happy to review

mheap avatar Dec 20 '23 17:12 mheap