bruli / php-git-hooks

Git hooks for PHP projects
MIT License
676 stars 107 forks source link

use custom phpcs.xml file with lumen/laravel project #122

Closed scramatte closed 5 years ago

scramatte commented 5 years ago

Hi,

How can I use phpcs.xml with php-git-hooks? I've put it on root of my project but looks that is ignored by pre-commit script. Any idea of how can I solve this?

<?xml version="1.0"?>
<ruleset name="PSR2-laravel">
 <description>The PSR2 standard, but ignore something for laravel.</description>
 <!-- use preg_match https://github.com/squizlabs/PHP_CodeSniffer/issues/742#issuecomment-215250517 -->
 <exclude-pattern>/bootstrap/cache/</exclude-pattern>
 <exclude-pattern>/storage/</exclude-pattern>
 <exclude-pattern>/vendor/</exclude-pattern>
 <exclude-pattern>/_[a-zA-Z0-9\._]+\.php</exclude-pattern>
 <exclude-pattern>/\.[a-zA-Z0-9\._]+\.php</exclude-pattern>
 <exclude-pattern>*\.js</exclude-pattern>
 <exclude-pattern>*\.css</exclude-pattern>

 <!-- Include the whole PSR2 standard -->
 <rule ref="PSR2"/>

 <!-- Lines can be longer -->
 <rule ref="Generic.Files.LineLength">
  <properties>
   <property name="lineLimit" value="9999"/>
  </properties>
 </rule>

 <!-- ignore WARNING: A file should declare new symbols -->
 <rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
  <exclude-pattern>/bootstrap/</exclude-pattern>
 </rule>

 <!-- ignore ERROR: Each class must be in a namespace of at least one level (a top-level vendor name) -->
 <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
  <exclude-pattern>/database/migrations/</exclude-pattern>
  <exclude-pattern>/database/seeds/</exclude-pattern>
 </rule>

 <rule ref="Internal.NoCodeFound">
  <exclude-pattern>/resources/views/</exclude-pattern>
 </rule>

</ruleset>
scramatte commented 5 years ago

I answer to myself. In php-git-hooks.yml you need to specify the new phpcs.xml file

pre-commit:
    enabled: true
    execute:
        composer: true
        jsonlint: true
        phplint: true
        phpmd:
            enabled: true
            options: null
        phpcs:
            enabled: true
            standard: phpcs.xml
            ignore: null
        php-cs-fixer:
            enabled: true
 ...