Open lukecarr opened 2 years ago
I did try using something a while back, but the problem was managing PRs. I wanted to keep things easy for contributors, without them having to install and run stuff locally. This was before GitHub actions came about, so I could revisit this now, and have a style guide that runs when a PR is opened, maybe with issues being either auto-fixed, or added as a comment on the PR
I wanted to keep things easy for contributors, without them having to install and run stuff locally.
That makes perfect sense.
Admittedly I've never used Prettier in a GitHub action to actually make changes, only to check and reject/accept PRs.
It looks like the prettier-action can do all of that. Probably would be sensible (and marginally more performant) to use only_changed
so it will skip linting unmodified files. (Although this means you probably want to do a one-off, manual commit to lint the existing source.
Something like:
name: Continuous Integration
on:
pull_request:
branches: [master]
jobs:
prettier:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Prettify code
uses: creyD/prettier_action@v4.2
with:
prettier_options: --write **/*.md *.md
only_changed: True
Awesome, thanks for snippet. I'll try this out this evening and hopefully get a proper styleguide implemented :)
I think it goes without saying that consistent and reproducible formatting on any project (especially one this popular) is always welcome.
I noticed in the
ATTRIBUTIONS.md
that you're (most likely) using a local installation of Prettier (<!-- prettier-ignore-start -->
). I think that adding a very minimal package.json with a pinned Prettier version included as a devDep could improve contributability(?).However, I've scanned the existing Markdown source with Prettier and there were quite a few recommendations for each file, so I'd be curious to know if you're using a customised config locally, or not using it at all (and the ignore tags I found are ancient relics)!