Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit error #1060

Closed
zhangyuang opened this issue Feb 7, 2018 · 2 comments

Comments

@zhangyuang
Copy link

commented Feb 7, 2018

image
image

@jandockx

This comment has been minimized.

Copy link

commented May 8, 2018

The example script is for GNU. macOS grep (BSD) does not support the -z / --null-data option (nor xargs -r). I could not find a complete workaround.

#!/usr/bin/env bash
#!/bin/bash

# `pre-commit` to ensure all JavaScript files staged for commit pass standard code style.
#
# Based on https://github.com/standard/standard#is-there-a-git-pre-commit-hook
# Tweaked
# - for Mac (where grep does not have the -z / --null-data option),
# - therefor, xargs-r does not work either
# - for .js files instead of .jsx files.

git diff --name-only --cached --relative | grep '\.js$' | xargs -t npx standard
if [[ $? -ne 0 ]]; then
  echo 'JavaScript Standard Style errors were detected. Aborting commit.'
  exit 1
fi

works on Mac,

  • as long as there are no spaces in the paths to the staged js(x) files
  • checks everything if there are no staged .js files
@feross

This comment has been minimized.

Copy link
Member

commented May 9, 2018

Thanks for helping out, @jandockx!

One other workaround might be to install GNU grep using homebrew (a package manager for macOS).

brew install grep

This installs GNU grep as a binary called ggrep (note the extra leading g character). So, just change the references to grep to ggrep and you should be good :)

@feross feross closed this May 9, 2018

@feross feross added the question label May 9, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Aug 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants
You can’t perform that action at this time.