Giter Site home page Giter Site logo

jlamb1 / git-precommit-checks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mbrehin/git-precommit-checks

0.0 0.0 0.0 239 KB

Customizable checks on pre-commit (staged) contents

Home Page: https://mbrehin.github.io/git-precommit-checks/

License: MIT License

JavaScript 100.00%

git-precommit-checks's Introduction

Check staged contents before commiting

version travis build node version dev dependencies vulnerabilities MIT license semantic-release

Documentation also available in: Traduction française

Because we love git hooks and npm, we want to share and automate code/content quality.

git-precommit-checks has to be loaded manually or using any wrapper around git hooks.

As you can read below we highly recommend Husky.

How does it look?

Install

npm install --save-dev git-precommit-checks

How to setup my checking rules?

Configuration is loaded from package.json so you can customize it according to your needs.

Here is an example :

"git-precommit-checks": {
  "rules": [
    {
      "filter": "\\.js$",
      "nonBlocking": "true",
      "message": "You’ve got leftover `console.log`",
      "regex": "console\\.log"
    },
    {
      "message": "You’ve got leftover conflict markers",
      "regex": "/^[<>|=]{4,}/m"
    },
    {
      "message": "You have unfinished devs",
      "nonBlocking": "true",
      "regex": "(?:FIXME|TODO)"
    }
  ]
}

Each "pre-commit" entry is a checking rule: the pattern describes a regular expression that will be searched upon staged content. The associated message is displayed when the pattern is found.

Each rule will stop the commit when the associated pattern is found unless you set the nonBlocking key to true. Non blocking rules will print warning messages.

You can also filter on files patterns using the filter key.

Only message and regex keys are mandatory.

⚠️ There is no default checks configured after install, so please be aware that nothing will happend without adding your own rules!

Display options

You can add an optional display entry in your config to enable some options:

"git-precommit-checks": {
  "display": {
    "offending-content": true,
    "rules-summary": true,
    "short-stats": true,
    "verbose": true
  },
  • offending-content: print offending contents right after associated file path and line number
  • rules-summary: print rules as a table before parsing staged files
  • short-stats: print short stats (ie. 1 error, 1 warning.)
  • verbose: print every performed action, files parsed, short summary/stats (errors and warnings number)

Usage

Triggering it straight with git hooks

After installing locally or globally your module, add the following code (or equivalent) to your project pre-commit hook .git/hooks/pre-commit:

#!/bin/sh
scriptName="git-precommit-checks"
scriptPath="$(npm bin)/$scriptName"

if [ -f $scriptPath ]; then
  $scriptPath
else
  echo "Can't find $scriptName module"
  echo "You can reinstall it using 'npm install $scriptName --save-dev' or delete this hook"
fi

Running git-precommit-checks with Husky

Husky is a great tool to manage git hooks from your package.json.

You can use it and call git-precommit-checks on pre-commit:

  "husky": {
    "hooks": {
      "pre-commit": "git-precommit-checks"
    }
  }

Contributing

Any contribution is welcomed. Here is our contribution guideline

git-precommit-checks's People

Contributors

mbrehin avatar

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.