/php-cs-fixer-git-hook

Git hook running PHP CS Fixer on staged files using CaptainHook

Primary LanguagePHPMIT LicenseMIT

MIT licensed Code coverage

php-cs-fixer-git-hook

Git hook running PHP CS Fixer on staged files using CaptainHook
Report Bug · Request Feature

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.

(back to top)

Requirements

(back to top)

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

That's it. From now on after running git commit files that were staged will be automatically fixed by Php Cs Fixer.

(back to top)

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"
        }
      }
    ]
  }
}

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)