Skip to content

Commit

Permalink
feat: add pre-commit hook support
Browse files Browse the repository at this point in the history
Fixes #791
  • Loading branch information
ccoVeille committed Jan 21, 2025
1 parent 812a888 commit 3b14ef9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
repos:
- repo: https://github.com/vektra/mockery
rev: v2 # This is a mutable reference
hooks:
- id: generate-mocks
- id: generate-mocks-local
14 changes: 14 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- id: generate-mocks
name: generate mocks
description: Generate mocks with mockery
language: golang
entry: go run .
pass_filenames: false

- id: generate-mocks-local
name: generate mocks with local mockery
description: Generate mocks with local mockery
language: system
entry: mockery
pass_filenames: false
41 changes: 39 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,45 @@ Generate all the mocks for your project:

Install through [brew](https://brew.sh/)

brew install mockery
brew upgrade mockery
```shell
brew install mockery
```

Upgrade to the latest version

```shell
brew upgrade mockery
```

### pre-commit

Add the following lines to your `.pre-commit-config.yaml` file

```yaml
repos:
- repo: https://github.com/vektra/mockery
rev: v2 # This is a mutable reference to the latest version
hooks:
- id: generate-mocks
```
!!! note
If the file is missing, you can simply create it with this content
Then install the hook with the following command:
```console
# This one will report a warning about mutable reference
$ pre-commit install

# This one will fix the warning
$ pre-commit autoupdate
```

It will install everything. And from now, your commit will trigger mock generation.

More information about pre-commit can be found on [pre-commit.com/](https://pre-commit.com/)


<script type="text/javascript">
Expand Down

0 comments on commit 3b14ef9

Please sign in to comment.