#!/usr/bin/env bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#

# To run, install node and npm, then install eslint:
#   sudo npm install eslint -g
# EsLint documentation is available from http://eslint.org

WHICH_ESLINT=`which eslint 2>/dev/null`
if [ "${WHICH_ESLINT}x" == "x" ]; then
    echo "You need to have eslint installed to run this script"
    echo "  Install node.js and npm, then install eslint like this:"
    echo "  sudo npm install -g eslint"
    exit 1
else
    if command -v realpath>/dev/null 2>&1; then
        CURRENT_FILE=`realpath "$0"`
    else
        CURRENT_FILE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/$(basename $0)"
    fi

    STATIC_ANALYSIS_DIR=`dirname "$CURRENT_FILE"`

    find "$1" -name "*.js" -exec eslint --quiet {} + && \
    find "$1" -name "*.jsm" -exec eslint --quiet {} +
    if [ $? -ne 0 ]; then
      exit 1
    fi
fi
