Skip to content

Commit 03dc455

Browse files
committed
Initial commit
0 parents  commit 03dc455

5 files changed

Lines changed: 109 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.idea/

.pre-commit-hooks.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- id: composer-validate
2+
name: Composer Validate
3+
description: Validates a composer.json and composer.lock
4+
entry: hooks/composer-validate.sh
5+
language: script
6+
files: composer\.(json|lock)$
7+
pass_filenames: false
8+
args:
9+
- "validate"
10+
- "--check-lock"
11+
- "--strict"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Charlie Marsh
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
pre-commit-laravel
2+
==================
3+
A [pre-commit](https://pre-commit.com/) hook for [Laravel](https://laravel.com/).
4+
5+
This adds support for running [Laravel Pint](https://laravel.com/docs/10.x/pint) and
6+
[Artisan Tests](https://laravel.com/docs/10.x/testing#running-tests) as pre-commit hooks in your Laravel project.
7+
8+
Usage
9+
-----
10+
11+
### Using Laravel Pint with pre-commit
12+
Add this to your `.pre-commit-config.yaml`:
13+
14+
```yaml
15+
- repo: https://github.com/matchory/pre-commit-laravel
16+
rev: v1.0.1
17+
hooks:
18+
- id: laravel-pint
19+
```
20+
21+
Or, to disable automatic fixing:
22+
```yaml
23+
- repo: https://github.com/matchory/pre-commit-laravel
24+
rev: v1.0.1
25+
hooks:
26+
- id: laravel-pint
27+
args: ["--test"]
28+
```
29+
30+
### Using Artisan tests with pre-commit
31+
Add this to your `.pre-commit-config.yaml`:
32+
33+
```yaml
34+
- repo: https://github.com/matchory/pre-commit-laravel
35+
rev: v1.0.1
36+
hooks:
37+
- id: laravel-tests
38+
```
39+
40+
Or, to enable parallel testing:
41+
```yaml
42+
- repo: https://github.com/matchory/pre-commit-laravel
43+
rev: v1.0.1
44+
hooks:
45+
- id: laravel-tests
46+
args: ["--parallel"]
47+
```
48+
Note that this requires the [`brianium/paratest` package](https://packagist.org/packages/brianium/paratest) to be
49+
installed in your project.
50+
51+
License
52+
-------
53+
MIT

hooks/composer-validate.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
color_red="\033[0;31m"
4+
color_reset="\033[0m"
5+
6+
title="Composer Validate"
7+
8+
phar_command="composer.phar"
9+
system_command="composer"
10+
11+
exec_command=""
12+
13+
if [ -f "$phar_command" ]; then
14+
exec_command=$phar_command
15+
elif hash $system_command 2> /dev/null; then
16+
exec_command=$system_command
17+
else
18+
echo -e "${color_red}${title} is not found.${color_reset}"
19+
echo "${phar_command} or ${system_command} is required."
20+
exit 1
21+
fi
22+
23+
${exec_command} "${@}"

0 commit comments

Comments
 (0)