-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
842fb58
commit c4dca5a
Showing
17 changed files
with
6,304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.MD] | ||
trim_trailing_whitespace = false | ||
|
||
[*.yml] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
### Description | ||
Tell us more about what you've done 🚀 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
template: | | ||
## What's changed: | ||
$CHANGES | ||
🚀 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: conventional-commit-pr-labels | ||
|
||
on: | ||
pull_request_target: | ||
types: [ opened, edited ] | ||
branches: [ main ] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
jobs: | ||
label-pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: bcoe/conventional-release-labels@v1 | ||
with: | ||
type_labels: '{"feat": "feature", "fix": "fix", "chore": "chore", "ci": "CI", "docs": "documentation", "refactor": "refactor", "test": "test"}' | ||
ignored_types: '[]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Integration checks | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
types: [ opened, synchronize, reopened, edited ] | ||
branches: [ main ] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
php-cs-fixer: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.2 | ||
- uses: php-actions/composer@v6 | ||
- run: composer lint | ||
|
||
phpstan: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: [ 8.0, 8.1, 8.2 ] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
- uses: php-actions/composer@v6 | ||
- run: composer analyse | ||
|
||
unit-tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: [ 8.0, 8.1, 8.2 ] | ||
coverage: [ false ] | ||
include: | ||
- php: 8.2 | ||
coverage: true | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: pcov | ||
- uses: php-actions/composer@v6 | ||
- name: Unit tests | ||
if: matrix.coverage == false | ||
run: composer test | ||
- name: Unit tests with coverage | ||
if: matrix.coverage == true | ||
run: composer test:coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Release drafter | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
update-release-draft: | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: release-drafter/release-drafter@v5 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
vendor/ | ||
.idea/ | ||
coverage/ | ||
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in([ | ||
__DIR__ . '/src', | ||
__DIR__ . '/test', | ||
]); | ||
|
||
$config = new PhpCsFixer\Config(); | ||
$config | ||
->setFinder($finder) | ||
->setUsingCache(false) | ||
->setRules([ | ||
'@PSR12' => true, | ||
'@PHP80Migration' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'arrays', 'parameters']], | ||
'binary_operator_spaces' => true, | ||
'whitespace_after_comma_in_array' => ['ensure_single_space' => true], | ||
'yoda_style' => true, | ||
]); | ||
|
||
return $config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<a name="readme-top"></a> | ||
|
||
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Unh3ck3d/php-cs-fixer-git-hook/blob/main/LICENSE) | ||
|
||
<h3 align="center">php-cs-fixer-git-hook</h3> | ||
<p align="center"> | ||
Git hook running PHP CS Fixer on staged files using CaptainHook | ||
<br /> | ||
<a href="https://github.com/Unh3ck3d/php-cs-fixer-git-hook/issues">Report Bug</a> | ||
· | ||
<a href="https://github.com/Unh3ck3d/php-cs-fixer-git-hook/issues">Request Feature</a> | ||
</p> | ||
|
||
## About The Project | ||
|
||
Git hook that with each `git commit` command runs Php Cs Fixer | ||
on staged files to automatically fix them and re-stage before committing. | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## Requirements | ||
|
||
* [PHP](https://www.php.net/) >= 8.0 | ||
* [CaptainHook](http://captainhook.info/) >= 5.0 | ||
* [PHP CS Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## Installation | ||
|
||
1. Install package as a dev dependency using composer | ||
``` | ||
composer require --dev unh3ck3d/php-cs-fixer-git-hook | ||
``` | ||
2. Add the following code to your `captainhook.json` configuration file | ||
``` | ||
{ | ||
"pre-commit": { | ||
"enabled": true, | ||
"actions": [ | ||
{ | ||
"action": "\\Unh3ck3d\\PhpCsFixerGitHook\\LintStagedFiles" | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
3. Install newly added hook by following [CaptainHook docs](http://captainhook.info/install.html) | ||
|
||
That's it. From now on after running `git commit` files that were staged will be | ||
automatically fixed by Php Cs Fixer. | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## Configuration | ||
|
||
You can customize the behaviour how git hook is run by changing following options | ||
|
||
| Option | Description | | ||
|----------------|-----------------------------------------------------------------------------| | ||
| phpCsFixerPath | Path to Php Cs Fixer executable. Defaults to `./vendor/bin/php-cs-fixer`. | | ||
| pathMode | `path-mode` cli option of Php Cs Fixer. Defaults to `intersection`. | | ||
| config | `config` cli option of Php Cs Fixer. Defaults to `.php-cs-fixer.dist.php`. | | ||
| additionalArgs | String of additional arguments that will be passed to Php Cs Fixer process. | | ||
|
||
e.g. | ||
``` | ||
{ | ||
"pre-commit": { | ||
"enabled": true, | ||
"actions": [ | ||
{ | ||
"action": "\\Unh3ck3d\\PhpCsFixerGitHook\\LintStagedFiles", | ||
"options": { | ||
"phpCsFixerPath": "php-cs-fixer.phar", | ||
"pathMode": "overwrite", | ||
"config": ".php-cs-fixer.php", | ||
"additionalArgs": "-v --dry-run --diff" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## License | ||
|
||
Distributed under the MIT License. See `LICENSE` for more information. | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"pre-commit": { | ||
"enabled": true, | ||
"actions": [ | ||
{ | ||
"action": "\\Unh3ck3d\\PhpCsFixerGitHook\\LintStagedFiles" | ||
}, | ||
{ | ||
"action": "composer analyse" | ||
}, | ||
{ | ||
"action": "composer test" | ||
} | ||
] | ||
}, | ||
"commit-msg": { | ||
"enabled": true, | ||
"actions": [ | ||
{ | ||
"action": "\\Ramsey\\CaptainHook\\ValidateConventionalCommit" | ||
} | ||
] | ||
}, | ||
"prepare-commit-msg": { | ||
"enabled": true, | ||
"actions": [ | ||
{ | ||
"action": "\\Ramsey\\CaptainHook\\PrepareConventionalCommit" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"name": "unh3ck3d/php-cs-fixer-git-hook", | ||
"type": "library", | ||
"description": "Git hook running PHP CS Fixer on staged files using CaptainHook", | ||
"license": "MIT", | ||
"keywords": [ | ||
"lint", | ||
"git", | ||
"php", | ||
"hook", | ||
"php-cs-fixer", | ||
"captainhook", | ||
"captainhook-extension" | ||
], | ||
"homepage": "https://github.com/Unh3ck3d/php-cs-fixer-git-hook", | ||
"support": { | ||
"issues": "https://github.com/Unh3ck3d/php-cs-fixer-git-hook/issues" | ||
}, | ||
"require": { | ||
"php": "^8.0", | ||
"captainhook/captainhook": "^5.0.0", | ||
"sebastianfeldmann/cli": "^3.4" | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^3.34.1", | ||
"phpstan/phpstan": "^1.10.38", | ||
"phpunit/phpunit": "^9.6.13", | ||
"ramsey/conventional-commits": "^1.4.0", | ||
"phpspec/prophecy-phpunit": "^2.0", | ||
"jangregor/phpstan-prophecy": "^1.0" | ||
}, | ||
"suggest": { | ||
"captainhook/plugin-composer": "Ensures that CaptainHook hooks get installed automagically" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Unh3ck3d\\PhpCsFixerGitHook\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Unh3ck3dTest\\PhpCsFixerGitHook\\": "test/" | ||
} | ||
}, | ||
"scripts": { | ||
"post-autoload-dump": "vendor/bin/captainhook install -f -s --only-enabled", | ||
"lint": "php-cs-fixer fix -v --dry-run --diff", | ||
"lint:fix": "php-cs-fixer fix -v --diff", | ||
"analyse": "phpstan analyse", | ||
"test": "phpunit", | ||
"test:coverage": "phpunit --coverage-html coverage --coverage-clover coverage.xml" | ||
}, | ||
"config": { | ||
}, | ||
"extra": { | ||
"ramsey/conventional-commits": { | ||
"config": { | ||
"types": ["chore", "ci", "docs", "refactor", "test", "revert"], | ||
"typeCase": "lower" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.