function eslint0ad { CURRENT_DIR=$(pwd) cd ~/0ad load_help_section() { cat < To what commit shall modified files be linted e.g HEAD~5 EOF return 1 } FIX='' COMMIT='' # the path to node_modules which contains the eslint-plugin-brace-rules plugin is a different path on Windows NODE_MODULE_PATH="/usr/local/lib/node_modules" for i in "$@"; do if [[ "$i" = "-h" ]] || [[ "$i" = "--help" ]]; then load_help_section elif [[ "$i" = "-f" ]] || [[ "$i" = "--fix" ]]; then FIX='--fix' else COMMIT+=($i) fi done if ! command -v eslint &>/dev/null; then echo "eslint NOT found, install it with:\nnpm i -g eslint" return 1 elif [[ ! -d "${NODE_MODULE_PATH}/eslint-plugin-brace-rules" ]]; then echo "eslint-plugin-brace-rules NOT found, install it with:\nnpm i -g eslint-plugin-brace-rules" return 1 fi # Untracked files need to be added for linting REGEX="(.*)\.(jsx|js|tsx|ts)$" git ls-files -o --exclude-standard | grep -E $REGEX | xargs git add # Guidance: https://gist.github.com//oroce/11282380 # IMPORTANT (--diff-filter=d) ensures that deleted files are filtered out, otherwise eslint would crash. eslint --config 'build/arclint/configs/eslintrc.json' --resolve-plugins-relative-to $NODE_MODULE_PATH $FIX $(git diff-index --name-only --diff-filter=d ${COMMIT:-'HEAD'} | grep -E $REGEX | xargs) cd $CURRENT_DIR }