Comments (9)
Great @braydonk, thanks for the explanation. I have myself contributed the R intregration to pre-commit and maintain a hook repo with many R hooks, so let me know if I can help. The maintainer of pre-commit is very friendly and willing to help.
from yamlfmt.
This hook is now listed in https://pre-commit.com/hooks.html!
from yamlfmt.
Welcome!
I have never tried pre-commit
before, interesting tool. I don't think there's much value in me adding support for installing this repo directly; I'm hoping to keep this repo as generic as possible so don't want to buy into any specific environment. However making a hook that would run the yamlfmt
binary would be pretty easy. I got it working by doing:
repos:
- repo: local
hooks:
- id: yamlfmt
name: yamlfmt
language: system
entry: yamlfmt
types: [yaml]
I can add instructions for that somewhere in the repo, maybe in the README.
from yamlfmt.
Yes that looks like it would work, I will give it a try.
I think an addition to the README
could be good, otherwise feel free to close this out! Thanks again
from yamlfmt.
While the above suggested local hook works, the lack of a hook repo (i.e. one with .pre-commit-hooks.yaml
) has a few disadvantages:
Depends on the system language
- So if someone new clones a repo with this hook in it,
git commit
will fail if the binary is not on the path. - This also implies it won't work with https://pre-commit.ci.
- The system language is really the fallback, as pre-commit can also not manage the environment and dependencies of this hook. I don't know how go works but if you install two python packages with conflicting dependencies on a user or system level, you can't use them properly (which is why there are virtual environments).
Higher barriers to use the tool with pre-commit
As you said, a local hook works, but people have to be familiar enough with the framework to use local hooks (or find this issue). Also, your tool won't be listed in https://pre-commit.com/hooks.html, which I for example used just now to find a yaml formatter (and there are not really good options).
As far as the buying into a specific environment argument goes, I can understand. But really all you do though is to put a yaml file into your package source. There is no magic and other popular formatters did so, I think it does not create any incompatibilities going forward.
Mirror repo as solution?
An alternative to support pre-commit in this repo is make your tool available through another git repo that contains just the hook. These are called mirror repos and the pre-commit project maintains many of these for popular tools like mypy and others. Not sure under which conditions they accept new mirror repos but I can investigate that for you if you are interested.
from yamlfmt.
Thanks for the perspective on pre-commit. The tool has never been a good fit for me so I do not know much about how people tend to use it. I'll start by quickly addressing some of the concerns:
So if someone new clones a repo with this hook in it, git commit will fail if the binary is not on the path.
That is indeed a barrier, but it seems like it's not super uncommon with a number of pre-commit hooks. For the Python environment its understandable that this is rarely a problem since code is distributed rather than binaries, but it looks like with non-Python tools this is a pretty common pattern.
This also implies it won't work with https://pre-commit.ci/.
That's true, it probably wouldn't. I've never seen this before.
I don't know how go works but if you install two python packages with conflicting dependencies on a user or system level, you can't use them properly (which is why there are virtual environments).
This isn't a concern for the scenario I posted above. yamlfmt
is distributed as a self-sufficient single binary that does not depend on anything else in the system.
As far as the buying into a specific environment argument goes, I can understand. But really all you do though is to put a yaml file into your package source.
Yeah, that's true. The main thing I dislike is that I truly wish I didn't have to clutter the root directory with it. Technically, the root directory of this repo is the actual API package, and I wish I didn't need to clutter it with stuff other than the important things like go.mod
and the actual source files. Often in other languages, source code is in src
, and the root directory is free to have config files dumped into it. With my setup, I really want to try and keep the root directory clean. I am trying not to be unreasonable about it, but it feels like saying yes to one thing means I could be saying yes to lots of things and lead to an unwieldy root directory.
However, it seems the pre-commit framework is quite popular and that there's demand for it. My first choice would be to get it accepted as a mirror repo; I'd happily help with whatever I needed to do to keep that up to date. I can take a look into that and see how to get that sort of thing approved. I'll report back what I can find out.
If it is not possible to get it accepted as a mirror, then I suppose we can put the hook in the root of this repo so people can use it. I'm not interested in deliberately making it harder for people to use the tool, so whether it's through the mirror repo or the yaml file in this repo, I'll try to make it happen.
from yamlfmt.
@jamesbraza @lorenzwalthert Thanks for your patience and great info about pre-commit
. After looking into it I realized that it is far more effort than it's worth to maintain a mirror repo, and have decided just to include a .pre-commit-hooks.yaml
file in this repo directly. It's available on main
and will be in the next release which will be some time in the next 2 weeks.
Unfortunately I could not find a nice way to allow a pre-commit hook to work without having go
installed, so unfortunately that is still a requirement of using the hook.
from yamlfmt.
Going to re-open the issue for now since I've decided to withhold the docs until v0.8.0 is released. I didn't realize pre-commit
warned against using mutable rev
entries like main
. If you would like to try it before v0.8.0 is released, you can add the following to your repos
section:
- repo: https://github.com/google/yamlfmt
rev: main
hooks:
- id: yamlfmt
Will close this after v0.8.0 release.
from yamlfmt.
Needed to do a patch release and this was already in main so it's released in v0.7.1
!
from yamlfmt.
Related Issues (20)
- Unexpected reformatting of block scalar? HOT 2
- Preserve multiline for line ending with \ HOT 4
- Exclude is still a little bit wonky HOT 8
- Feature Request: Optional exclude content from .gitignore HOT 1
- Docs request: `best_width`, YAML library HOT 2
- Request: `indent` being respected beyond top level HOT 1
- Support system-installed yamlfmt HOT 15
- Wrong front matter interpretation HOT 1
- Feature request: allow to retain some empty lines HOT 5
- scan_folded_as_literal not behaving plausible with trailing whitespace HOT 4
- yamlfmt does not respect `excldue` HOT 5
- yamlfmt -dry and yamlfmt (no -dry) have a difference of opinion HOT 1
- Support finding a local yamlfmt config file named `.yamlfmt.yaml` HOT 1
- Simple, single line output when there is a file with incorrect formatting HOT 2
- Do not touch file if there are no changes HOT 5
- Preserve at most X lines setting
- bug: nested arrays are flattened HOT 3
- Get yamlfmt into official Debian repositories
- Infinite adding EOL HOT 4
- Broken stdin operation output in 0.12.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yamlfmt.