Skip to content

Instantly share code, notes, and snippets.

@wwwebman
Last active February 18, 2018 16:37
Show Gist options
  • Select an option

  • Save wwwebman/54fc234df55fe588d9ea8cd37b8a5417 to your computer and use it in GitHub Desktop.

Select an option

Save wwwebman/54fc234df55fe588d9ea8cd37b8a5417 to your computer and use it in GitHub Desktop.

Revisions

  1. wwwebman renamed this gist Feb 18, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. wwwebman created this gist Feb 18, 2018.
    35 changes: 35 additions & 0 deletions eslint-pre-commit hook
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #!/bin/sh

    # 1.
    # Code Quality Check
    # @scope ./react
    #
    STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM "src/react/*.js" "react/*.jsx" | tr '\n' ' ')
    ESLINT="$(git rev-parse --show-toplevel)/react/node_modules/.bin/eslint"

    [ -z "$STAGED_FILES" ] && exit 0

    # Check if Eslint installed
    [ ! -x "$ESLINT" ] && echo "\033[41m Please install ESlint \033[0m (cd react && npm i -D eslint)" && exit 1

    # Start validation
    VALIDATION_PASSED=true

    echo "$STAGED_FILES \n Validating Javascript:"

    for FILE in $STAGED_FILES
    do
    "$ESLINT" "$FILE"
    if [ -n "$?" ]; then
    VALIDATION_PASSED=false
    fi
    done

    if ! $VALIDATION_PASSED; then
    echo "\033[41m COMMIT FAILED: \033[0m
    Your commit contains files that should pass ESLint but do not.
    Please fix the ESLint errors and try again."
    exit 1
    fi

    exit $?