prepush-hook

A useful pre-push hook for git based projects that lints and runs npm test

prepush-hook

An npm installable git pre-push hook used to lint and test your code. Thanks to nlffor his precommit-hookproject. prepush-hook borrows heavily from his work.

Installation

npm install prepush-hook

Everything else is automatic!

I recommend putting precommit-hook in your project's devDependencies to make sure that anyone who may be contributing to your project will have the hook installed.

{
  "name": "your_project",
  "description": "just an example",
  "scripts": {
    "validate": "./command/to/run",
    "test": "./other/command"
  },
  "devDependencies": {
    "precommit-hook": "latest"
  }
}

Usage

When you install this project, by default it will create sane .jshintignoreand .jshintrcfiles for you if they do not already exist. That means it's safe to upgrade the hook after customizing these files, as they will never be overwritten. If you have your jshint configuration in your package.json, then the .jshintrcfile will not be created ever.

You can prevent this behavior by modifying your package.json file. If a lintscript is specified and does not start with the string "jshint"OR if you configure the hook to run specific scripts, and that list of scripts does not include "lint", the jshint configuration files will not be created.

For example:

{
  "name": "your_project",
  "description": "just an example",
  "scripts": {
    "lint": "some_other_linter ."
  }
}

OR

{
  "name": "your_project",
  "description": "just an example",
  "precommit": ["test"]
}

If you do not configure the hook with an array of scripts to run, it will default to ["lint", "validate", "test"]to maintain backwards compatibility with the old version of this hook. In addition to that, if a lintscript is not specified, it will default to "jshint .". If a lintscript is configured, it will not be overridden. If an array of scripts is configured, it will be used and there will be no default lintscript.

Package.json

{
  "name": "your_project",
  "description": "just an example",
  "scripts": {
    "validate": "./command/to/run",
    "test": "./other/command"
  }
}

The contents of the validate and test properties are the shell command to be run to perform those functions. Having these specified in your package.json also lends you the ability to be able to run them manually like so

npm run-script validate
npm test

These scripts can be any shell executable commands, but must exit with a status code of 0 for success and 1 or greater for failure. The PATHenvironment variable used when executing these scripts will be similar to how npm configures it. That means if you npm install jshintlocally to your project, you can put simply "jshint ."for your script rather than "./node_modules/.bin/jshint .".

You may configure what scripts will be run by the hook, by passing an array of script names to the "precommit"key in your package.json.

{
  "name": "your_project",
  "description": "just an example",
  "scripts": {
    "lint": "jshint --with --different-options",
    "validate": "./command/to/run",
    "test": "./other/command"
  },
  "precommit": ["lint", "test"]
}

This example would run only the lintand testscripts, in that order.

JSHint Defaults

The default .jshintrclooks like the following:

{
  "node": true, // node environment
  "curly": true, // enforce using curly braces around blocks
  "latedef": true, // enforce defining a variable before using it
  "undef": true, // error on use of undefined variables
  "unused": true, // error on variables that are defined but never used
  "trailing": true // error on trailing whitespace
  "eqeqeq": true // prohibits the use of == and != in favor of === and !==
  "camelcase": true // force all variable names to use either camelCase style or UPPER_CASE
  "maxlen": true // enforce line length maximum of 80
}

And the default .jshintignorecontains only one line

node_modules

License

MIT

HomePage

https://github.com/thadclay/prepush-hook

Repository

https://github.com/thadclay/prepush-hook.git


上一篇:travis-weigh-in
下一篇:angular-jsdoc

相关推荐

  • 面试题:Hooks 与 React 生命周期的关系

    React 生命周期很多人都了解,但通常我们所了解的都是 单个组件 的生命周期,但针对 Hooks 组件、多个关联组件(父子组件和兄弟组件) 的生命周期又是怎么样的喃?你有思考和了解过吗,接下来我们将...

    1 年前
  • 面试官: 聊一聊 HOC、Render props、Hooks

    在以前我们可能会看到很多文章在分析 HOC 和 render props, 但是在 2020 年 ,我们有了新欢 “hook” . 本篇文章会分析 hook , render props 和 HOC ...

    4 个月前
  • 通过简单的示例来理解React Hook

    This hook makes it easy to dynamically change the appearance of your app using CSS variables. You si...

    1 年前
  • 让你我不得不学习的React Hook

    1 什么是Hook 首先我们要明白的是React 16.8 的新增特性。它可以让我们在不编写 class 的情况下使用 state 以及其他的 React 特性。

    1 年前
  • 茴字的四种写法——如何在React Hook中获得最新的state

    今天的这个问题也源于生活(工作)😂。在我们刚开始使用React hook的时候,经常会遇到这样的情况:我需要在某个异步请求/事件监听中更新我的state的值,并拿着更新好的state去做什么事情。

    23 天前
  • 自定义 React Hook

    对于开发者来说,函数是对某一个功能的封装,那么 hook 就是对相同逻辑功能的封装。当你觉得重复在做一件事情的时候,那么你会把它封装成一个函数。同理,当你觉得在写重复的逻辑时,那么它就可以是一个 ho...

    2 个月前
  • 结合React的Effect Hook分析组件副作用的清除

    一个订阅好友在线的组件 我们在DidMount的时候通过ID订阅了好友的在线状态 并且为了防止内存泄漏,我们需要在WillUnmount清除订阅 但是当组件已经显示在屏幕上时,friend pr...

    9 个月前
  • 终于搞懂 React Hooks了!!!!!

    (/public/upload/776f7115c905ba46eadd00ff62b8c272) (/public/upload/aa428a9f0941877303e5b6476eea...

    5 个月前
  • 精读《怎么用 React Hooks 造轮子》

    1 引言 上周的 精读《React Hooks》(https://github.com/dtfe/weekly/blob/master/79.%E7%B2%BE%E8%AF%BB%E3%80%8A...

    2 年前
  • 精读《React Hooks》

    1 引言 React Hooks 是 React 版本推出的新特性,想尝试的同学安装此版本即可。 React Hooks 要解决的问题是状态共享,是继 renderprops(https://...

    2 年前

官方社区

扫码加入 JavaScript 社区