JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5888
  • Score
    100M100P100Q136160F
  • License MIT

Customizable checks on pre-commit (staged) contents

Package Exports

  • git-precommit-checks

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (git-precommit-checks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Check staged contents before commiting

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

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 like?

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 :

"hooks": {
  "pre-commit": [
    {
      "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!

Debug mode

You can use the --debug option to print processing detail:

  • package.json path
  • loaded rules (printed as a table)
  • checked files
  • short summary/stats (errors and warnings number)

Recommendations

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"
    }
  }