Giter Site home page Giter Site logo

precommit-hook's Introduction

What is it?

Note: This module is simply a wrapper around git-validate. If you wish to use a linter other than jshint, I highly recommend you look there instead as this module will always bundle jshint for historical reasons.

Join the chat at https://gitter.im/nlf/precommit-hook

This module is a handy little tool that I wrote to help enforce code quality in Node.js projects. It allows you to run any scripts defined in your package.json before a commit is made.

WARNING: If you already have a .git/hooks/pre-commit file, this package will overwrite it.

Breaking changes

Version 2.0.0 of this module (and the current master branch in this repository) has been updated to use git-validate, as such the configuration key in package.json will be changed to "pre-commit" with a dash, instead of the old "precommit". All other functionality should work the same.

Why should I use it?

No one likes a messy code base. When working on a team, it becomes more and more difficult to make sure that your project's code stays consistent and error free. Since the hook can lint all of the project's code, based on your configuration, you can be sure that at the very least standards are being followed. It can also run build steps, unit tests, or any other script you like.

Having a tool that automates this process has been priceless for us, and has very much improved the quality of our code.

Usage

When you install this project, by default it will create sane .jshintignore and .jshintrc files 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 .jshintrc file will not be created ever.

A .validate.json file will also be created to provide defaults to git-validate in order to run your scripts. This configuration is only used if you have not specified your own configuration in package.json.

If you need to make changes to the hook's configuration, you should always make them in your package.json as the .validate.json file will be overwritten every time the install script is run.

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, if a lint script is not specified, it will default to "jshint .". If a lint script is configured, it will not be overridden. If an array of scripts is configured, it will be used and there will be no default lint script.

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 commands 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 PATH environment variable used when executing these scripts will be similar to how npm configures it. That means if you npm install jshint locally 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 "pre-commit" 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"
  },
  "pre-commit": ["lint", "test"]
}

This example would run only the lint and test scripts, in that order.

Usage

npm install precommit-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"
  }
}

JSHint Defaults

The default .jshintrc looks like the following:

{
  "node": true, // node environment

  "curly": true, // enforce using curly braces around blocks
  "latedef": true, // enforce defining a variable before using it
  "quotmark": true, // allows either " or ' but you must be consistent
  "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
}

And the default .jshintignore contains only one line

node_modules

Contact

Like the project? Hate it? Just want to say hi? Find me on twitter @quitlahok

License

MIT

precommit-hook's People

Contributors

alavers avatar blakmatrix avatar gitter-badger avatar jcugno avatar nlf avatar thadclay avatar trott avatar vvo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

precommit-hook's Issues

Do not create .jshint files

Lots of projects now use ESlint and creating JSHint configs automatically on installing precommit-hook package is strange. Maybe it is better to create an empty "lint" npm script instead and leave the linter choice and configuration up to developer?

Not working

I added some lint errors, but it's still making the commit

{
  "pre-commit": ["lint"],
  "scripts": {
    "lint": "eslint ./app/**/*.js"
  }
}
λ git commit -m "test"
env: git: No such file or directory
this does not look like a git repository.. exiting
[dev 2c6a426] test
warning: LF will be replaced by CRLF in code/.jshintignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in code/.jshintrc.
The file will have its original line endings in your working directory.
 3 files changed, 13 insertions(+)
 create mode 100644 code/.jshintignore
 create mode 100644 code/.jshintrc

README: Confusing note about version 2.0.0

Perhaps I was just being dense, but I found this line from the README confusing.

As of version 2.0.0 of this module, the configuration key in package.json has been changed to "pre-commit" with a dash, instead of the old "precommit". All other functionality should work the same.

I realize now that that version 2.0.0 is forthcoming, but the currently published version in npm is 1.0.7. Took me a bit to figure out that I should still use 'the old "precommit"' rather than 'pre-commit' for config in my package.json.

Might I recommend removing that line until version 2.0.0 is actually released?

Not a git repository: '.git'

Hi, I'm getting this:

Fatal: Not a git repository: '.git'
no checks for pre-commit found.. skipping
running csslint...failed!
Running "csslint:git" (csslint) task

Not sure if should I worry about Fatal: Not a git repository: '.git', what could be the problem?

2.0.0 broken

After the update my config (which I just set up successfully yesterday) has broken.

My package.json looks like this:

{
    "scripts": {
      "lint": "jshint Gruntfile.js server.js app/ config/"
    },
    "pre-commit": ["lint"]
}

But the generated .validate.json looks like this:

{
  "scripts": {
    "lint": "jshint ."
  },
  "pre-commit": ["lint", "validate", "test"]
}

Furthermore there is no way to stay on version 1.0.7, since you basically added the core dependency as *. This is pretty bad versioning.

Hope you will be able to fix it, because this means I have to remove your package and/or find another way to setup my pre-commits 👎

Can't install without a hooks directory

After cloning my repo with Sourcetree (Mac OS X) the hooks directory didn't exist, therefore the installation failed.

Batmans-MBP:myproject fra$ npm install precommit-hook
|
> [email protected] install /Users/fra/Workspace/myproject/node_modules/precommit-hook/node_modules/git-validate
> node bin/install

fs.js:500
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory '/Users/fra/Workspace/myproject/.git/hooks/pre-commit'
    at Error (native)
    at Object.fs.openSync (fs.js:500:18)
    at Object.fs.writeFileSync (fs.js:1099:15)
    at Object.exports.installHooks (/Users/fra/Workspace/myproject/node_modules/precommit-hook/node_modules/git-validate/lib/utils.js:240:12)
    at Object.<anonymous> (/Users/fra/Workspace/myproject/node_modules/precommit-hook/node_modules/git-validate/bin/install.js:3:7)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
npm ERR! Darwin 14.3.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "precommit-hook"
npm ERR! node v0.12.5
npm ERR! npm  v2.11.2
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node bin/install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node bin/install'.
npm ERR! This is most likely a problem with the git-validate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node bin/install
npm ERR! You can get their info via:
npm ERR!     npm owner ls git-validate
npm ERR! There is likely additional logging output above.

I have solved the issue by manually creating the directory and re-running the install process, but can this issue be solved on the module side?

Thanks!

find: invalid predicate `-iwholename'

I'm implementing this on another project and when I run jshint . everything works, but when i run git commit I get this message:

find: invalid predicate `-iwholename'

Do you know what does it mean or have an idea where to start looking? I can't find anything on google.

This is my package.json:

  "scripts": {
    "lint": "jshint ."
  },
  "pre-commit": [
    "lint"
  ],

issue running from sourcetree on osx

i just installed this from osx and i was getting an error about jshint not being found. i manually installed it and now i get the following:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree commit -q -F /var/folders/gk/jgmznnj935lftgxb1627jrmh0000gn/T/SourceTreeTemp.MW6zNO
running lint...failed!
env: node: No such file or directory
Completed with errors, see above

i'm new to node so maybe i missed something obvious but i'm not sure what the issue could be.

make commands configurable

Possibly using the package.json file to define arbitrary variables, the user should be able to configure either explicit commands for each step, or that steps should be skipped.

jshint already installed means commits break

If the ~2.3.0 requirement for jshint is already met elsewhere (higher up in the dependency chain or installed globally) commits fail w/ a thrown exception that precommit-hook/node_modules/jshint/.bin/jshint can not be found.

Loosen jshint dependency

My project uses jshint@^2.5.1 but when I try to install I get the following error message:

npm ERR! peerinvalid The package jshint does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants jshint@~2.4.4

npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/usr/local/bin/npm" "i"
npm ERR! cwd /Volumes/Projects/dispatchr
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.10
npm ERR! code EPEERINVALID

The jshint peerDependency in precommit-hook should be loosened so users can use the version of jshint that they want.

Permissions with jshint on only modified files

I'm trying to make the precommit hook run jshint ONLY on files that have been changed.

In package.json my scripts object looks like the following

{
  "lint": "jshint $(git diff --cached --name-only --diff-filter=ACM | grep \".js$\")",
  "test": "make test"
}

Oddly, it appears that if I have more than one file staged to be committed, I get permission denied error(s).

running pre-commit checks...
running lint: failed!

sh: line 1: lib/index.js: Permission denied

Running jshint $(git diff --cached --name-only --diff-filter=ACM | grep ".js$" directly from the command line works as expected, though, and having my lint script as "jshint ." also works fine.

Thoughts on a more generalized module

Hey Nathan. I forked this module to experiment with some ideas on making it more generalized. I'd like to see if you're interested in pulling some of these ideas into this repo.

Removing JSHint requirement

Don't get me wrong, I use JSHint most of the time, but there are some projects I work on that wrap it or use another linter. I specifically wanted to remove the part where the installation script adds .jshint* files to the repo. And in some cases these files could already exist with slightly different names.

Not hardcoding tasks

I noticed the tasks are hard-coded. Which means only these 3 scripts are possible to make pre-commit hooks out of.

console.log('running pre-commit checks...');
runCmd('lint', function () {
    runCmd('validate', function () {
        runCmd('test', process.exit);
    });
});

Source: https://github.com/nlf/precommit-hook/blob/master/bin/pre-commit#L95-L100

Changes to project configuration

Instead of configuring tasks as an object with true | false values. We could use an array. This helps us maintain the running order of tasks and allows for us to chain any number of scripts during the pre-commit hook.

To turn a task off we can just exclude it from the array, or add items to the array which turns them on. With no configuration the default is ['lint', 'test'].

With this change we can chain the tasks together like this:

console.log('running pre-commit checks...');
var tasks = myconfig.map(function (cmd) {
    return runCmd.bind(null, cmd);
});
tasks.forEach(function (task, index, tasks) {
    tasks[index] = function () {
        task.call(null, tasks[index + 1] || process.exit);
    };
});
if (tasks.length > 0) {
    tasks[0]();
}

Source: https://github.com/jedireza/precommit-hooky/blob/master/bin/pre-commit#L91-L102

Adding an uninstall script

When the module is removed we should also remove the hook.

https://github.com/jedireza/precommit-hooky/blob/master/bin/uninstall


I've made these changes over here jedireza/precommit-hooky. If you'd like I can clean anything up and create a pull request.

Support another linters?

Awesome tool, but currently it unconditionally copies default .jshintrc and other stuff. We use ESLint, so each time we npm i we also need to manually remove artifacts generated by precommit-hook.

unnecessary jshint dependency

I'm using eslint ... I don't see the need to have a jshint dependency in this project, since it add a bunch of configuration I don't need nor want.

Question

When I run npm run-script lint I get:

λ npm run-script lint

> @ lint C:\Repositories\chrome-wakatime
> jsxhint --jsx-only .

But when I do a commit I get:

λ git cm -m "Updated tests."
find: ./node_modules/.bin/jest: No such file or directory
find: ./node_modules/.bin/jsx: No such file or directory
running lint...passed!

This is my package.json file:

"scripts": {
    "lint": "jsxhint --jsx-only ."
  },
  "pre-commit": ["lint"],

Why am I getting:

find: ./node_modules/.bin/jest: No such file or directory
find: ./node_modules/.bin/jsx: No such file or directory

?

jshint could be optional

It's good module but every time I execute npm install it creates .jshintignore and .jshintrc. It would be better if module suggest it not to force it (for ex. I use eslint).

Assumes the module has access to shell environment variables

Is there a way to enhance or modify this module so that it can be ran outside of the shell environment? Running this module from GUI Git clients most likely results in an access error because the clients do not run in the shell process but rather their own; therefore, trying to get access to shell variables are assumed and not actually available to the process. Sorry in advance if my question is a bit newbish when it comes to the shell.

Here is some direction from one such GUI client (Tower):

Are Hook scripts supported in Tower?
Yes, hook scripts are respected by Tower. Please note: Do your hook scripts rely on the existence or on specific values of shell environment variables that are created/modified in your shell profile (like extending "PATH" by a non-standard-path (e.g. '~/bin') to run a script from there in the hook)?

If the answer is yes, then you need to make sure you're creating the required shell environment in the hook script itself (like modifying "PATH"), not in your shell profile, as the hook script is called from the Tower process environment which is not running in a shell environment (hence your shell profile is not loaded).

Unable to install precommit-hook

Having latest Node, npm. I get permission denied error, unable to install. Pls help.

wavejourney-lm:~ damehta$ npm -v
1.4.14
wavejourney-lm:~ damehta$ node -v
v0.10.29
wavejourney-lm:~ damehta$ sudo npm install precommit-hook -g
/usr/local/bin/hook_install -> /usr/local/lib/node_modules/precommit-hook/bin/install
/usr/local/bin/hook_uninstall -> /usr/local/lib/node_modules/precommit-hook/bin/uninstall
/usr/local/bin/pre-commit -> /usr/local/lib/node_modules/precommit-hook/bin/pre-commit

[email protected] install /usr/local/lib/node_modules/precommit-hook
hook_install

/
module.js:340
throw err;
^
Error: Cannot find module '/usr/local/lib/package.json'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at configJshint (/usr/local/lib/node_modules/precommit-hook/bin/install:31:19)
at Object. (/usr/local/lib/node_modules/precommit-hook/bin/install:10:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)

[email protected] uninstall /usr/local/lib/node_modules/precommit-hook
hook_uninstall

Removing .git/hooks/pre-commit...

fs.js:765
return binding.unlink(pathModule._makeLong(path));
^
Error: ENOENT, no such file or directory '/usr/local/.git/hooks/pre-commit'
at Object.fs.unlinkSync (fs.js:765:18)
at /usr/local/lib/node_modules/precommit-hook/bin/uninstall:14:12
at /usr/local/lib/node_modules/precommit-hook/utils.js:11:9
at ChildProcess.exithandler (child_process.js:645:7)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:755:16)
at Socket. (child_process.js:968:11)
at Socket.emit (events.js:95:17)
at Pipe.close (net.js:465:12)
npm WARN continuing anyway [email protected] uninstall: hook_uninstall
npm WARN continuing anyway Exit status 8
npm ERR! [email protected] install: hook_install
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the precommit-hook package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! hook_install
npm ERR! You can get their info via:
npm ERR! npm owner ls precommit-hook
npm ERR! There is likely additional logging output above.

npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "precommit-hook" "-g"
npm ERR! cwd /Users/damehta
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/damehta/npm-debug.log
npm ERR! not ok code 0

Manually editing the hooks/pre-commit file

Hi,

When I install this package, it creates a hooks/pre-commit file.

I need to manually edit this file and add the following line to allow the hook to be run from Source Tree as well as the command line.

export PATH=/usr/local/bin:$PATH

Editing this file in vim is fine, and allows my hooks to be run from Source Tree. However if I edit the file in Sublime Text on Mac, the hooks no longer run, even on the command line. Instead I see this error:

sed: 1: "s/
$//": unterminated substitute pattern
EXPECTED value GOT EOF
failed parsing /Users/kestreet/myproject/package.json.. exiting

If I compare the original hooks/pre-commit file generated by this package with the file I have edited in Sublime Text, the original file has "mixed line endings" and the edited file has Unix (LF) line endings.

Do you know why this package is breaking when the hooks/pre-commit file has Unix (LF) line endings?

Script breaks with escaped quotes in package.json

If my test script is:

"test": "echo \"no tests\""

then the hook fails with this error:

> ./.git/hooks/pre-commit
running lint...passed!
running validate...passed!
running test...failed!
./.git/hooks/pre-commit: eval: line 235: unexpected EOF while looking for matching `"'
./.git/hooks/pre-commit: eval: line 236: syntax error: unexpected end of file

hooks per branch

Not sure if it could work this way, but it would be nice if I could specify a branch as a target for running the hooks. For example, I only want to run my tests in the master branch. I know other branches will break tests, but I still want to be able to make commits- in an effort to share code. Is there some way to accomplish this?

How to Check the Jshint in this updated version of Precommit-hook

Hi,

In older versions of precommit-hook i was able to check jshint but in updated version lint is getting checked , as of my client demand i need to check jshint only.

when try to set jshint in "precommit": ["jshint", "test"] getting warning as no script found.
if jshint is replaced with lint then it shows ok even if it contains error.

and one more doubt is old files had node_modules with .bin/jshint in the updated version this files are missing is this related to the above issue.

Please reply regarding this ASAP..

Version 2.0 plans

While considering some of the current inflexibilities with this module I've come to a conclusion. It's time for a version 2.0.

The initial plan for the new version is to make it simple to wrap this library and provide your own config files for linters (or anything else for that matter), as well as default scripts to be run.

Installing this module directly would create a pre-commit hook, but would not create any files other than the hook itself. The default hook would continue to run ['lint', 'validate', 'test'] (though I'm debating reducing the set of default scripts at this level to just 'test' and allowing wrappers to define additional default scripts as needed) if the scripts are defined, and still allow for configuration as it currently does.

This would definitely be a breaking change, though I don't believe a severe one.

As part of this, we would also create a couple of "default" wrapper modules precommit-hook-jshint, precommit-hook-eslint and precommit-hook-jslint that would demonstrate how to create your own.

Users that desire a custom configuration could then easily fork one of these defaults and modify it as desired without having to worry about the main script becoming out of sync, since it will be a dependency of their custom wrapper.

Comments? Suggestions? Thoughts?

@Trott since you've been contributing a lot, I'd love your input on this.

Confirm that all changes are stashed

I'm using this project successfully in my team.
The only issue I sometimes encounter is with people unfamiliar with git (or very distracted) solve the lint errors but don't add them to the commit.

This results in locally the lint ending successfully but the pushed code is 'dirty'.

Do you think it makes sense to check for not stashed changes?
And add a message like Please, add your changes or stash them before this commit?

Won't run if scripts isn't in package.json

If the 'script' section isn't in your package.json things asplode.

Iceman:fireball gar$ git commit -a

/Users/gar/Development/projects/fireball/.git/hooks/pre-commit:95
scripts.lint = 'jshint .';
^
TypeError: Cannot set property 'lint' of undefined

Assumes that nodejs app is in the top level directory.

root@nodejs-app1-andy:/mnt/srv/www/checkout/current/src# ll ../.git
root@nodejs-app1-andy:/mnt/srv/www/checkout/current/src# git status
# On branch next
# Your branch is ahead of 'origin/next' by 1 commit.
...
npm http GET https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz

> coffeelint@0.5.7 install /mnt/srv/www/checkout/releases/20130819185230/src/node_modules/precommit-hook/node_modules/coffeelint
> [ -e lib/commandline.js ] || npm run compile

npm http 200 https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz

> precommit-hook@0.3.8 install /mnt/srv/www/checkout/releases/20130819185230/src/node_modules/precommit-hook
> node install.js

This project doesn't appear to be a git repository. JSHint configuration will be created anyway. To enable the pre-commit hook, run `git init` and reinstall precommit-hook.
Did not find a .jshintignore, creating one

fs.js:338
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: EACCES, permission denied '/mnt/srv/www/checkout/releases/20130819185230/src/.jshintignore'
    at Object.fs.openSync (fs.js:338:18)
    at Object.fs.writeFileSync (fs.js:756:15)
    at Object.<anonymous> (/mnt/srv/www/checkout/releases/20130819185230/src/node_modules/precommit-hook/install.js:40:8)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)
npm ERR! [email protected] install: `node install.js`
npm ERR! `sh "-c" "node install.js"` failed with 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the precommit-hook package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node install.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls precommit-hook
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.2.0-51-virtual
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "precommit-hook"
npm ERR! cwd /mnt/srv/www/checkout/releases/20130819185230/src
npm ERR! node -v v0.8.19-opsworks
npm ERR! npm -v 1.2.10
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /mnt/srv/www/checkout/releases/20130819185230/src/npm-debug.log
npm ERR! not ok code 0

cannot install latest precommit-hook

$ npm install precommit-hook
/
> [email protected] install /prj1/node_modules/precommit-hook/node_modules/git-validate
> node bin/install

|
> [email protected] install /prj1/node_modules/precommit-hook
> node bin/install

/prj1/node_modules/precommit-hook/bin/install:7
Validate.installScript('lint', 'jshint .');
         ^
TypeError: undefined is not a function
    at Object.<anonymous> (/prj1/node_modules/precommit-hook/bin/install:7:10)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

```shell

2.0.1 works just fine.
I assume this is trying to run a validation script before installing the dependency.

Make it warn instead of blow up if no `.git` directory

I'm currently including this in the app scaffolding for humanjs stuff. Ideally it wouldn't blow up if they don't use git. It would just print out something about it not being installed. It could still create the .jshintrc etc.

Flesh out the readme a bit more.

What does it do, why does it do it, what are .jshintignore and .jshintrc files, add that it's MIT licensed, tell 'em to follow you on twitter. etc.

Ignore "projects" in repository

Hi,

First of all thanks for this module, its usage is simple and yet very powerful!

I came across what I thought that was an issue but after looking at your code, it seems more like it's a feature that incidentally triggers an issue for us. So the present issue is more a feature request than a real issue.

Your way of finding all projects in the current repo to check all of them, is assuming that all package.json are actually intended to be used for a check. In our repository, we have a build process that copies our main package.json to another directory (still inside the same repository) to prepare a complete folder ready for production. Incidentally, this copy of our package.json is detected by pre-commit hook and all hooks are run from that build folder. This issue is that this build folder is missing lots of packages that were intentionally not installed for production - like babel-node - which then triggers some failure in precommit hooks.

I found a workaround by editing the package.json's copy to make sure that it won't be detected by pre-commit hooks but I would find it much better to be able to somehow ignore some folders from being scanned to find a package.json.

Would you think this is a valid feature request or would you say that the current "patch package.json" strategy is better?

Thanks.

Option to skip installation of jshint files

We're using eslint for linting and the jshint config files are adding a bit of confusion since it can automatically enable linting by both jshint and eslint in some editor setups. Is there a way to use precommit-hook without adding any jshint files to our repo?

Mishandles shell escapes in some cases

Let's say you have this in your package.json:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
},

The hook will think the test passed despite the exit 1.

This is because it runs this:

sh -c "echo "Error: no test specified" && exit 1"

You might think that would return an error in the shell but try it out and you'll see that it actually outputs the string Error: and returns an exit code of 0!

Valid JSON fails to parse

Any ' in the script will cause the JSON parser to fail.

package.json

{
    "pre-push#production": [ "pre-push" ],
    "scripts": {
        "pre-push": "echo \"don't push to production, open a pull request\"; exit 1"
    }
}

shell

git:(production) > git push
running pre-push...failed!
.git/hooks/pre-push: eval: line 235: unexpected EOF while looking for matching `''
.git/hooks/pre-push: eval: line 236: syntax error: unexpected end of file

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.