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

Add support for pre-commit #465

Closed
wants to merge 2 commits into from
Closed

Conversation

Copy link
Contributor

@ArturKlauser ArturKlauser commented Dec 29, 2019

pre-commit is infrastructure to easily set up running any set of tools as git pre-commits on a repo. A tool only needs to provide a hook description (.pre-commit-hook.yaml) in its repo to become usable by the pre-commit infrastructure.

Here I'm adding this hook description, which makes shfmt easily usable by pre-commit (see added example in README.md). I'm also turning pre-commit loose on this repo and configure it to run automatically on the Github Actions CI pipeline on every push and pull request.

Changes:
* .pre-commit-hooks.yaml: defines this shfmt repo as a hook for pre-commit
* .github/workflows/release.yml: make sure .pre-commit-hooks.yaml is in sync
  with release tag
Changes:
* .pre-commit-config.yaml: uses pre-commit on this repo
* .github/workflows/test.yml: run pre-commit in Github Actions CI pipeline
@mvdan
Copy link

@mvdan mvdan commented Dec 30, 2019

I'm conflicted about this PR. I see the value in pre-commit hooks, but this adds nearly a hundred lines of code for me to maintain. I'm not sure I see the point of all this machinery, when in reality running shfmt as a pre-commit hook is pretty trivial.

In the past, I've welcomed "downstream" contributions like packaging shfmt for Linux distros, but I haven't been involved simply because there is too much work and I can't keep up with the 20+ ways to distribute software. I simply publish git tags with binaries, and a Docker image, since that last bit is very little work for me and does seem like a very popular request.

I think pre-commit falls under the kind of downstream work that I'd prefer others to maintain. If someone must maintain these files, it should be possible for it to happen in a separate git repository. We can then link that from https://github.com/mvdan/sh#related-projects.

@ArturKlauser
Copy link
Author

@ArturKlauser ArturKlauser commented Dec 30, 2019

Up to you. If you're not interested feel free to close the PR.

@mvdan
Copy link

@mvdan mvdan commented Dec 30, 2019

Thanks for understanding. I'll close this for now, but I'm still happy to add links to other repos or projects in the README.

@asottile
Copy link

@asottile asottile commented Jan 8, 2020

The only necessary file is .pre-commit-hooks.yaml -- would you be more amenable to a PR with just that file?

Not sure why the other stuff was proposed here :S

name: shfmt shell scripts
description: Format shell scripts with shfmt running in Docker
language: docker_image
entry: mvdan/shfmt:v3.0.0
Copy link

@asottile asottile Jan 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be language: go and entry: shfmt

@asottile
Copy link

@asottile asottile commented Jan 8, 2020

(with my recommendations and only shipping .pre-commit-hooks.yaml there should be zero maintenance as the config format is stable)

@mvdan
Copy link

@mvdan mvdan commented Jan 9, 2020

I mean, sure, I can add a short yaml file with some simple metadata. I'm not sure why that's necessary or useful, though, or why it couldn't be in another repo.

Edit: To clarify, I just mean in the context of #465 (comment). Running shfmt in CI or as part of scripts is already trivial, and as a rule I don't write downstream packages. I don't see why I should break that rule here.

@mvdan mvdan mentioned this pull request Feb 17, 2020
@mvdan mvdan mentioned this pull request Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants