commitlint
commitlint copied to clipboard
Support the Pre-Commit framework with a .pre-commit-hooks.yaml file
~~Expected Behavior~~ Question/Feature request
This is more a blatant question and feature request:
Would a basic config for the pre-commit framework be possible, and if so, even desired for the repo to have?
It would be implemented by having a .pre-commit-hooks.yaml
file in the root of the repo, that pre-commit can be pointed at in other projects to implement commit linting.
Possible Solution
Adding a .pre-commit-hooks.yaml
to the project to be able to be used by the pre-commit tool simply. A number of projects, such as Prettier and Python's Black provide such files to allow the tool to be transparently installed and run as git hooks.
- Prettier's
.pre-commit-hooks.yaml
- Black's
.pre-commit-hooks.yaml
Context
Pre-commit is a tool for declaratively managing git hooks in a repo, not unlike husky. The major difference is that pre-commit manages pulling down and transparently installing the tools itself, regardless of language, allowing projects to use software that don't necessarily suit being a part of a project's dependencies.
Many projects provide a .pre-commit-hooks.yaml
themselves, for just this reason.
While Husky is the gold standard in the JS world, it's not ideal for multi-language projects, as you either need to set up a dedicated package.json in the root of the repository, or even less elegantly, configure it just in sub-folder, likefrontend/
for example. I believe commit linting is such a powerful tool, that anything we can do to make it more widespread is a big win, and would lead to wider spread adoption outside of just javascript environments.
Incidentally, I have run across a small repo that achieves just this, though a first party equivalent would be a much healthier signal.
Hey @tkcranny , thanks for the suggestion and providing context.
I guess this could help certain users. @byCedric what do you think?
Wanted to +1 this
I found a repo mirroring commitlint
to provide a .pre-commit-hooks.yaml
: https://github.com/alessandrojcm/commitlint-pre-commit-hook
IMHO its better to have the .pre-commit-hooks.yaml
directly in the repo to use. +1 for this request.
But currently (at least for me) the hook does not work: #2254
Hi @Cielquan, I did actually link to alessandrojcm/commitlint-pre-commit-hook in the last sentance of the ticket 😛
I agree commitlint should support it with a .pre-commit-hooks.yaml
file for sure.
An interesting change Prettier has done recently has been to extract the yaml file (and related npm stuff) for the pre-commit hook into its own repo. This is still a first-party solution though, so it's still a healthy sign for the Prettier project.
As for mitigating #2254, I've had to manually pin to version 9.1.1
in my company's fork of the project.
Hi @Cielquan, I did actually link to alessandrojcm/commitlint-pre-commit-hook in the last sentance of the ticket
I totally oversaw this .. lol
As for mitigating #2254, I've had to manually pin to version
9.1.1
in my company's fork of the project.
Thanks for the info.
Hey guys, I would also love to see first party support for this. As already mentioned by others, https://github.com/alessandrojcm/commitlint-pre-commit-hook project has it done for you, just a matter of copying it here! I'm sure @alessandrojcm would be fairly proud of it!
Added a PR, let's see if it gets traction.
Hey guys, I would also love to see first party support for this. As already mentioned by others, https://github.com/alessandrojcm/commitlint-pre-commit-hook project has it done for you, just a matter of copying it here! I'm sure @alessandrojcm would be fairly proud of it!
I am, don't know how this flew under my radar until now. Super exciting to see my small repo used in this way 😳
@alessandrojcm feel free to take over my PR. I just wanted to get something going. :)
The existing hook repo is great but has 2 major problems,
- it doesn't have latest versions
- the tags do not match commitlint, making it impossible for renovate to update the dependency in pre-commit configs
So I think there is a lot of value to be gained here...
Are we interested in putting the file here? If the maintainers are not interested in that, the alternative is building a mirror, which the pre-commit maintainers apparently do not want to do -
We’d also like to get the .pre-commit-hooks.yaml files added to popular linters without maintaining forks / mirrors.
https://pre-commit.com/#contributing
There's a tool for that, tho. I can't recall exactly, but you can probably sleuth on @asottile for guidance. In the past, I've forked that tool to get the desired behavior, and added a GitHub Action to run daily and update state. Do mind the stock tool always recreates the whole git history (or it did, back then), which is a bit unwieldy.
Thread patiently.
The existing hook repo is great but has 2 major problems,
- it doesn't have latest versions
- the tags do not match commitlint, making it impossible for renovate to update the dependency in pre-commit configs
So I think there is a lot of value to be gained here...
Are we interested in putting the file here? If the maintainers are not interested in that, the alternative is building a mirror, which the pre-commit maintainers apparently do not want to do -
We’d also like to get the .pre-commit-hooks.yaml files added to popular linters without maintaining forks / mirrors.
https://pre-commit.com/#contributing
Hey @aentwist I do try to keep up with the releases, but sometimes, dependabot notifications just slip under the radar. ~~I actually am looking into automating that, but if you do need a release done, feel free to tag me in the dependabot PRs, and I'll merge them~~. As per your second point, it does not make sense to follow commitlint versioning, IMO. What is your use case for that?
EDIT: Point 1 has been automated now, dependabot PRs will be merged automatically and new tagged versions will be published after that.
This issue being years old I make the assumption that it has no priority with the maintainers as I do not see any here. I went ahead and spent today pushing the limits of pre-commit... which didn't go well... and making a more standard mirror project https://github.com/aentwist/pre-commit-mirrors-commitlint. It additionally has point 2 from above - if you are not concerned about such then @alessandrojcm project is great. Update: In addition to the basic commit hook, it supports running in all CIs with a manual invocation ~~I also do not support Travis, or anything other than commitlint --edit
for that matter. At least for now, although personally I'm done putting time into this.~~
@pkoch yes, the tool can be seen in other mirrors like mirrors-eslint and mirrors-prettier. It is called pre-commit-mirror-maker. Gave it a try today, works ok.