Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-format YAML with prettier and pre-commit #2728

Closed

Conversation

sgibson91
Copy link
Member

@sgibson91 sgibson91 commented Oct 14, 2022

Summary

In #2726, there was an issue with the book build due to incorrectly formatted YAML. @aleesteele and I suggested it would be a good idea to enforce YAML formatting since it is a tricky thing to hand-edit and book build failures are not super informative.

List of changes proposed in this PR (pull-request)

  • Configured pre-commit
    • This is a tool that can be used locally to perform certain, specified actions just before git creates a commit
    • It can also be used in CI so that, for any open Pull Requests, if the files would have been edited when running pre-commit locally, an extra commit applying these changes would be added to the PR
  • Configured prettier, which will be executed by pre-commit and perform the auto-formatting
    • Provided a .prettierignore file to restrict which files will be auto-formatted to only YAML. We can change this file as needed to include other file we would like to be auto-formatted.

This combination of pre-commit and prettier is a very common workflow among open source projects.

What should a reviewer concentrate their feedback on?

There will be three commits on this repo:

  • The two original commits I made containing the pre-commit and prettier configuration files described above
  • An automatically generated commit applying prettier auto-formatting to YAML files, by pre-commit
    • [link TBA]
  • Does everything look ok?

Acknowledging contributors

@netlify
Copy link

netlify bot commented Oct 14, 2022

Deploy Preview for the-turing-way ready!

Name Link
🔨 Latest commit 39e3e9d
🔍 Latest deploy log https://app.netlify.com/sites/the-turing-way/deploys/634960ae421a660009a3c98f
😎 Deploy Preview https://deploy-preview-2728--the-turing-way.netlify.app/communication/binder/zero-to-binder
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@sgibson91 sgibson91 marked this pull request as draft October 14, 2022 13:18
@sgibson91
Copy link
Member Author

sgibson91 commented Oct 14, 2022

Pre-commit doesn't auto-add correction commits for prettier and it seems this is intentional (see refs below). So this approach will only work for those using pre-commit locally.

@sgibson91 sgibson91 removed the request for review from aleesteele October 14, 2022 13:21
@sgibson91 sgibson91 closed this Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant