Git Product home page Git Product logo

drupal-code-check's Introduction

Drupal Code Check

A Git pre-commit hook to check Drupal Coding Standards and more.

Latest Stable Version Total Downloads Latest Unstable Version License composer.lock

Description

This Git pre-commit hook will be active on your Composer based Drupal project.

Things which will be checked in the pre-commit hook:

  • Syntax checking using PHP Linter
  • Automatically try to match code style via PHP Code Sniffer Beautifier and Fixer
  • Coding standards checking using PHP Code Sniffer
  • Blacklisted strings checking/validation

Note that files of the following origins are not checked:

  • Drupal Core
  • Contributed Modules
  • Contributed Libraries
  • Contributed Themes
  • Contributed Profiles

Getting started

Prerequisites

  • Composer
  • Composer based Drupal project
  • PHP 5.4 or higher

Installation

Add this project as a composer dependency on your Composer based Drupal project.

composer require jover_be/drupal-code-check

And don't forget to update...

composer update jover_be/drupal-code-check

In order to activate the Git Hooks, update your composer.json file like following:

{
    "scripts": {
        "post-install-cmd": [
            "jover_be\\drupal_code_check\\GitHooks::create"
        ],
        "post-update-cmd": [
        	"jover_be\\drupal_code_check\\GitHooks::create",
        ]
    }
}

Development requirement

In case you want to install it as a development requirement (require-dev), make use of the project neronmoon/scriptsdev in order to execute the scripts only in case your project was installed in development mode.

composer require --dev neronmoon/scriptsdev
composer require --dev jover_be/drupal-code-check

And instead, you should be using the scripts-dev part as described by

{
    "extra": {
        "scripts-dev": {
            "post-install-cmd": [
                "jover_be\\drupal_code_check\\GitHooks::create"
            ],
            "post-update-cmd": [
                "jover_be\\drupal_code_check\\GitHooks::create",
            ]
        }
    }
}

Author

jover.be

License

This project is licensed under the MIT License - see the LICENSE file for details.

drupal-code-check's People

Contributors

jover avatar woutersf avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

drupal-code-check's Issues

Committing via command line throws error on composer.json

After adding the code-check to the dev requirements and instantiating the post install/update hooks, I am unable to commit changes via the command line.
The checkscript throws errors on composer.json:

$ composer require --dev jover_be/drupal-code-check
$ vi composer.json (add post install and update hook)
$ composer update jover_be/drupal-code-check
...
> DrupalProject\composer\ScriptHandler::createRequiredFiles
> jover_be\drupal_code_check\GitHooks::create
Create a symbolic link for Git Hook: pre-commit
Create a symbolic link for Git Hook: pre-commit.php

$ git commit -am "Adding jover_be/drupal-code-check to the composerfile"

FILE: [project]/composer.json
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 1 | WARNING | No PHP code was found in this file and short open tags
   |         | are not allowed by this install of PHP. This file may
   |         | be using short open tags but PHP does not allow them.
----------------------------------------------------------------------

Time: 110ms; Memory: 7.5Mb

When trying to commit via a UI (SourceTree, Tower...) this error is not shown.

Make things configurable

There're a bunch of assumptions regarding paths & locations of folders which are setup by default by Drupal-Scaffold.

This should be configurable so it's possible to use this project with a different folder structure.

More specifically:

  • $allowed_extensions
  • $excluded_paths

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.