Skip to content

edetaillac/static-review

 
 

Repository files navigation

Web/PHP Pre-Commit

PHP Precommit Tools to lint/review/clean all your web files (php/js/scss/xml/yml/json)

Based on https://github.com/sjparkinson/static-review

Table of Contents

  1. What is it?
  2. Requirements
  3. How to Install
  4. How to Update
  5. Usage
  6. PHPStorm Integration
  7. Used Libraries

What is it

This Code Reviewing tool can check:

  • GIT merge conflict markers
  • GIT NOCOMMIT markers
  • Forgot debugging (JS,PHP) statements
  • PHP Syntax Error
  • XML Syntax Error
  • YML Syntax Error
  • JSON Syntax Error
  • JS Syntax Error & auto-fix it
  • Composer .json validation
  • Composer Sync .json and .lock files

It optimizes PHP Syntax with specific php-cs-fixer rules (See PhpCsFixerReview.php) :

  • Automatically Fix coding standards issues (PHP CS Fixer)

It optimizes SCSS Syntax :

  • Automatically Fix coding standards issues (Sass-convert)

It reports about bad JS statements with specific eslint rules (See Rules/.eslintrc)

It reports about bad SCSS statements specific scss-lint rules (See Rules/.scsslint.yml)

It reports about bad PHP statements :

  • Mess Detection (Unused code, complexity...) with phpmd rules (See Rules/phpmd.xml)
  • Copy/Paste detection
  • Code sniffing to notify missing PHPDOC function

Requirements

Execute check-requirements command: ./bin/precommit checkRequirements

Change PHP Cli Configuration if necessary with:

phar.readonly = Off

How to Install

To install precommit tool and generate phar package: Launch install script ./install_precommit.sh

This script will install all required libraries, create a phar file with sources files, and move it to /usr/local/bin

In your project path, just execute install command precommit install

To know which project is configured with pre-commit, you can simply execute precommit listRepo [WORKSPACE_PATH]

How to Update

Get latest libraries version with a "composer global update"

Just update your GIT fork and re-launch install script.

Usage

After the installation, you can execute "precommit" command to:

  • checkRequirements : Execute check requirements
  • check : Execute pre-commit
  • checkFile [file] : Execute pre-commit checks on single file
  • php-cs-fixer [file] : Execute php-cs-fixer rule on single file
  • install : Install pre-commit hook on your current project
  • delete : Delete pre-commit hook on your current project
  • listRepo [workspace_path] : Analyse all git projects to get pre-commit informations

PHPStorm Integration

In order to check file manually in PhpStorm:

  • Go to Settings / External Tools
  • Add new one and fill info like this:
    • Program: "precommit"
    • Parameters: "checkFile $FilePath$"
    • Working Directory: "$ProjectFileDir$"

Used Libraries

About

Pre-Commit Tool (PHP/Symfony/JS/SCSS/JSON/XML/YML...)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 98.0%
  • Shell 2.0%