Giter VIP home page Giter VIP logo

phpcs-git-pre-commit's Introduction

PHPCS git pre-commit hook

About

Auto installed git pre-commit hook for running PHP Code Sniffer code checking to PSR2 coding standard compliance. It checks only files that are to be committed.

Inspired by Enforce code standards with composer, git hooks, and phpcs

Installation

Install smgladkovskiy/phpcs-git-pre-commit with composer require command:

composer require --dev "smgladkovskiy/phpcs-git-pre-commit"

Or alternatively, include a dependency for smgladkovskiy/phpcs-git-pre-commit in your composer.json file manually:

{
    "require-dev": {
        "smgladkovskiy/phpcs-git-pre-commit": "dev-master"
    }
}

To enable code sniff, аdd to post-install-cmd and post-update-cmd in composer.json installation script:

"scripts": {
    "install-hooks": ["sh ./vendor/smgladkovskiy/phpcs-git-pre-commit/src/setup.sh"],
    "post-install-cmd": ["@install-hooks"],
    "post-update-cmd": ["@install-hooks"]
}

Then run composer install or composer update. pre-commit hook will be installed or updated if it already exists.

Usage

Run git commit and pre-commit hook will check your committed files like if you run

php phpcs.phar --standard=PSR2 --encoding=utf-8 -n -p /path/to/file.php

Contributing

Feel free to make pull requests!

phpcs-git-pre-commit's People

Contributors

boryn avatar michnovka avatar smgladkovskiy avatar sreichel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

phpcs-git-pre-commit's Issues

I have installed the package but it is not restricting git commit

I have followed steps and installed package and below command is showing errors

php phpcs.phar --standard=PSR2 --encoding=utf-8 -n -p /path/to/file.php

but why I tried, I have used git bash to commit in winows

git commit -m "" file.php

it does not show error message and stopped committing code

PreCommit fails

When I run the pre-commits on my windows machine it always fails

When I run the exact same phpcs command in my docker container, the -p flag shows the progress (100%), hence the return value of this command in the bash script does not return 0, so it is interpreted as an error

When I remove the -p the command returns empty, which is good, however the if statement seems not be correct
When I replace the if comparison if 'ne' then it works.
The code below the pre-commit succeeds on a valid phpcs check, and fails on an invalid phpcs check.

    ./vendor/bin/phpcs --standard=PSR2 --exclude=Generic.Files.LineLength --extensions=php -n $FILES
    if [ $? ne 0 ]

Adding new branch/openmage-lts support

Is it possible to ad a new branch or setup script to make it work out of the box (w/o forking) with OpenMage/magento-lts#982? Magento1/Openmage just needs two sniffs to be excluded by default .... (
--exclude=Squiz.Classes.ValidClassName,PSR1.Classes.ClassDeclaration)

Either a new branch (openmage-lts) with a modified hook, or add a new setup-script and a new hook? (pre-commit.default, pre-commit.openmage-lts) ... or close it :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.