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
project: pre-commit hooks #2834
Comments
I've never seen this
It seems kinda like a CI dependency manager and runner that you can also use locally. Is this really worth the trouble? As far as implementation (here are some resources: Creating new hooks, golang), it appears that would involve adding a - id: vet
name: cue vet
description: Validate CUE and other data files.
language: golang
language_version: "1.22" // ?
// since it installs with `go install ./...` I think the cue cli binary would be named `cmd`, so invoke it with that name
// not sure how to override the installer command to make it be named `cue`
entry: cmd Could you do this without modifying the cue repo at all and creating a new repo instead? Unclear. And then in the repo where you want to use it, you would have something like: repos:
- repo: https://github.com/cue-lang/cue
rev: v0.7.1
hooks:
- id: vet
args: ["args to pass to cue vet"] |
I'm surprised, maybe it is huge in the Python community cause we use it fairly extensively at work and there are tons of Python-related projects that provide pre-commit hooks.
I would argue in favor of it, yeah. It is pretty unintrusive to the core codebase and enables adoption. The validation aspect of cue would be nice to have in a pre-commit hook.
Not sure what you mean here. I guess there would need to be some extra files (at least a .pre-commit-hooks.yaml). But I don't think any existing files would have to be changed. |
I made a small POC which you can check out in my fork of cue - https://github.com/gauthsvenkat/cue/blob/master/.pre-commit-hooks.yaml. It turns out all that was needed was just a simple pre-commit-hooks.yaml. |
Hi @gauthsvenkat - one thing I'm not clear on is why changes are required to the CUE project itself. Please can you help to explain that point? If people want to use CUE in their pre-commit hooks in their projects, that's great. Just not clear how/why we need to make a change in the project itself to support that. |
Hey @myitcv ! The way pre-commit works is that the project offering pre-commit hook(s) needs to have a The other option is to maintain a separate repository for the pre-commit-hook(s) (example - ruff). The question is would this repo live in the cue-lang organization? (I think it should). I think both these options are fairly decent approaches and ultimately it boils down to preference. What would be your advice? |
My 2c would be that adding a "dot file" at the root of the main CUE repository feels like unnecessary noise. Note that every extra file in the root directory pushes the README further down the page, and is one of the first files anyone sees when looking at the source. The Go module and ./cmd/cue package are very standard, to the point that one can run a specific version of CUE very easily:
So my impression is that we should not be required to insert a root-level "dot file" to allow pre-commit to do the right thing. Anyone should be able to tell pre-commit to e.g. "run the Go tool at |
@gauthsvenkat unless I'm missing something in your use case, you don't need to have it pre-installed outside of the pre-commit config. For example: # .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: cue-fmt
name: Format CUE files
entry: cue
args: [ fmt ]
types: [ cue ]
language: golang
additional_dependencies:
- cuelang.org/go/cmd/cue@v0.8.2 |
I agree with @mvdan's point and the following response by @riclima pretty much hits the nail. I checked it out and it works well. Based on this discussion, I'm closing this issue (+ related pull request). Thanks for your input guys! Especially @riclima for pointing out I could do this in a much better way. |
Is your feature request related to a problem? Please describe.
I would love to use cue to validate some yamls everytime I make a commit by the use of pre-commit hooks. At the moment, it is possible to run cue commands from a pre-commit hook but that requires cue to be already installed outside the pre-commit config.
Describe the solution you'd like
It would be lovely if the cue repo could offer pre-commit hooks and we can manage everything by just having a cue entry in the pre-commit config.
Describe alternatives you've considered
One option is to call cue commands by setting up a local script that pre-commit has to run. The disadvantage is that cue would need to already be installed on the machine pre-commit runs. It would be hard to adopt since that would require other repository stakeholders to install an additional dependency manually.
The text was updated successfully, but these errors were encountered: