Git Product home page Git Product logo

Comments (9)

lorenzwalthert avatar lorenzwalthert commented on May 4, 2024 1

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.

braydonk avatar braydonk commented on May 4, 2024 1

This hook is now listed in https://pre-commit.com/hooks.html!

from yamlfmt.

braydonk avatar braydonk commented on May 4, 2024

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.

jamesbraza avatar jamesbraza commented on May 4, 2024

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.

lorenzwalthert avatar lorenzwalthert commented on May 4, 2024

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.

braydonk avatar braydonk commented on May 4, 2024

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.

braydonk avatar braydonk commented on May 4, 2024

@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.

braydonk avatar braydonk commented on May 4, 2024

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.

braydonk avatar braydonk commented on May 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.