Skip to content

Commit

Permalink
feat: initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikZaluskiCleeng committed Nov 6, 2023
1 parent 842fb58 commit cc86a0d
Show file tree
Hide file tree
Showing 18 changed files with 6,316 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
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
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto eol=lf

.gitattributes export-ignore
.editorconfig export-ignore
.gitignore export-ignore
.github/ export-ignore
.php-cs-fixer.dist.php export-ignore
captainhook.json export-ignore
phpstan.neon.dist export-ignore
phpunit.xml export-ignore
test/ export-ignore
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Description
Tell us more about what you've done 🚀
6 changes: 6 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
template: |
## What's changed:
$CHANGES
🚀
22 changes: 22 additions & 0 deletions .github/workflows/conventional-label.yml
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: '[]'
60 changes: 60 additions & 0 deletions .github/workflows/integration-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 ]
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- uses: php-actions/composer@v6
- run: composer test

unit-tests-with-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2
coverage: pcov
- uses: php-actions/composer@v6
- run: composer test:coverage
20 changes: 20 additions & 0 deletions .github/workflows/release-drafter.yml
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 }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor/
.idea/
coverage/
coverage.xml
25 changes: 25 additions & 0 deletions .php-cs-fixer.dist.php
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;
92 changes: 92 additions & 0 deletions README.md
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>
32 changes: 32 additions & 0 deletions captainhook.json
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"
}
]
}
}
63 changes: 63 additions & 0 deletions composer.json
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"
}
}
}
}
Loading

0 comments on commit cc86a0d

Please sign in to comment.