function eslint0ad {
CURRENT_DIR=$(pwd)
cd ~/0ad
# IMPORTANT: eslint-plugin-brace-rules and eslint need to be installedload_help_section() {
# the path to node_modules which contains the eslint-plugin-brace-rules plugin is a different path on Windows cat <<EOF
NODE_MODULE_PATH="/usr/local/lib/node_modules"Linting of modified files up to a certain commit (HEAD by default) and optionally attempt to autofix problems.
if ! command -vIMPORTANT: eslint-plugin-brace-rules and eslint &>/dev/null; thenmust be installed
(no input) Display possible warnings/ errors
echo "eslint NOT found-h, install it with:\nnpm i -g eslint"--help Show help
-f, --fix return 1Autofix as many issues as possible
elif [[ ! -d "${NODE_MODULE_PATH}/eslint-plugin-brace-rules" ]]; then<COMMIT> To what commit shall modified files be linted e.g HEAD~5
echo "eslint-plugin-brace-rules NOT found, install it with:\nnpm i -g eslint-plugin-brace-rules"EOF
return 1
fi}
# Guidance: https://gist.github.com//oroce/11282380#gistcomment-2741146FIX=''
# Fix modified files or just do a dry-run (default)COMMIT=''
FIX=()# 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 or I need a better git formula to capture them too
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=dd) ensures that deleted files are filtered out, eslint can't lint deleted files andotherwise eslint would otherwise 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
}