Skip to content

Instantly share code, notes, and snippets.

@gsgbullniu
Forked from broofa/pre-commit
Created July 14, 2021 07:11
Show Gist options
  • Save gsgbullniu/b6271ce36b8a9e4b2b68576568a1f277 to your computer and use it in GitHub Desktop.
Save gsgbullniu/b6271ce36b8a9e4b2b68576568a1f277 to your computer and use it in GitHub Desktop.

Revisions

  1. @broofa broofa revised this gist Nov 1, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion pre-commit
    Original file line number Diff line number Diff line change
    @@ -18,10 +18,12 @@ fi

    $ESLINT "${STAGED_FILES[@]}" --fix

    ESLINT_EXIT="$?"

    # Re-add files since they may have been fixed
    git add "${STAGED_FILES[@]}"

    if [[ "$?" == 0 ]]; then
    if [[ "${ESLINT_EXIT}" == 0 ]]; then
    printf "\n\033[42mCOMMIT SUCCEEDED\033[0m\n"
    else
    printf "\n\033[41mCOMMIT FAILED:\033[0m Fix eslint errors and try again\n"
  2. @broofa broofa revised this gist Oct 28, 2016. No changes.
  3. @broofa broofa created this gist Oct 28, 2016.
    31 changes: 31 additions & 0 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/bin/bash
    cd "$(git rev-parse --show-toplevel)"
    ESLINT="node_modules/.bin/eslint"
    pwd

    if [[ ! -x "$ESLINT" ]]; then
    printf "\t\033[41mPlease install ESlint\033[0m (npm install eslint)\n"
    exit 1
    fi

    STAGED_FILES=($(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$"))

    echo "ESLint'ing ${#STAGED_FILES[@]} files"

    if [[ "$STAGED_FILES" = "" ]]; then
    exit 0
    fi

    $ESLINT "${STAGED_FILES[@]}" --fix

    # Re-add files since they may have been fixed
    git add "${STAGED_FILES[@]}"

    if [[ "$?" == 0 ]]; then
    printf "\n\033[42mCOMMIT SUCCEEDED\033[0m\n"
    else
    printf "\n\033[41mCOMMIT FAILED:\033[0m Fix eslint errors and try again\n"
    exit 1
    fi

    exit $?