#!/usr/bin/env bash

npm install -g npm@'>=4.0.3'
npm install -g eslint eslint-plugin-import eslint-plugin-react eslint-plugin-flowtype eslint-plugin-jsx-a11y babel-eslint

KITE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )
# Note a bunch of specific exclusions in the JS_FILES variable.  The excluded files are
# generated by the jsx transformer, not hand-written. Occasionally something that is
# natural in the JSX files gets transformed into an unnatural layout in the compiled
# Javascript (often this has to do with the transformation for arrow functions). Since
# the not-yet-compiled Javascript is already being linted, I figure it's okay.  -- Noah
JS_FILES=$(find . \
    -not -path '*node_modules*' \
    -not -path '*module-cache*' \
    -not -path '*/lib/*' \
    -not -name '*.min.js' \
    -not -name 'bundle.js' \
    -not -path '*/osx/SocketRocket/TestChatServer/*' \
    -not -path '*/search-debugger/static/js/*' \
    -not -path '*/vendor/*' \
    -not -path '*/webapp/*' \
    -not -path '*/web-settings/*' \
    -name '*.js')

eslint -c $KITE_DIR/.eslintrc.json -f compact $JS_FILES
