grnrbt/php-lint

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

greenrabbit lint config

dev-master 2017-02-27 13:43 UTC

This package is not auto-updated.

Last update: 2021-10-16 11:54:05 UTC


README

PHP-Lint is simplified linter solution for php, based on PHP_CodeSniffer.

Currently it's support only as HG hook, GIT hook will come soon.

Current rule set is in progress. It consist of PSR1, PSR2, PEAR, PHPCompatibility, Yii2 Coding Standard, some of Squiz and Generic rules.

Installation

Installation is realized by Composer.

In the console write:

composer require --dev grnrbt/php-lint "*"

or add following line in require-dev section of composer.json file.

"grnrbt/php-lint": "*"

Usage

HG hook
Checks only staged files in repository so it can be added in present repositories without problems with old files.

Add following code into .hg/hgrc file or HG-client settings:

[hooks]
pretxncommit.hglint = vendor/bin/lint

or on Windows:

[hooks]
pretxncommit.hglint = vendor\bin\lint.bat

To skip checking run commit from console with ENV param NO_VERIFY=1:

NO_VERIFY=1 hg ci -u <user> -m <message> 

Manual run
You can run linter with ruleset manually from console

$ ./vendor/bin/lint

It will check staged files or run CodeSniffer itself

$ ./vendor/bin/phpcs --extensions=php --standard=/vendor/grnrbt/php-lint/ruleset.xml <dir>

For checking choosen directory <dir>

PHPStorm
If you're using PhpStorm you can configure it to use CodeSniffer using Settings → Languages & Frameworks → PHP → Code Sniffer.

Custom rules

You can override standard rules by placing file ruleset.xml in root directory of your project. In that file you can include original file and add your own rules or disable rules, that was added in common ruleset.

<?xml version="1.0"?>
<ruleset name="Custom Standard">
    <description>A custom coding standard</description>

    <exclude-pattern>*/tests/*</exclude-pattern>
    
    <rule ref="/vendor/grnrbt/php-lint/ruleset.xml"/>
    
    <!-- custom rules, overrides -->
</ruleset>

Links